From e71609731ae14f9829553bdddc5b11111ed3d4bc Mon Sep 17 00:00:00 2001 From: Rob Young Date: Wed, 13 Jul 2022 13:23:29 +0100 Subject: [PATCH] Skip malformed baggage items (#1491) We are seeing baggage headers coming in with a single comma. This is obviously invalid but Sentry should error out. --- sentry_sdk/tracing_utils.py | 2 ++ tests/tracing/test_baggage.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py index aff5fc1076..0b4e33c6ec 100644 --- a/sentry_sdk/tracing_utils.py +++ b/sentry_sdk/tracing_utils.py @@ -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): diff --git a/tests/tracing/test_baggage.py b/tests/tracing/test_baggage.py index 3c46ed5c63..185a085bf6 100644 --- a/tests/tracing/test_baggage.py +++ b/tests/tracing/test_baggage.py @@ -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