Skip to content

Commit

Permalink
Skip malformed baggage items (#1491)
Browse files Browse the repository at this point in the history
We are seeing baggage headers coming in with a single comma. This is
obviously invalid but Sentry should error out.
  • Loading branch information
robyoung authored Jul 13, 2022
1 parent 9e69fcf commit e716097
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ def from_incoming_header(cls, header):

if header:
for item in header.split(","):
if "=" not in item:
continue
item = item.strip()
key, val = item.split("=")
if Baggage.SENTRY_PREFIX_REGEX.match(key):
Expand Down
10 changes: 10 additions & 0 deletions tests/tracing/test_baggage.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,13 @@ def test_mixed_baggage():
"other-vendor-value-1=foo;bar;baz,other-vendor-value-2=foo;bar;"
).split(",")
)


def test_malformed_baggage():
header = ","

baggage = Baggage.from_incoming_header(header)

assert baggage.sentry_items == {}
assert baggage.third_party_items == ""
assert baggage.mutable

0 comments on commit e716097

Please sign in to comment.