Skip to content

Commit 852faaa

Browse files
authored
fix: reject traceparent headers with unsupported versions (#241)
This addresses a regression introduced in #178, where traceparent headers containing unsupported characters were not properly rejected and were incorrectly treated as valid. [APMAPI-1599]
1 parent ae0d9a3 commit 852faaa

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/datadog/w3c_propagation.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ auto verboten(int lowest_ascii, int highest_ascii,
3333
};
3434
}
3535

36+
constexpr bool is_hexdiglc(const char c) {
37+
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
38+
(c >= 'A' && c <= 'F');
39+
}
40+
3641
// Populate the specified `result` with data extracted from the "traceparent"
3742
// entry of the specified `headers`. Return `nullopt` on success. Return a value
3843
// for the `tags::internal::w3c_extraction_error` tag if an error occurs.
@@ -59,6 +64,8 @@ Optional<std::string> extract_traceparent(ExtractedData& result,
5964

6065
beg = i + 1;
6166
internal_state = state::trace_id;
67+
} else if (!is_hexdiglc(traceparent[i])) {
68+
return "invalid_version";
6269
}
6370
} break;
6471

test/test_tracer.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,19 @@ TEST_TRACER("span extraction") {
755755
{__LINE__, "invalid: non hex trace tag ID",
756756
"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-xy", // traceparent
757757
"malformed_traceflags"}, // expected_error_tag_value
758+
759+
{
760+
__LINE__,
761+
"invalid: non supported character in trace version 1/x",
762+
".0-12345678901234567890123456789012-1234567890123456-01",
763+
"invalid_version",
764+
},
765+
{
766+
__LINE__,
767+
"invalid: non supported character in trace version 2/x",
768+
"0.-12345678901234567890123456789012-1234567890123456-01",
769+
"invalid_version"
770+
},
758771
}));
759772
// clang-format on
760773

0 commit comments

Comments
 (0)