Preserve captured response body when AppSec response hook fails - #12388
Open
dougqh wants to merge 1 commit into
Open
Conversation
If publish() throws inside onResponse() after the response body has already been read and rebuilt into `result`, the exception propagated out of onResponse() and caused intercept() to fall back to the original response, whose body had already been consumed. Callers then saw an empty/closed body instead of the real one. Catch and log non-blocking failures from publish() locally so the rebuilt response is always returned. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
dougqh
marked this pull request as ready for review
September 3, 2026 00:24
Contributor
|
🎯 Code Coverage (details) 🔗 Commit SHA: 04ae7fb | Docs | View more details | Give us feedback! |
Contributor
There was a problem hiding this comment.
More details
The new catch keeps the rebuilt response when the AppSec hook fails. It does not catch BlockingException.
🤖 Datadog Autotest · Commit 04ae7fb · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest
Contributor
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Does This Do
Wraps the
publish()call for the AppSec response hook insideAppSecInterceptor.onResponse()in its own try/catch (matching the existing pattern for the request-hook path), so a non-blocking exception from the response hook no longer discards the already-rebuilt response.Motivation
onResponse()rebuilds the response with the body it captured for AppSec analysis into a localresult. If the response hook (publish()) then threw an exception other thanBlockingException, that exception propagated out ofonResponse()andintercept()'s outer catch fell back to the originalresponseobject — whose body had already been consumed reading it intoresult. Callers ended up seeing an empty/closed body instead of the real one.Stacked on #12242, which fixed a related NPE (
span.getTag(Tags.HTTP_URL)risk) flagged during the same review pass on that PR.Additional Notes
okhttp-2.2andokhttp-3.0instrumentation modules.responseHookFailureAfterBodyCapturePreservesCapturedBodytoAppSecInterceptorTestin both modules, verifying the response body survives a throwing response hook.AppSecInterceptorTestsuites pass for both modules;./gradlew spotlessApplyrun./techdebtand/perf-reviewrun over the branch diff: no findings.Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: [PROJ-IDENT]