Skip to content

fix(servlet): cover Servlet 6.1 3-arg sendRedirect in jakarta IAST instrumentation#11599

Closed
wconti27 wants to merge 1 commit into
masterfrom
boot4/jakarta-servlet-6.1
Closed

fix(servlet): cover Servlet 6.1 3-arg sendRedirect in jakarta IAST instrumentation#11599
wconti27 wants to merge 1 commit into
masterfrom
boot4/jakarta-servlet-6.1

Conversation

@wconti27
Copy link
Copy Markdown
Contributor

@wconti27 wconti27 commented Jun 8, 2026

Summary

Servlet 6.1 (Jakarta EE 11, Spring Boot 4 / Tomcat 11) adds a new sendRedirect(String location, int sc, boolean clearBuffer) overload. The existing jakarta-servlet-5.0 instrumentation already covers it — its matcher (named("sendRedirect").and(takesArgument(0, String.class))) is arity-agnostic and the muzzle range [5.0.0,) loads on 6.1.0 — so no new module is needed.

However, Tomcat 11's 1-arg sendRedirect internally delegates to the 3-arg overload. With both methods woven, the IAST onRedirect callback fired twice per redirect. This PR adds a CallDepthThreadLocalMap guard (mirroring the APM SendAdvice pattern) to ensure exactly one callback per redirect regardless of the internal delegation chain.

Changes

  • JakartaHttpServletResponseInstrumentation.java: Added CallDepthThreadLocalMap enter/exit guard to SendRedirectAdvice
  • DummyResponse.java: Added 3-arg sendRedirect stub + made 1-arg delegate to it (models Tomcat 11 / Servlet 6.1 behavior for tests)
  • JakartaHttpServletResponseInstrumentationTest.groovy.java: Full JUnit 5 migration (CLAUDE.md requirement), adding new cases: 3-arg fires exactly once, 1-arg delegation fires exactly once, null/empty locations fire nothing

Verification

./gradlew :dd-java-agent:instrumentation:servlet:jakarta-servlet-5.0:testBUILD SUCCESSFUL

Part of: #11597

🤖 Generated with Claude Code

Add a call-depth guard to the jakarta sendRedirect IAST advice so the
Servlet 6.1 sendRedirect(String,int,boolean) overload and the 1-arg form
(which 6.1 delegates to the 3-arg method) yield exactly one unvalidated-
redirect detection. Migrate the Groovy response instrumentation test to
JUnit 5 and add 3-arg overload coverage.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@wconti27 wconti27 requested a review from a team as a code owner June 8, 2026 16:03
@wconti27 wconti27 requested review from ValentinZakharov and removed request for a team June 8, 2026 16:03
@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented Jun 8, 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.

@dd-octo-sts dd-octo-sts Bot added the tag: ai generated Largely based on code generated by an AI or LLM label Jun 8, 2026
@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented Jun 8, 2026

PR Blocked - Invalid Label

The pull request introduced unexpected labels:

  • ai-generated

This PR is blocked until:

  1. The invalid labels are deleted, and
  2. A maintainer deletes this comment to unblock the PR

Note: Simply removing labels from the pull request is not enough - a maintainer must delete this comment then remove the label to remove the block.

@datadog-prod-us1-3
Copy link
Copy Markdown

datadog-prod-us1-3 Bot commented Jun 8, 2026

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 3 Pipeline jobs failed

Check pull requests | Check pull requests   View in Datadog   GitHub Actions

DataDog/apm-reliability/dd-trace-java | linux-java-spring-petclinic-sca-load-parallel   View in Datadog   GitLab

Validate PR Label Format | Check pull request labels   View in Datadog   GitHub Actions

Useful? React with 👍 / 👎

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

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

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: 2f8378ae67

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

final UnvalidatedRedirectModule module = InstrumentationBridge.UNVALIDATED_REDIRECT;
if (module != null) {
if (null != location && !location.isEmpty()) {
module.onRedirect(location);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Ensure call depth is reset when the redirect sink throws

When UNVALIDATED_REDIRECT.onRedirect(location) throws, the @Advice.OnMethodEnter(suppress = Throwable.class) swallows the exception after the call depth has already been incremented but before onEnter can return true; the exit advice then sees the default false enter value and skips CallDepthThreadLocalMap.reset(...). In that failure scenario the servlet response call-depth remains nonzero on the request thread, so subsequent sendRedirect calls on the same thread are treated as nested and the IAST redirect sink stops firing until the thread is reused/reset elsewhere.

Useful? React with 👍 / 👎.

@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented Jun 8, 2026

🟢 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 13.98 s 13.92 s [-0.6%; +1.5%] (no difference)
startup:insecure-bank:tracing:Agent 12.78 s 12.93 s [-2.3%; -0.0%] (maybe better)
startup:petclinic:appsec:Agent 16.79 s 16.61 s [-0.3%; +2.6%] (no difference)
startup:petclinic:iast:Agent 16.88 s 16.98 s [-1.7%; +0.5%] (no difference)
startup:petclinic:profiling:Agent 16.71 s 16.96 s [-3.0%; +0.1%] (no difference)
startup:petclinic:sca:Agent 16.92 s 16.64 s [+0.1%; +3.2%] (maybe worse)
startup:petclinic:tracing:Agent 15.10 s 16.00 s [-13.9%; +2.6%] (unstable)

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

@wconti27 wconti27 marked this pull request as draft June 8, 2026 16:25
@wconti27 wconti27 closed this Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated tag: ai generated Largely based on code generated by an AI or LLM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant