Skip to content

fix(asap): free inbound response payload once on envelope OOM - #93

Closed
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/high-severity-issues-7e66
Closed

cursor[bot] wants to merge 1 commit into
mainfrom
cursor/high-severity-issues-7e66

Conversation

@cursor

@cursor cursor Bot commented Sep 20, 2026

Copy link
Copy Markdown

Summary

  • fill_response_envelope now transfers payload ownership to the envelope and lets asap_envelope_clear free it once when a required field strdup fails.
  • Regression test drops sender after a valid task.cancel parse so the same post-attach cleanup path runs without a malloc hook.

Bug

On main @ d367477, fill_response_envelope assigned out->payload = payload then on missing id / asap_version / sender / recipient / payload_type called cJSON_Delete(payload) and asap_envelope_clear(out), which deletes out->payload again.

Trigger (production HTTP): unauthenticated POST /asap with payload_type state.query or task.cancel (parser requires sender/recipient, so those pointers are present). After the payload is attached, any required strdup failure (OOM; heap pressure from concurrent /asap bodies that malloc(ASAP_BODY_MAX+1)) takes the cleanup path. AddressSanitizer on the unit path reports heap-use-after-free in cJSON_Delete via asap_envelope_clear.

Impact: heap double-free / UAF on the gateway HTTP thread (crash or memory corruption).

Distinct from #84 (client JSON-RPC id double-free) and #86 (POST body size cap).

Test plan

  • make test_asap_server && ./build/test_asap_server
  • ASan+UBSan ./build/test_asap_server: previously aborted with heap-use-after-free at fill_response_envelope; now exits 0
  • ./build/test_asap_envelope, ./build/test_asap_invoke, ./build/test_asap_client, ./build/test_asap_log

Changelog

  • Unreleased Security note added.
Open in Web聽View Automation聽

fill_response_envelope attached the payload cJSON then deleted it
and called asap_envelope_clear, which deleted the same object.
Unauthenticated POST /asap state.query and task.cancel reach this
path; required-field strdup failure is a heap double-free.

Co-authored-by: esadrianno <esadrianno@gmail.com>
@adriannoes

Copy link
Copy Markdown
Collaborator

Superseded by #97 (rewrite against development; local owned_payload so cppcheck stays clean).

@adriannoes adriannoes closed this Sep 21, 2026
@adriannoes
adriannoes deleted the cursor/high-severity-issues-7e66 branch September 22, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants