Skip to content

Tag JAX-RS server spans with _dd.appsec.normalized_route - #13718

Draft
jandro996 wants to merge 2 commits into
APPSEC-72043from
APPSEC-72043-integrations
Draft

jandro996 wants to merge 2 commits into
APPSEC-72043from
APPSEC-72043-integrations

Conversation

@jandro996

Copy link
Copy Markdown
Member

What Does This Do

Sets _dd.appsec.normalized_route on JAX-RS server spans for Jersey 2/3 and RESTEasy 3, next to http.route, only when AppSec is active and API Security is enabled. Stacked on #13717 (PR 2 of 2).

Request capture

The JAX-RS annotations advice that sets http.route has no access to the request, so the framework modules capture what it needs and hand it over through a global context store keyed by the local root span:

  • Jersey (jersey-appsec-2.0, Jersey 2.x to 4.x, new muzzle directive jersey_server_2+3): UriRoutingContextMatchInstrumentation on exit of UriRoutingContext.setMatchedResourceMethod. It reads the bound values from the encodedTemplateValues field and the mount prefix from getBaseUri(). It never calls getPathParameters, which jersey-appsec already hooks for the WAF.
  • RESTEasy (resteasy-appsec-3.0): ResourceMethodInvokerInstrumentation on enter of ResourceMethodInvoker.invoke(HttpRequest, HttpResponse, Object), with getBaseUri() and getPathParameters(false) (encoded values, like Jersey).
  • JaxRsRequestMatchCapture (one copy per module) stores a copy of the decoded prefix and the values, never the framework objects. With no base URI, nothing is stored.

Tagging

  • JaxRsAnnotationsDecorator (javax) and JakartaRsAnnotationsDecorator (jakarta): right after each withRoute, the tag is cleared and recomputed from JaxRsRouteParser.cached(route) and the stored match, so the last writer of http.route owns the tag. No stored match (unknown mount prefix) means no tag.
  • Sub-resource locators: http.route is truncated for them, so the locator stores a SUBRESOURCE marker that the capture keeps, and the request gets no tag.
  • http.route and its priority logic are unchanged.

Tests

  • Unit: JaxRsAnnotationsDecoratorTest, JakartaRsNormalizedRouteTest, JaxRsRequestMatchCaptureTest (both modules).
  • End to end on Jetty with context path /ctx and servlet mapping /api: JerseyNormalizedRouteTest and ResteasyNormalizedRouteTest (regex, catch-all, several parameters, encoded literals, locators, AppSec inactive), plus forked tests with API Security disabled and with route-based naming off.
  • DropwizardTest declares the tag.

Motivation

RFC-1125 (amends RFC-1103): normalized routes for API Security Testing.

Additional Notes

  • Validated locally with [java] Add normalized route endpoints and enable RFC-1125 tests for Spring weblogs system-tests#8689 (tests/appsec/api_security_testing/test_normalized_route.py, manifest entries added locally): jersey-grizzly2 (Jersey 3) 27 passed; resteasy-netty3 26 passed, 1 skipped (test_empty_catch_all, RESTEasy returns 404 for //).
  • Known limitations:
    • Not captured, so no tag: RESTEasy 4+ (resteasy-core, jakarta), Jersey 1, CXF and requests aborted by a filter.
    • A locator that the JAX-RS advice does not see (excluded class, programmatic Jersey resource) cannot be detected, so its sub-resource gets the truncated route.
    • The Jersey capture reads a private field; it is unchanged from Jersey 2.0 to 4.0, but muzzle does not check field names.

Contributor Checklist

Jira ticket: APPSEC-72043

Note: Once your PR is ready to merge, add it to the merge queue by commenting /merge. /merge -c cancels the queue request. /merge -f --reason "reason" skips all merge queue checks; please use this judiciously, as some checks do not run at the PR-level. For more information, see this doc.

Capture the mount prefix and bound path values in Jersey (UriRoutingContext.setMatchedResourceMethod) and RESTEasy (ResourceMethodInvoker.invoke), and set _dd.appsec.normalized_route next to http.route in the jax-rs 2 and jakarta-rs 3 decorators. Dropwizard and new Jetty servlet tests for Jersey and RESTEasy cover the tag end to end.
- Clear _dd.appsec.normalized_route before recomputing it on every withRoute,
  so the last writer of http.route owns the tag (no stale value on re-dispatch
  or Quarkus on Vert.x)
- Mark sub-resource locators only where the locator sets the route
- Drop dead root-scope tagging (no server span, no capture)
- Unit tests for JaxRsRequestMatchCapture (null base URI, no span, SUBRESOURCE kept)
- jakarta-rs negative tests (AppSec inactive, malformed route) and stale-tag tests
@jandro996 jandro996 added type: feature Enhancements and improvements comp: asm waf Application Security Management (WAF) inst: jax-rs JAX-RS instrumentation labels Nov 27, 2026
@jandro996

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T08:56:16.836715Z d14b612 Manual request
🔒 Security Review ✅ Completed 2026-11-27T08:58:10.344444Z d14b612 Manual request
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: d14b6124b7

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: d14b6124b7

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@datadog-official

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Nov 27, 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.03 s 14.09 s [-1.0%; +0.2%] (no difference)
startup:insecure-bank:tracing:Agent 13.07 s 13.02 s [-0.5%; +1.1%] (no difference)
startup:petclinic:appsec:Agent 17.05 s 17.00 s [-0.5%; +1.0%] (no difference)
startup:petclinic:iast:Agent 16.98 s 17.08 s [-1.7%; +0.5%] (no difference)
startup:petclinic:profiling:Agent 16.28 s 16.92 s [-8.0%; +0.4%] (no difference)
startup:petclinic:sca:Agent 16.65 s 16.50 s [-5.1%; +6.9%] (unstable)
startup:petclinic:tracing:Agent 15.88 s 16.14 s [-5.8%; +2.6%] (no difference)

Commit: d14b6124 · 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.

This branch has not been deployed

No deployments
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) inst: jax-rs JAX-RS instrumentation type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant