Skip to content

Commit fd631d1

Browse files
committed
fix(tracing_utils): use maxsplit=1 in Baggage header parsing to handle values with '=' characters
Baggage values that contain '=' (e.g. base64-encoded strings) caused str.split("=") to return more than two parts, raising ValueError which was silently swallowed by capture_internal_exceptions(), dropping the sentry baggage item entirely. Fix: item.split("=", 1). Fixes #6449
1 parent 2ce26d1 commit fd631d1

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)