Skip to content

fix(native): escape JSON attachments#1771

Open
jpnurmi wants to merge 2 commits into
masterfrom
jpnurmi/fix/native/json-escape
Open

fix(native): escape JSON attachments#1771
jpnurmi wants to merge 2 commits into
masterfrom
jpnurmi/fix/native/json-escape

Conversation

@jpnurmi
Copy link
Copy Markdown
Collaborator

@jpnurmi jpnurmi commented May 30, 2026

Filenames and attachment/content types are arbitrary user-supplied strings that can contain characters that must be escaped in JSON.

JSON injection in crash daemon envelope headers via unescaped attachment filenames

Details

The write_attachment_to_envelope function constructs a JSON envelope item header using snprintf with %s interpolation for filename and content_type values. These originate from user-controlled API calls (sentry_attach_bytes, sentry_attachment_set_filename) with no validation. The values are properly JSON-escaped when serialized to the attachment list file via sentry_value_to_json, but after the crash daemon deserializes them with sentry__value_from_json and retrieves them with sentry_value_as_string, the raw unescaped strings are returned. Characters like double-quotes, backslashes, and newlines in filenames are interpolated verbatim into the JSON header, breaking the JSON structure. The normal envelope serialization path in sentry_envelope.c uses proper JSON writers, but the crash daemon duplicates this logic with raw snprintf.

Location

src/backends/native/sentry_crash_daemon.c:117

Impact

Attacker corrupts envelope structure causing misinterpretation of crash data

Reproduction steps

  1. An application preserves user-uploaded filenames when attaching files via sentry_attach_bytes. An attacker sets a filename like: x","type":"event","length":999}\n which, after JSON round-tripping through serialize/deserialize, injects a malformed item header into the crash envelope. The Sentry relay/backend may misinterpret item boundaries, treating attachment data as event payload.

Recommended fix

Envelope item headers in the crash daemon must use proper JSON serialization (the existing sentry_jsonwriter) rather than raw snprintf interpolation, ensuring all string values are escaped.


Severity: MEDIUM
Status: Open
Category: Injection
Repository: getsentry/sentry-native
Branch: master

jpnurmi added 2 commits May 30, 2026 11:13
File names and content types are arbitrary user-supplied strings that
can contain characters that must be escaped in JSON.
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e319974. Configure here.

_write(fd, header, (unsigned int)header_written);
_write(fd, "\n", 1);
#endif
sentry_free(header);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial headers on builder failure

Medium Severity

Replacing the fixed snprintf header with sentry__jsonwriter drops the old overflow guard and only treats a null header as failure. The JSON writer ignores sentry__stringbuilder append errors, so allocation pressure can yield a truncated item header that is still written and followed by attachment bytes, corrupting the crash envelope.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e319974. Configure here.

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