Skip to content

Add JAX-RS route parser for _dd.appsec.normalized_route - #13717

Open
jandro996 wants to merge 4 commits into
masterfrom
APPSEC-72043
Open

jandro996 wants to merge 4 commits into
masterfrom
APPSEC-72043

Conversation

@jandro996

Copy link
Copy Markdown
Member

What Does This Do

Adds the JAX-RS route tokenizer for the _dd.appsec.normalized_route tag, on top of the shared core in datadog.trace.api.appsec.route (no core class changes). This is PR 1 of 2; the Jersey and RESTEasy integrations come in the stacked PR.

  • JaxRsRouteParser (parse / cached, 256-entry DDCache like SpringRouteParser) turns the route built from the class and method @Path into a RouteTemplate:
    • {name} and { name : regex } (whitespace, nested braces and / inside the regex); the regex is never part of the tag.
    • Several parameters and static text in one segment ({id}.{format}, user-{id}, {a}-{b}-{c}).
    • A parameter whose regex accepts / ({path: .*}) is a catch-all (one parameter, optional when empty). This is decided by a static scan of the regex (., \S/\W/\D, \x2F, \u002F, octal, negated and range classes, \p{..}/\P{..}), never with java.util.regex.
    • Malformed templates give NOT_EXPRESSIBLE (no tag).
  • JaxRsRequestMatch: immutable carrier of the decoded mount prefix and a copy of the bound path values captured by the framework, plus the SUBRESOURCE marker for sub-resource locators.
  • Tests: JaxRsRouteParserTest, JaxRsRouteParserRfcVectorsTest (RFC-1125 rows 1-14, 30-35 and 49 in JAX-RS syntax; the other rows use syntax JAX-RS does not have), JaxRsRouteParserCacheTest, JaxRsRequestMatchTest.

Motivation

RFC-1125 (amends RFC-1103): normalized routes for API Security Testing. Follow-up of APPSEC-62077 (Spring MVC #13633, WebFlux #13635).

Additional Notes

  • JAX-RS treats %XX in @Path as escapes. The core renderer re-encodes literals from their text, so the parser decodes each escape and lets the core encode it again: caf%c3%a9 and café give caf%C3%A9, %20 stays. Escapes of unreserved characters come out decoded (%7E gives ~): keeping them would need a core change.
  • A } inside a regex character class ({id: [}a]+}) closes the parameter early, so the route gets no tag (fails closed, tested).

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.

Add JaxRsRouteParser, which turns JAX-RS @path routes ({name: regex} with whitespace, nested braces and '/' inside the regex) into a RouteTemplate, treating regexes that accept '/' as catch-alls by a static scan. Add JaxRsRequestMatch, an immutable carrier of the decoded mount prefix and bound path parameters for the JAX-RS decorators. Tests cover the RFC-1125 vectors expressible in JAX-RS syntax.
@jandro996 jandro996 added type: feature Enhancements and improvements comp: asm waf Application Security Management (WAF) 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-27T20:40:29.316698Z ca2108a Draft marked ready
🔒 Security Review ✅ Completed 2026-11-27T20:41:09.500838Z ca2108a Draft marked ready
ℹ️ 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 Security Review · Automatically triggered

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

Reviewed commit: 390297d7c4

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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 390297d7c4

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

@datadog-official

datadog-official Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 90.43%
• Overall Coverage: 59.85% (-1.49%)

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

@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.83 s 14.73 s [-0.2%; +1.5%] (no difference)
startup:insecure-bank:tracing:Agent 13.67 s 13.80 s [-1.8%; -0.1%] (maybe better)
startup:petclinic:appsec:Agent 17.28 s 16.66 s [-0.8%; +8.2%] (no difference)
startup:petclinic:iast:Agent 17.10 s 17.20 s [-1.3%; +0.2%] (no difference)
startup:petclinic:profiling:Agent 16.70 s 16.73 s [-1.2%; +0.9%] (no difference)
startup:petclinic:sca:Agent 17.30 s 17.17 s [-0.2%; +1.6%] (no difference)
startup:petclinic:tracing:Agent 16.26 s 16.39 s [-1.8%; +0.2%] (no difference)

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

A nested class can negate its members ([^[^/]] accepts '/'), so flattening it as a union misclassified a catch-all as a constrained param. Classes with a nested class or an intersection now count as accepting '/', like the other uncertain constructs of the scan.
@jandro996
jandro996 marked this pull request as ready for review November 27, 2026 20:37
@jandro996
jandro996 requested review from a team as code owners November 27, 2026 20:37
@jandro996
jandro996 requested review from dougqh, dromanol and manuel-alvarez-alvarez and removed request for a team November 27, 2026 20:37

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ca2108ac3b

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

@datadog-official datadog-official Bot 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.

Bits Code Review: FAIL

Valid Unicode property aliases and character-class ranges are misclassified as required parameters. Empty catch-all bindings consequently render /files/{path} instead of /files, producing incorrect normalized-route tags.

Open Bits AI session

🤖 Bits Code Review · Commit ca2108a

The scan now answers YES, NO or UNKNOWN: negating a class never flips an uncertain answer, \p{..} properties are slash-free only from an explicit whitelist, \Q..\E and \N{..} inside a class are uncertain, and a lone & is a literal. Any uncertain answer makes the param a catch-all, so presence still comes from the bound value. Also covers ']' as first class member and the (?x) flag.

@datadog-official datadog-official Bot 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.

Bits Code Review: PASS

More details

The PR adds JAX-RS route parsing and request-match data for _dd.appsec.normalized_route, with framework integration deferred to the stacked PR. All three earlier defects—Unicode property aliases, quoted range endpoints, and lone ampersand ranges—are fixed, and the incremental review leaves no findings open.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 0f123e8

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) type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant