Skip to content

Collect Datadog security-testing headers on HTTP server entry spans#11418

Open
christophe-papazian wants to merge 3 commits into
masterfrom
christophe-papazian/aap-collect-security-testing-headers
Open

Collect Datadog security-testing headers on HTTP server entry spans#11418
christophe-papazian wants to merge 3 commits into
masterfrom
christophe-papazian/aap-collect-security-testing-headers

Conversation

@christophe-papazian
Copy link
Copy Markdown

APPSEC-64531

Tags x-datadog-endpoint-scan and x-datadog-security-test HTTP request headers
on every HTTP server entry span as http.request.headers.<name>, unconditionally
— independent of DD_TRACE_HEADER_TAGS and AppSec enablement.

These markers let the API endpoint reducer distinguish Datadog scan/test traffic
from real user traffic and keep it out of the API inventory. They are not
propagated downstream: Java's propagator injects only DDSpanContext, not
arbitrary span tags.

When an inferred proxy span is the local root, the markers are forwarded from
the service-entry span at finish time (matching the Node.js implementation).

Test plan

  • 8 unit tests in HttpServerDecoratorSecurityTestingHeadersTest (new, JUnit 5)
  • 1 unit test in InferredProxySpanTests for inferred-proxy forwarding
  • Existing HttpServerDecoratorTest (Groovy) passes — no regression

🤖 Generated with Claude Code

Tags x-datadog-endpoint-scan and x-datadog-security-test as
http.request.headers.<name> on every HTTP server entry span,
unconditionally (independent of DD_TRACE_HEADER_TAGS and AppSec).
When an inferred proxy span is the local root, the markers are
forwarded from the service-entry span at finish time.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@datadog-datadog-prod-us1
Copy link
Copy Markdown
Contributor

datadog-datadog-prod-us1 Bot commented May 19, 2026

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 7 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-java | Ubuntu_20_amd64.SI94: [test-app-java-container]   View in Datadog   GitLab

🔧 Fix in code (Fix with Cursor). 1 failed test: AssertionError: _container_tags_validator failed to validate trace_id: 56299365307998712 in tests/auto_inject/test_auto_inject_install.py:255

DataDog/apm-reliability/dd-trace-java | Ubuntu_23_10_arm64.SI94: [test-app-java-alpine]   View in Datadog   GitLab

🔧 Fix in code (Fix with Cursor). 1 failed test. AssertionError: _container_tags_validator failed to validate trace_id: 27977837393815129 in tests/auto_inject/test_auto_inject_install.py:255

DataDog/apm-reliability/dd-trace-java | Ubuntu_23_10_arm64.SI94: [test-app-java-container]   View in Datadog   GitLab

🔧 Fix in code (Fix with Cursor). 1 failed test due to assertion error: _container_tags_validator failed to validate trace_id: 9590191563181650 in tests/auto_inject/test_auto_inject_install.py:255

View all 7 failed jobs.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 12a511f | Docs | Datadog PR Page | Give us feedback!

if (carrier == null || getter == null) {
return;
}
getter.forEachKey(carrier, new SecurityTestingHeaderTagClassifier(span));
Copy link
Copy Markdown
Member

@manuel-alvarez-alvarez manuel-alvarez-alvarez May 19, 2026

Choose a reason for hiding this comment

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

This seems a bit too heavy if we just want to test for the presence of two headers, have you though about using protected String getRequestHeader(REQUEST request, String key)?

I know that not all frameworks are implemented, but we could ask APM to extend it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point — I went back and forth on this. I chose the iteration approach because getRequestHeader defaults to null on HttpServerDecorator and is currently only overridden where DSM needs it (a handful of integrations). With ~120 instrumentations in tree, switching to direct lookups means we'd ship the feature only for the few decorators that already implement it, until APM extends the rest.

The iteration cost is also mitigated:

  • the classifier short-circuits via return false after both markers are found, so on requests without the markers it scans the carrier once (same cost as the existing ResponseHeaderTagClassifier does for DD_TRACE_HEADER_TAGS) and on requests with them it stops as soon as both are seen;
  • it follows the same pattern as ResponseHeaderTagClassifier, so the perf trade-off is one we've already taken on the response path.

Happy to switch to getRequestHeader in a follow-up once APM is on board with extending it across server decorators — that'd be the cleaner long-term shape. Let me know if you'd rather hold this PR for that or land it now and refactor later.

christophe-papazian and others added 2 commits May 20, 2026 10:31
Address PR review nit: replace two near-identical anonymous
HttpServerDecorator subclasses with one helper that takes the
ContextVisitor as a parameter.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@christophe-papazian christophe-papazian marked this pull request as ready for review May 20, 2026 08:45
@christophe-papazian christophe-papazian requested review from a team as code owners May 20, 2026 08:45
@christophe-papazian christophe-papazian requested review from claponcet, manuel-alvarez-alvarez, mtoffl01 and vandonr and removed request for a team May 20, 2026 08:45
@dd-octo-sts dd-octo-sts Bot added the tag: ai generated Largely based on code generated by an AI or LLM label May 20, 2026
@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented May 20, 2026

Hi! 👋 Thanks for your pull request! 🎉

To help us review it, please make sure to:

  • Add at least one type, and one component or instrumentation label to the pull request

If you need help, please check our contributing guidelines.

@christophe-papazian christophe-papazian added comp: asm waf Application Security Management (WAF) type: enhancement Enhancements and improvements labels May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: asm waf Application Security Management (WAF) tag: ai generated Largely based on code generated by an AI or LLM type: enhancement Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants