Repository navigation
Commit 3f581ec
authored
Fix trailing element separator rejecting valid dd tracestate (#12229)
Fix trailing element separator rejecting valid dd tracestate
A trailing ';' at the end of the W3C tracestate 'dd' member value was
incorrectly rejected as invalid, dropping the entire dd member and any
decoded tags, priority, or origin instead of ignoring the separator.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Apply same fix to DatadogPTagsCodec
Fix OWS before comma after trailing separator, align OWC helpers
Skipping to the next comma when a trailing separator is followed by OWS (e.g. "dd=s:2;o:some; ,x=y")
left the parser resuming on a space, which isAllowedKeyChar rejects and drops the whole dd member.
We add skipLeadingOWC to consume that OWS, and restyle stripTrailingOWC to the same while-loop shape.
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.
Exclude TAG_KEY_SEPARATOR alongside TAGS_SEPARATOR, mirroring the W3C codec's isAllowedKeyChar.
Note TAG_KEY_SEPARATOR is already caught by the separator check in validateCharsUntilSeparatorOrEnd,
so this doesn't change behavior, but keeps the predicate decoupled from how it's used by the caller.
(the similar KEY_VALUE_SEPARATOR check in the W3C codec is also a no-op given how it's used, but is
also worth keeping in case the calling code changes.)
Avoid exception when unknown dd tag is followed by trailing-OWS-only content
cleanUpAndAppendUnknown re-scans the raw tracestate to re-append unknown
dd submembers, assuming every element is at least 2 chars long so it can
peek a second character to detect known s/o tags. Accepting a trailing
separator followed only by OWS (e.g. "dd=x:y; ") breaks that assumption.
We skip leading OWS before each element the same way the value scanner
already does, so a trailing whitespace-only remainder is recognized as
padding and the loop exits cleanly.
Disallow interior OWS padding inside 'dd' section
Ignore empty elements inside dd tracestate
Drop malformed elements from dd tracestate, but retain valid elements
(unless we're sure it's a bad tid/dm/ts value in which case it's safer to drop the whole section)
Ensure last parent tag (p:) is not duplicated when updating
Still relay elements we couldn't parse, as downstream tracers might handle them
Co-authored-by: stuart.mcculloch <stuart.mcculloch@datadoghq.com>1 parent 2d8d93d commit 3f581ec
5 files changed
Lines changed: 171 additions & 65 deletions
File tree
- dd-trace-core/src
- main/java/datadog/trace/core/propagation/ptags
- test/java/datadog/trace/core/propagation
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
| 179 | + | |
| 180 | + | |
183 | 181 | | |
184 | 182 | | |
185 | 183 | | |
| |||
189 | 187 | | |
190 | 188 | | |
191 | 189 | | |
192 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
193 | 194 | | |
194 | 195 | | |
195 | 196 | | |
| |||
Lines changed: 58 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
103 | 107 | | |
104 | 108 | | |
105 | 109 | | |
| |||
108 | 112 | | |
109 | 113 | | |
110 | 114 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
115 | 120 | | |
116 | 121 | | |
117 | 122 | | |
| |||
123 | 128 | | |
124 | 129 | | |
125 | 130 | | |
126 | | - | |
127 | | - | |
128 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
129 | 135 | | |
130 | 136 | | |
131 | 137 | | |
| |||
152 | 158 | | |
153 | 159 | | |
154 | 160 | | |
155 | | - | |
156 | 161 | | |
157 | 162 | | |
158 | 163 | | |
| |||
351 | 356 | | |
352 | 357 | | |
353 | 358 | | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
| 359 | + | |
| 360 | + | |
358 | 361 | | |
359 | 362 | | |
360 | 363 | | |
| |||
365 | 368 | | |
366 | 369 | | |
367 | 370 | | |
368 | | - | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
369 | 375 | | |
370 | 376 | | |
371 | 377 | | |
| |||
613 | 619 | | |
614 | 620 | | |
615 | 621 | | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
620 | 625 | | |
621 | | - | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
622 | 653 | | |
623 | 654 | | |
624 | 655 | | |
| |||
631 | 662 | | |
632 | 663 | | |
633 | 664 | | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
634 | 669 | | |
635 | 670 | | |
636 | | - | |
| 671 | + | |
637 | 672 | | |
638 | 673 | | |
639 | 674 | | |
640 | 675 | | |
641 | | - | |
642 | | - | |
643 | | - | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
644 | 680 | | |
645 | 681 | | |
646 | 682 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
Lines changed: 16 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
120 | 127 | | |
121 | 128 | | |
122 | 129 | | |
| |||
0 commit comments