Skip to content

Fix baggage header escaping of non-ASCII values - #12564

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits into
masterfrom
roseanna.mcfarlane/escape-non-ascii-baggage-values
Sep 25, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits into
masterfrom
roseanna.mcfarlane/escape-non-ascii-baggage-values

Conversation

@RoseannaM

Copy link
Copy Markdown
Contributor

What Does This Do

Fixes PercentEscaper.nextEscapeIndex() skipping non-ASCII characters, so baggage keys and values are now fully percent-escaped.

Motivation

See Jira APMS-20590

nextEscapeIndex() duplicated part of needsEncoding() but tested only the unsafe-octet table, dropping the c > '~' and c <= ' ' conditions. Those tables are 93 entries (values) / 126 (keys), so every non-ASCII character sits outside them and the scan skipped straight past it.

The first character was still escaped via the escape(String, boolean[]) fast path, so the bug only showed from the second escape onward — raw UTF-8 bytes went into the header value and were mangled in transit.

Testing

  • New PercentEscaperTest — 12 tests covering the 2-byte, 3-byte and 4-byte (surrogate pair) UTF-8 branches, non-ASCII at the start vs. after an escape, repeated interleaving, and both the key and value octet tables. All pass; 10 fail with the fix reverted.
  • Verified end to end in a Spring Boot app: released 1.66.0 emits the mangled header above, a local build of this branch emits the fully escaped one.

Additional Notes

Contributor Checklist

  • Format code with ./gradlew spotlessApply
  • Tests added

🤖 Generated with Claude Code

Jira ticket: [PROJ-IDENT]

@RoseannaM RoseannaM added the type: bug fix Bug fix label Sep 18, 2026
@RoseannaM
RoseannaM requested a review from a team as a code owner September 18, 2026 12:06
@RoseannaM RoseannaM added the comp: context propagation Trace context propagation label Sep 18, 2026
@RoseannaM
RoseannaM requested review from jordan-wong and removed request for a team September 18, 2026 12:06
@RoseannaM RoseannaM added the tag: ai generated Largely based on code generated by an AI or LLM label Sep 18, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-18T12:09:26.470152Z 173a447 PR opened
🔒 Security Review ✅ Completed 2026-09-18T12:12:18.225692Z 173a447 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

🎯 Code Coverage (details)
• Patch Coverage: 50.00%
• Overall Coverage: 59.12% (+0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 6eb3ad9 | Docs | Give us feedback!

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datadog Autotest: PASS

More details

The shared encoding check now stops the scan at each unsafe ASCII or non-ASCII character. All later characters stay in the percent-encoding path.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Datadog Autotest · Commit 173a447 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

@dd-octo-sts

dd-octo-sts Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.01 s 13.89 s [-0.0%; +1.7%] (no difference)
startup:insecure-bank:tracing:Agent 12.90 s 13.00 s [-1.5%; +0.1%] (no difference)
startup:petclinic:appsec:Agent 17.01 s 17.01 s [-0.9%; +1.0%] (no difference)
startup:petclinic:iast:Agent 17.02 s 17.07 s [-1.0%; +0.4%] (no difference)
startup:petclinic:profiling:Agent 16.98 s 16.43 s [+2.3%; +4.3%] (significantly worse)
startup:petclinic:sca:Agent 16.92 s 16.70 s [+0.3%; +2.3%] (maybe worse)
startup:petclinic:tracing:Agent 16.24 s 16.22 s [-0.8%; +1.0%] (no difference)

Commit: 6eb3ad9b · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@jordan-wong
jordan-wong requested a review from mhlidd September 23, 2026 14:51

@jordan-wong jordan-wong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved from IDM perspective but we do not really touch this area of the codebase - would like to see some review from Capabilities, tagging @mhlidd as the current sole file contributor

@mhlidd mhlidd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some additional fixes that are relevant to the issue.

Comment thread dd-trace-core/src/main/java/datadog/trace/core/util/PercentEscaper.java Outdated
Comment thread dd-trace-core/src/main/java/datadog/trace/core/util/PercentEscaper.java Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

URL-decoded values and keys can still round-trip incorrectly for + and %.

Review effort: Lite
Findings: None

What changed in this PR

Fixes baggage header percent escaping for non-ASCII characters.

Changes:

  • Corrects escape scanning logic.
  • Adds Unicode, control-character, and key/value regression tests.
File Summary
dd-trace-core/​src/​main/​java/​datadog/​trace/​core/​util/​PercentEscaper.java Updates escaping logic; moderate issues remain for + in values and % in keys.
dd-trace-core/​src/​test/​java/​datadog/​trace/​core/​util/​PercentEscaperTest.java Adds comprehensive escaping regression coverage; round-trip tests for the remaining issues are requested.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@RoseannaM
RoseannaM added this pull request to the merge queue Sep 25, 2026
@dd-octo-sts

dd-octo-sts Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-25 09:43:30 UTC ℹ️ Start processing command /merge


2026-09-25 09:43:34 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-09-25 10:59:33 UTC ℹ️ MergeQueue: This merge request was merged

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 25, 2026
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 190a012 into master Sep 25, 2026
606 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the roseanna.mcfarlane/escape-non-ascii-baggage-values branch September 25, 2026 10:59
@github-actions github-actions Bot added this to the 1.67.0 milestone Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: context propagation Trace context propagation tag: ai generated Largely based on code generated by an AI or LLM type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants