Skip to content

Commit c204938

Browse files
committed
Reject ';' as a dd tracestate key character
isAllowedKeyChar didn't exclude the element separator, so a key scan starting right after an empty element (e.g. "dd=s:2;;o:some") would swallow the next ';' into the key instead of failing, silently dropping the origin tag rather than rejecting the malformed member. Datadog's sibling codec already excludes its element separator from key chars; align W3C's the same way. Flagged by Copilot review on PR #12229.
1 parent 3c2938b commit c204938

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

dd-trace-core/src/main/java/datadog/trace/core/propagation/ptags/W3CPTagsCodec.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,10 @@ private static int validateCharsUntilSeparatorOrEnd(
365365
private static boolean isAllowedKeyChar(int c) {
366366
// We already know that the segments have been validated against the valid chars for
367367
// the general tracestate header
368-
return c > MIN_ALLOWED_CHAR && c <= MAX_ALLOWED_CHAR && c != KEY_VALUE_SEPARATOR;
368+
return c > MIN_ALLOWED_CHAR
369+
&& c <= MAX_ALLOWED_CHAR
370+
&& c != KEY_VALUE_SEPARATOR
371+
&& c != ELEMENT_SEPARATOR;
369372
}
370373

371374
private static boolean isAllowedValueChar(int c) {

dd-trace-core/src/test/java/datadog/trace/core/propagation/W3CHttpExtractorTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ void checkMaxFromW3CTraceIds(@ConvertWith(TraceIdTestConverter.class) DDTraceId
115115
"keep with trailing element separator | '00-00000000000000000000000000000001-123456789abcdef0-01' | 'dd=s:2;o:some;' | USER_KEEP | | some ",
116116
"keep with trailing separator and OWS | '00-00000000000000000000000000000001-123456789abcdef0-01' | 'dd=s:2;o:some; \t' | USER_KEEP | | some ",
117117
"keep with trailing separator OWS before comma | '00-00000000000000000000000000000001-123456789abcdef0-01' | 'dd=s:2;o:some; ,x=y' | USER_KEEP | | some ",
118+
"reject dd member with empty element in middle | '00-00000000000000000000000000000001-123456789abcdef0-01' | 'dd=s:2;;o:some' | SAMPLER_KEEP | SamplingMechanism.DEFAULT | ",
119+
"reject dd member with leading separator | '00-00000000000000000000000000000001-123456789abcdef0-01' | 'dd=;s:2;o:some' | SAMPLER_KEEP | SamplingMechanism.DEFAULT | ",
118120
"keep with user keep state and manual dm | '00-00000000000000000000000000000001-123456789abcdef0-01' | 'dd=s:2;o:some;t.dm:-4' | USER_KEEP | SamplingMechanism.MANUAL | some ",
119121
"drop with user keep state and manual dm | '00-00000000000000000000000000000001-123456789abcdef0-00' | 'dd=s:2;o:some;t.dm:-4' | SAMPLER_DROP | | some ",
120122
"drop with user drop state | '00-00000000000000000000000000000001-123456789abcdef0-00' | 'dd=s:-1;o:some' | USER_DROP | | some ",

0 commit comments

Comments
 (0)