Skip to content

Tag Ratpack server spans with _dd.appsec.normalized_route - #13725

Open
jandro996 wants to merge 3 commits into
masterfrom
APPSEC-72045
Open

jandro996 wants to merge 3 commits into
masterfrom
APPSEC-72045

Conversation

@jandro996

Copy link
Copy Markdown
Member

What Does This Do

Sets _dd.appsec.normalized_route (RFC-1125) next to http.route on Ratpack server spans (netty.request and ratpack.handler) when AppSec is active and API Security is enabled. Same approach as the Spring MVC (#13633) and WebFlux (#13635) integrations, on top of the shared core in datadog.trace.api.appsec.route (unchanged).

Route grammar

  • New RatpackRouteParser (internal-api) turns PathBinding.getDescription() into a RouteTemplate. The description already holds the whole prefix(...) chain and Ratpack has no context path, so no mount prefix is added.
  • It mirrors the placeholder rules of Ratpack's DefaultPathBinderBuilder by hand (no java.util.regex): tokens only start a segment; :name -> {name} (static text may follow it, :name.json -> {name}.json); :name? -> optional segment; :name:regex / :name?:regex -> regex removed; ::regex -> unnamed {param<N>}; any other : is static text.
  • Literals are percent-decoded before the RFC encoding because Ratpack matches the raw request path (caf%C3%A9 renders caf%C3%A9).
  • prefix(x) { all {} } reached with an unconsumed rest (getPastBinding()) renders a trailing unnamed catch-all (/x/a/b -> /x/{param1}, /x// -> /x/, /x -> /x).
  • The / that Ratpack adds when joining get(handler) (== get("", handler)) under a prefix is not a declared trailing slash: prefix("users") { get {} } renders /users.
  • Templates are cached in bounded DDCaches, one per (empty inner path, remainder) combination.

Presence and tagging

  • New RatpackPresenceResolver: optional tokens from PathBinding.getAllTokens() (includes prefix tokens), catch-all from getPastBinding().
  • RatpackServerDecorator.onContext tags the span right after withRoute, gated by NormalizedRouteHelper.isEnabled(), never throws. RootPathBinding (unmatched request, root all {}) gets no tag; a root get("") renders /.

Tests

  • RatpackRouteParserTest, RatpackRouteParserRfcVectorsTest (RFC-1125 rows expressible in Ratpack syntax, non-applicable rows listed), RatpackRouteParserCacheTest, RatpackPresenceResolverTest.
  • NormalizedRouteTest on an embedded Ratpack app: optional segment and chain, prefix catch-all, prefix tokens, regex, ::regex, encoded literal, static text after a token, root, 404, prefix fall-through 404, 405, handler error under a nested prefix, both spans. NormalizedRouteApiSecurityDisabledForkedTest.
  • RatpackHttpServerTest (expectedNormalizedRoute + the ratpack.handler span) and RatpackOtherTest assert the new tag.

Motivation

RFC-1125 (amends RFC-1103): stable normalized routes for App and API Protection. Follow-up of APPSEC-62077 for Ratpack.

Additional Notes

  • System-tests: [java] Add normalized route endpoints and enable RFC-1125 tests for Spring weblogs system-tests#8689 enables test_normalized_route.py for the ratpack weblog (commit 560cfd680). Validated locally against this branch: 16 passed, 11 skipped (irrelevant). CI there stays red until a snapshot contains this change.
  • The tag is computed per span (netty and ratpack.handler, both carry http.route). Routes without optional parts cost one cache lookup per span.
  • Known limitations (documented in RatpackRouteParser):
    • /x/ under prefix(x) { all {} } renders /x: Ratpack reports an empty past binding, so prefix and exact bindings look the same (RFC fallback).
    • No tag for an optional token followed by text in the same segment (:fmt?.json, Ratpack makes its / optional too) or sharing a name with another token (getAllTokens() lets the child value replace the parent one).
    • Programmatic PathBinder.builder() descriptions that the string grammar cannot express (a literal starting with :, a regex containing /) and user regexes with capturing groups (Ratpack shifts its own token group indexes) follow the description and the values Ratpack binds.
    • Stacked empty bindings prefix("users") { prefix("") { get {} } } give the same description as prefix("users/") { get {} } and render a trailing slash.

Contributor Checklist

Jira ticket: APPSEC-72045

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.

Set the RFC-1125 normalized route next to http.route on the netty and
ratpack.handler spans when AppSec is active and API Security is enabled.

- RatpackRouteParser (internal-api) turns PathBinding.getDescription(),
  which already holds the whole prefix(...) chain, into a RouteTemplate:
  :name, :name? (optional), :name:regex and :name?:regex (regex removed),
  ::regex (unnamed), literals percent-decoded since Ratpack matches the
  raw path. prefix(x){all{}} reached with an unconsumed rest renders a
  trailing unnamed catch-all; the join slash of get("") under a prefix is
  not a declared trailing slash.
- RatpackPresenceResolver takes presence from getAllTokens() and the
  catch-all presence from getPastBinding().
- RootPathBinding (404, root all{}) gets no tag; root get("") renders "/".
- JUnit tests for the parser, the RFC-1125 vectors expressible in Ratpack
  syntax, the cache and an embedded Ratpack app (both spans, error, 405,
  fall-through 404, API Security disabled); existing Spock suites assert
  the new tag.
@jandro996 jandro996 added type: feature Enhancements and improvements inst: ratpack Ratpack instrumentation 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:34.276817Z 22bf06d Draft marked ready
🔒 Security Review ✅ Completed 2026-11-27T20:40:06.522089Z 22bf06d 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: 79abb7ba24

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: 79abb7ba24

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

@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 ValentinZakharov, claponcet and dromanol and removed request for a team November 27, 2026 20:37

@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

Ratpack route grammar compatibility remains the main validation limit: framework sources were unavailable for independent verification, and tests were not run. No concrete defect was identified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 22bf06d

@datadog-official

datadog-official Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 97.06%
• Overall Coverage: 59.81% (-1.54%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 1a9c5bb | 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.06 s 14.07 s [-0.9%; +0.7%] (no difference)
startup:insecure-bank:tracing:Agent 12.98 s 13.11 s [-1.7%; -0.3%] (maybe better)
startup:petclinic:appsec:Agent 17.90 s 17.76 s [-0.1%; +1.7%] (no difference)
startup:petclinic:iast:Agent 16.95 s 17.77 s [-8.9%; -0.4%] (maybe better)
startup:petclinic:profiling:Agent 17.56 s 17.43 s [-0.6%; +2.2%] (no difference)
startup:petclinic:sca:Agent 17.87 s 17.79 s [-0.3%; +1.2%] (no difference)
startup:petclinic:tracing:Agent 16.94 s 17.04 s [-1.7%; +0.4%] (no difference)

Commit: 1a9c5bbf · 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: ratpack Ratpack instrumentation type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant