Skip to content

Commit 53249b3

Browse files
fix(tracing_utils): handle baggage values containing '=' in from_incoming_header (#6450)
## What's broken `Baggage.from_incoming_header` silently drops any sentry baggage item whose value contains an `=` character (e.g. base64-encoded strings like `v1.0==1`). A header like `sentry-release=v1.0==1,sentry-trace_id=abc123` produces `{'trace_id': 'abc123'}` instead of `{'release': 'v1.0==1', 'trace_id': 'abc123'}`. ## Why it happens `key, val = item.split("=")` without a `maxsplit` argument raises `ValueError: too many values to unpack` when the value contains `=`. The surrounding `capture_internal_exceptions()` swallows the exception, silently discarding the item. ## Fix Changed `item.split("=")` to `item.split("=", 1)` so the split stops after the first delimiter, correctly assigning the key and the full value (including any `=` in the value). ## Test Added `test_baggage_from_incoming_header_value_with_equals_sign` which parses a header containing a sentry item with `==` in its value and asserts both items are present in `sentry_items`. Fixes #6449 Co-authored-by: Aegis Dev <devteamaegis@users.noreply.github.com> Co-authored-by: Ivana Kellyer <ivana.kellyer@sentry.io>
1 parent 41ff92e commit 53249b3

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

sentry_sdk/tracing_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ def from_incoming_header(
719719

720720
with capture_internal_exceptions():
721721
item = item.strip()
722-
key, val = item.split("=")
722+
key, val = item.split("=", 1)
723723
if Baggage.SENTRY_PREFIX_REGEX.match(key):
724724
baggage_key = unquote(key.split("-")[1])
725725
sentry_items[baggage_key] = unquote(val)

tests/test_tracing_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,10 @@ def test_should_continue_trace(
279279

280280
baggage = Baggage.from_incoming_header(baggage_header) if baggage_header else None
281281
assert _should_continue_trace(baggage) == should_continue_trace
282+
283+
284+
def test_baggage_from_incoming_header_value_with_equals_sign():
285+
# Baggage values that legitimately contain '=' (e.g. base64) must not be dropped
286+
header = "sentry-release=v1.0==1,sentry-trace_id=abc123"
287+
baggage = Baggage.from_incoming_header(header)
288+
assert baggage.sentry_items == {"release": "v1.0==1", "trace_id": "abc123"}

0 commit comments

Comments
 (0)