Skip to content

fix(core): Parse envelopes that contain an empty attachment - #24769

Draft
breken-ai wants to merge 1 commit into
getsentry:developfrom
breken-ai:fix/core-parse-empty-envelope-item
Draft

breken-ai wants to merge 1 commit into
getsentry:developfrom
breken-ai:fix/core-parse-empty-envelope-item

Conversation

@breken-ai

Copy link
Copy Markdown

parseEnvelope treats an item header with length: 0 as if it had no length, because the check is binaryLength ? readBinary(...) : readJson(). For an empty attachment (for example scope.addAttachment({ filename: 'log.txt', data: '' })), it then reads the next empty line as JSON. JSON.parse('') throws, so the whole envelope fails to parse.

Two places parse envelopes after they have been sent:

  • handleTunnelRequest answers 400 Invalid envelope, so the event and all its attachments are dropped at the tunnel.
  • The browser offline transport deletes the entry from IndexedDB before it parses it. When the parse throws, shift returns undefined and the event is lost.

The fix checks binaryLength !== undefined, so a zero-length item reads zero bytes. There are two new tests: a parseEnvelope round trip with an empty attachment, and a tunnel request carrying one. Both fail on develop (Unexpected end of JSON input, and fetch is never called) and pass with this change.

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).
  • Link an issue if there is one related to your pull request. If no issue is linked, one will be auto-generated and linked.

I ran the packages/core vitest suite with and without the change. The only failures are the same 2 environment failures (zoderrrors, typedef) on both. oxfmt --check is clean on the changed files. I also ran oxlint on them, without the @sentry/eslint-plugin-sdk JS plugin.

An AI coding agent (Claude Code, run by breken-ai) found this bug and wrote this change. I checked the red/green tests above before opening the PR.

🤖 Generated with Claude Code

`parseEnvelope` treated an item header with `length: 0` as having no
length and tried to read a JSON payload instead. That payload is empty,
so `JSON.parse('')` threw and the whole envelope failed to parse.

This made `handleTunnelRequest` answer 400 for an event that carried an
empty attachment, and made the browser offline transport drop such an
envelope when reading it back from IndexedDB.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant