Skip to content

feat(tracing): collect Datadog security-testing headers on entry spans#18049

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
christophe-papazian/collect-security-headers
May 15, 2026
Merged

feat(tracing): collect Datadog security-testing headers on entry spans#18049
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
christophe-papazian/collect-security-headers

Conversation

@christophe-papazian

@christophe-papazian christophe-papazian commented May 12, 2026

Copy link
Copy Markdown
Contributor

APPSEC-62412

Summary

Tags two new Datadog markers — x-datadog-endpoint-scan and x-datadog-security-test — on every span that goes through set_http_meta, as http.request.headers.<name>. Collection is unconditional: it happens regardless of DD_TRACE_HEADER_TAGS or AppSec being enabled. Scope intentionally matches the existing user-agent/referrer extraction.

These let the API endpoint reducer distinguish Datadog scan/test traffic from real user traffic and keep it out of the API inventory.

The dd-style tag name (http.request.headers.<name>) is what dd-trace-py emits; the OTel-style variant (http.request.header.<name>) is handled by the reducer, not by tracers.

RFC: Security Testing: Trace Attribution for Inventory Enrichment and Pollution Prevention

Test plan

🤖 Generated with Claude Code

Unconditionally tag `x-datadog-endpoint-scan` and `x-datadog-security-test`
request headers as `http.request.headers.<name>` on any span that goes
through `set_http_meta`, matching the scope of user-agent/referrer
extraction. Collection does not depend on DD_TRACE_HEADER_TAGS or AppSec
enablement. These headers let the API endpoint reducer distinguish
scan/test traffic from real user traffic.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@christophe-papazian christophe-papazian added the ASM Application Security Monitoring label May 12, 2026
@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented May 12, 2026

Copy link
Copy Markdown

Codeowners resolved as

ddtrace/contrib/internal/trace_utils.py                                 @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/internal/trace_utils_base.py                            @DataDog/apm-core-python @DataDog/apm-idm-python
releasenotes/notes/aap-collect-security-testing-headers-64eb4a1cbc7778b2.yaml  @DataDog/apm-python
tests/tracer/test_trace_utils.py                                        @DataDog/apm-sdk-capabilities-python @DataDog/apm-core-python

The RFC requires unconditional collection of these markers. An empty
header value is a valid signal (the header is still present), so switch
from `if value:` to `if value is not None:` and flip the corresponding
test.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread ddtrace/contrib/internal/trace_utils_base.py
@christophe-papazian

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented May 15, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-05-15 08:00:13 UTC ℹ️ Start processing command /merge


2026-05-15 08:00:18 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 52m (p90).


2026-05-15 09:32:44 UTC ⚠️ MergeQueue: This merge request build was cancelled

christophe.papazian@datadoghq.com cancelled this merge request build

@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot merged commit 07cb0c1 into main May 15, 2026
844 checks passed
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot deleted the christophe-papazian/collect-security-headers branch May 15, 2026 10:22
christophe-papazian added a commit to DataDog/dd-trace-dotnet that referenced this pull request May 27, 2026
…ry spans (#8682)

## Summary of changes

Tag `x-datadog-endpoint-scan` and `x-datadog-security-test` HTTP request
headers as `http.request.headers.<name>` on every HTTP server entry span
(and the inferred-proxy span when one is created), unconditionally —
independent of `DD_TRACE_HEADER_TAGS` and AppSec enablement. Markers are
not propagated downstream.

## Reason for change

APPSEC-65483 — RFC ["Security Testing: Trace Attribution for Inventory
Enrichment and Pollution
Prevention"](https://docs.google.com/document/d/1uR4QQvU8pItEV2zFqr3-L6jO2jxzmvLrFTX_yyvqIOA).
These two markers let the API endpoint reducer distinguish Datadog
scan/test traffic from real user traffic and keep it out of the API
inventory.

Sibling-tracer implementations already merged:
[`dd-trace-py#18049`](DataDog/dd-trace-py#18049),
[`dd-trace-js#8463`](DataDog/dd-trace-js#8463),
[`dd-trace-java#11418`](DataDog/dd-trace-java#11418).

## Implementation details

- New `SpanContextPropagator.AddSecurityTestingHeadersAsTags<THeaders>`
reads both markers from any `IHeadersCollection` and tags them on the
supplied span. Tag names are precomputed; `string[]` fast-path avoids
enumerator allocation on the legacy `NameValueCollection` /
`WebHeaderCollection` carriers; presence-based (empty values still
tagged).
- Wired into every HTTP server entry path:
- `AspNetMvcIntegration` (System.Web MVC) — entry span + inferred-proxy
span (proxy tagged at creation site)
- `AspNetWebApi2Integration` (System.Web Web API 2) — entry span (no
proxy support on this path)
- `TracingHttpModule` (OWIN/IIS classic) — entry span + inferred-proxy
span
- `AspNetCoreHttpRequestHandler` (ASP.NET Core, including Azure
Functions isolated worker HTTP-proxying mode) — entry span +
inferred-proxy span
  - `WcfCommon` (WCF over HTTP) — entry span

## Test coverage

- `SpanContextPropagatorTests_AddSecurityTestingHeadersAsTags` (new — 13
cases): both markers + unrelated header, absent headers, no `HeaderTags`
config, only one marker present, empty-string value still tagged,
case-insensitive lookup, ASP.NET Core `HeadersCollectionAdapter` with
mixed-case lookup.
- All existing `SpanContextPropagatorTests*` continue to pass.

## Other details

<!-- Fixes #{issue} -->

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ASM Application Security Monitoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants