Skip to content

Fix AppSec redirect analysis for OkHttp 3.4+ and 4.x - #13683

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
masterfrom
APMLP-2194
Nov 26, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
masterfrom
APMLP-2194

Conversation

@jandro996

@jandro996 jandro996 commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

What Does This Do

  • Adds AppSecRetryAndFollowUpInstrumentation. It applies an exit advice to okhttp3.internal.http.RetryAndFollowUpInterceptor.followUpRequest and reports each redirect followed by OkHttp 3.4+ and 4.x to AppSec as a separate downstream request: the 3xx response, then the follow-up request.
    • The matcher does not fix the number of arguments: followUpRequest(Response) in 3.4, (Response, Route) in 3.10 to 4.0, (Response, Exchange) in 4.12.
    • It only reports when OkHttp builds a follow-up for a 3xx. Auth, timeout and retry follow-ups are ignored.
  • Keeps AppSecHttpEngineInstrumentation for OkHttp 3.0-3.3. Both advices now delegate to AppSecInterceptor.onRedirect. It returns early when there is no active span or AppSec context. It rethrows a BlockingException and logs any other failure, so a failure in the AppSec hooks no longer reaches the application's HTTP call. The advices have no suppress, so that blocking still works.
  • When a redirect is blocked, AppSecInterceptor.onBlockedRedirect does the cleanup OkHttp skips because the exception comes from followUpRequest. It closes the 3xx body. On OkHttp 3.4-3.13 it also releases the StreamAllocation through reflection, because OkHttp only releases it for an IOException. Without that, every blocked redirect leaks a pooled connection.
  • Tests:
    • Removes the latestDepForkedTest opt-out in okhttp-3.0/build.gradle.
    • Adds okhttp4Test / okhttp4ForkedTest suites against OkHttp 4.12.0. The module muzzle range [3.0,) already instruments 4.x.
    • Adds an optional blockRequestUrlSuffix to the HttpClientTest AppSec callbacks, and a "test appsec client redirect blocking" scenario in OkHttp3Test. The scenario checks that the redirect is reported, that the call fails with BlockingException, and that no connection stays allocated.
    • Adds AppSecRedirectTest unit tests for the helper and the advice.

Motivation

latestDepForkedTest has run since #13218, and "test appsec client redirect analysis" failed against OkHttp 3.14.9: the redirected request was never captured. The cause is that okhttp3.internal.http.HttpEngine, where #10252 hooked the redirect analysis, only exists in OkHttp 3.0-3.3. From 3.4 on, redirects are followed in RetryAndFollowUpInterceptor. So AppSec did not analyze redirects on OkHttp 3.4+ and 4.x, and nothing failed.

Additional Notes

  • Suites:
    • okhttp4Test overrides the strictly OkHttp 3 / okio 1 versions it inherits from test with resolutionStrategy.force.
    • gradle.lockfile was regenerated. It only adds the okhttp4Test* configurations; the existing configurations do not change.
    • IastOkHttp3InstrumentationTest is excluded on OkHttp 4. That is an existing IAST gap with the Kotlin HttpUrl, tracked in APPSEC-72003.
  • Blocked redirects on async calls: the blocked-redirect scenario uses a synchronous call. On an async OkHttp 3 call, a downstream BlockingException never reaches the user callback. This already happens for any blocked downstream request and is tracked in APPSEC-72004.
  • Connection release on 3.4-3.13: no CI suite covers these versions. I checked it locally by pinning latestDepTest to OkHttp 3.12.12: the blocking scenario passes with the fix and fails on the connection-pool assertion without it.
  • Accepted limitation: the advice runs before OkHttp's own checks on the follow-up (one-shot request body, maximum of 20 follow-ups). So a redirect that OkHttp later drops can still be reported, or blocked.
  • OkHttp 5.x also falls within the muzzle range, but no suite covers it.

Contributor Checklist

Jira ticket: APMLP-2194

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.

