Skip to content

fix(native): escape JSON attachments#1771

Merged
jpnurmi merged 3 commits into
masterfrom
jpnurmi/fix/native/json-escape
Jun 1, 2026
Merged

fix(native): escape JSON attachments#1771
jpnurmi merged 3 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.

Comment thread src/backends/native/sentry_crash_daemon.c
@jpnurmi jpnurmi merged commit e8a1e65 into master Jun 1, 2026
63 checks passed
@jpnurmi jpnurmi deleted the jpnurmi/fix/native/json-escape branch June 1, 2026 14:49
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