- Report redirects followed by RetryAndFollowUpInterceptor (OkHttp 3.4+, 4.x); keep HttpEngine for 3.0-3.3
- Share AppSecInterceptor.onRedirect: only BlockingException reaches the caller
- Release the redirect body and connection when the redirect is blocked
- Run okhttp-3.0 latestDepForkedTest and add okhttp4Test suites
@jandro996 jandro996 added type: bug fix Bug fix comp: asm waf Application Security Management (WAF) inst: okhttp Square OkHttp instrumentation labels Nov 25, 2026
@jandro996

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 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-25T10:28:35.478224Z c7998b7 Draft marked ready
🔒 Security Review ✅ Completed 2026-11-25T10:27:10.577792Z c7998b7 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 Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: c7998b7958

ℹ️ 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 25, 2026 10:23
@jandro996
jandro996 requested review from a team as code owners November 25, 2026 10:23
@jandro996
jandro996 requested review from amarziali and ygree and removed request for a team November 25, 2026 10:23
@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: c7998b7958

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-prod-us1-4 datadog-prod-us1-4 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.

Bits Code Review: PASS

More details

The static reviewer reported no actionable defects in redirect reporting or blocked-redirect cleanup. Human PR discussion provided no additional technical concerns; runtime compatibility remains unverified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit c7998b7

@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 68.82% (+7.57%)

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

@dd-octo-sts

dd-octo-sts Bot commented Nov 25, 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.00 s 14.02 s [-0.8%; +0.5%] (no difference)
startup:insecure-bank:tracing:Agent 12.94 s 13.05 s [-1.5%; -0.2%] (maybe better)
startup:petclinic:appsec:Agent 17.84 s 17.64 s [+0.2%; +2.1%] (maybe worse)
startup:petclinic:iast:Agent 17.59 s 17.69 s [-1.6%; +0.5%] (no difference)
startup:petclinic:profiling:Agent 17.31 s 17.14 s [+0.1%; +1.9%] (maybe worse)
startup:petclinic:sca:Agent 17.82 s 17.69 s [-0.2%; +1.7%] (no difference)
startup:petclinic:tracing:Agent 16.75 s 16.42 s [-2.3%; +6.3%] (no difference)

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

@jandro996
jandro996 disabled auto-merge November 25, 2026 15:37
@jandro996
jandro996 enabled auto-merge November 25, 2026 15:40
@jandro996
jandro996 added this pull request to the merge queue Nov 25, 2026
@dd-octo-sts

dd-octo-sts Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-11-25 16:20:36 UTC ℹ️ Start processing command /merge


2026-11-25 16:20:41 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-11-25 17:31:12 UTC ❌ MergeQueue: The build pipeline failed for this merge request

Build pipeline has failing jobs for cc41078:

⚠️ Do NOT retry failed jobs directly (why?).

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 25, 2026
@jandro996
jandro996 added this pull request to the merge queue Nov 26, 2026
@dd-octo-sts

dd-octo-sts Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-11-26 08:35:29 UTC ℹ️ Start processing command /merge


2026-11-26 08:35:37 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-11-26 09:43:57 UTC ❌ MergeQueue: The build pipeline contains failing jobs for this merge request

Build pipeline has failing jobs for 3374da2:

⚠️ Do NOT retry failed jobs directly (why?).

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.
Details

Since those jobs are not marked as being allowed to fail, the pipeline will most likely fail.
Therefore, and to allow other builds to be processed, this merge request has been rejected and the pipeline got canceled.

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 26, 2026
@jandro996
jandro996 enabled auto-merge November 26, 2026 09:48
@jandro996
jandro996 added this pull request to the merge queue Nov 26, 2026
@dd-octo-sts

dd-octo-sts Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-11-26 10:35:55 UTC ℹ️ Start processing command /merge


2026-11-26 10:35:58 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-11-26 10:45:24 UTC ❌ MergeQueue: This merge request was updated

This PR is rejected because it was updated

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 26, 2026
@jandro996
jandro996 enabled auto-merge November 26, 2026 11:15
@jandro996
jandro996 added this pull request to the merge queue Nov 26, 2026
@dd-octo-sts

dd-octo-sts Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-11-26 11:27:18 UTC ℹ️ Start processing command /merge


2026-11-26 11:27:22 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-11-26 12:20:24 UTC ℹ️ MergeQueue: This merge request was merged

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 26, 2026
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit b46a30f into master Nov 26, 2026
688 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the APMLP-2194 branch November 26, 2026 12:20
@github-actions github-actions Bot added this to the 1.70.0 milestone Nov 26, 2026
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: okhttp Square OkHttp instrumentation type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants