Skip to content

[AppSec] Send the real response status to the WAF and stop resending the request addresses - #9082

Merged
dromanol merged 6 commits into
masterfrom
dani/aap/waf-response-status-repro
Sep 9, 2026
Merged

dromanol merged 6 commits into
masterfrom
dani/aap/waf-response-status-repro

Conversation

@dromanol

@dromanol dromanol commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary of changes

  • server.response.status reaches the WAF with the real status code: it is never sent during the request-phase scans, and it is sent once the real response status is known. On ASP.NET Core requests that reach the end of the pipeline without an endpoint, both Scan(lastTime: true) and the later response scan can carry it — the WAF doesn't report the same match twice.
  • On ASP.NET Core the request address set is collected once per request instead of on every run. ASP.NET Framework keeps refreshing it on each BeginRequest, including the second pipeline a Server.TransferRequest creates, which is deliberate.
  • Responses the WAF never saw get a report-only scan at the end of the pipeline: HTTP.sys, which never fires the instrumented response start hook, and server-generated error responses on Kestrel.

Reason for change

The status came from the request-phase address set, where HttpContext.Response.StatusCode is still the default 200, so status rules were fed a fabricated value — and on HTTP.sys that was the only status the WAF ever saw. Resending every request address on the later runs also re-evaluated the whole request rule set for no new information.

The same gap existed on Kestrel for responses the server writes itself. On an unhandled exception the 500 is produced by ProduceEnd(), after application.ProcessRequestAsync() has returned, so the scope set by the diagnostic observer inside that call is no longer visible in the AsyncLocal: FireOnStarting finds no active span and skips the WAF entirely. Those requests reached the WAF without a response status or response headers at all.

Implementation details

Two one-shot flags on AppSecRequestContext, both driving the Core path. Persistent addresses live for the whole WAF context, so later runs re-evaluate rules, schemas and fingerprints against the stored values.

server.request.cookies on ASP.NET Framework is the one address the end-of-request run re-reads. ASP.NET puts ASP.NET_SessionId in Request.Cookies when the session id is read, which SessionStateModule normally does at AcquireRequestState, well before EndRequest; the explicit SessionID read in GetEndRequestArgsForWaf is the guard for hosts where the cookie isn't visible yet, and it has to happen before the cookies are snapshotted. Without the re-read the cookie halves of _dd.appsec.fp.session go empty.

Test coverage

New unit tests against the real WAF: status rule matching per phase, schemas surviving a run without resupplied addresses, session fingerprint vs late cookies, server detection. Coordinator-level tests for the one-shot address collection, the omission of the status during the request phase and the real status at the end of the request, on both Core and Framework. Green locally: Security unit tests net8.0/net48, Security integration AspNetCore net8.0 + AspNetMvc5 net48, and system-tests APPSEC_BLOCKING, APPSEC_API_SECURITY, APPSEC_WAF_TELEMETRY, APPSEC_RASP, APPSEC_AUTO_EVENTS_EXTENDED, DEFAULT.

Because error responses now reach the last WAF run, API Security samples them too and error spans can carry _dd.appsec.s.* schemas. That breaks the DEBUGGER_EXCEPTION_REPLAY span approvals, where the schemas land on a different request every run (the sampler's 30s window against the test's 30s retry interval): DataDog/system-tests#7543 scrubs them like the _dd.appsec.fp.* fingerprints already are.

Other details

Replaces #8856 (rewritten from scratch, not rebased). Left out on purpose: registering Response.OnStarting(...) from BlockingMiddleware would work on every server and let HTTP.sys block, but it means removing a calltarget and redoing the blocking and ordering story.

@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: 98f2a72c31

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

Comment thread tracer/src/Datadog.Trace/AspNet/TracingHttpModule.cs Outdated
Comment thread tracer/src/Datadog.Trace/AppSec/Coordinator/SecurityCoordinator.cs
@dd-trace-dotnet-ci-bot

dd-trace-dotnet-ci-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (9082) and master.

✅ No regressions detected

📄 View the full report (charts + all metrics) →

@pr-commenter

pr-commenter Bot commented Aug 19, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-09-09 15:27:58

Comparing candidate commit 3924a44 in PR branch dani/aap/waf-response-status-repro with baseline commit ea1b829 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 72 metrics, 0 unstable metrics, 65 known flaky benchmarks, 61 flaky benchmarks without significant changes.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net472

  • 🟥 throughput [-8594.181op/s; -8065.306op/s] or [-10.190%; -9.563%]

scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild netcoreapp3.1

  • 🟥 throughput [-9874.849op/s; -8029.758op/s] or [-10.041%; -8.164%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟥 allocated_mem [+1.541KB; +1.541KB] or [+46.817%; +46.831%]
  • 🟥 execution_time [+306.963ms; +312.100ms] or [+152.326%; +154.875%]
  • 🟥 throughput [-64.035op/s; -58.272op/s] or [-11.521%; -10.484%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net6.0

  • 🟥 allocated_mem [+1.012KB; +1.012KB] or [+37.524%; +37.537%]
  • unstable execution_time [+290.831ms; +353.227ms] or [+229.774%; +279.071%]
  • 🟩 throughput [+75.639op/s; +79.802op/s] or [+9.973%; +10.522%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1

  • 🟥 allocated_mem [+1.090KB; +1.090KB] or [+40.417%; +40.429%]
  • 🟥 execution_time [+398.546ms; +399.859ms] or [+352.698%; +353.860%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody net472

  • 🟥 allocated_mem [+4.734KB; +4.734KB] or [+99.652%; +99.667%]
  • 🟥 throughput [-59540.360op/s; -59160.237op/s] or [-46.325%; -46.030%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody net6.0

  • 🟥 allocated_mem [+3.856KB; +3.856KB] or [+81.546%; +81.558%]
  • 🟩 execution_time [-16.278ms; -12.113ms] or [-7.602%; -5.657%]
  • 🟥 throughput [-61643.119op/s; -58881.290op/s] or [-44.996%; -42.980%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody netcoreapp3.1

  • 🟥 allocated_mem [+4.583KB; +4.584KB] or [+99.120%; +99.133%]
  • 🟥 throughput [-48704.126op/s; -46456.840op/s] or [-44.034%; -42.002%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net472

  • 🟥 allocated_mem [+1.356KB; +1.356KB] or [+109.716%; +109.731%]
  • 🟥 throughput [-294292.727op/s; -280582.435op/s] or [-30.049%; -28.649%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net6.0

  • 🟥 allocated_mem [+519 bytes; +520 bytes] or [+42.477%; +42.486%]
  • 🟩 execution_time [-26.123ms; -21.262ms] or [-11.650%; -9.482%]
  • 🟥 throughput [-96779.191op/s; -74251.553op/s] or [-10.339%; -7.932%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody netcoreapp3.1

  • 🟥 allocated_mem [+1.320KB; +1.320KB] or [+109.261%; +109.277%]
  • 🟥 throughput [-167285.646op/s; -151366.002op/s] or [-24.036%; -21.748%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody net472

  • 🟥 allocated_mem [+3.378KB; +3.378KB] or [+89.003%; +89.017%]
  • 🟥 throughput [-72398.736op/s; -71639.974op/s] or [-48.724%; -48.213%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody net6.0

  • 🟥 allocated_mem [+3.336KB; +3.336KB] or [+88.150%; +88.161%]
  • 🟥 throughput [-75414.552op/s; -72519.932op/s] or [-47.985%; -46.143%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody netcoreapp3.1

  • 🟥 allocated_mem [+3.264KB; +3.264KB] or [+88.493%; +88.506%]
  • 🟥 throughput [-56904.075op/s; -54277.187op/s] or [-45.331%; -43.239%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody net6.0

  • 🟩 throughput [+155138.229op/s; +232565.797op/s] or [+5.173%; +7.755%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody netcoreapp3.1

  • 🟩 execution_time [-18.423ms; -14.087ms] or [-8.492%; -6.494%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs net472

  • 🟩 allocated_mem [-13.759KB; -13.757KB] or [-42.326%; -42.318%]
  • 🟥 execution_time [+300.368ms; +301.091ms] or [+150.084%; +150.445%]
  • 🟩 throughput [+962.106op/s; +991.432op/s] or [+10.626%; +10.950%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs net6.0

  • 🟩 allocated_mem [-13.722KB; -13.718KB] or [-42.341%; -42.329%]
  • 🟥 execution_time [+299.389ms; +302.527ms] or [+150.982%; +152.565%]
  • 🟩 throughput [+2427.952op/s; +2637.987op/s] or [+18.570%; +20.177%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs netcoreapp3.1

  • 🟩 allocated_mem [-13.722KB; -13.718KB] or [-42.341%; -42.329%]
  • 🟥 execution_time [+299.854ms; +302.673ms] or [+151.043%; +152.463%]
  • 🟩 throughput [+1806.251op/s; +1937.256op/s] or [+17.438%; +18.703%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net472

  • 🟥 execution_time [+295.611ms; +296.315ms] or [+145.192%; +145.538%]
  • 🟩 throughput [+480.368op/s; +558.592op/s] or [+12.735%; +14.808%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net6.0

  • 🟥 execution_time [+298.368ms; +299.610ms] or [+145.861%; +146.468%]
  • 🟩 throughput [+2823.105op/s; +2894.704op/s] or [+41.014%; +42.055%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs netcoreapp3.1

  • 🟥 execution_time [+302.062ms; +303.203ms] or [+150.970%; +151.541%]
  • 🟩 throughput [+1411.319op/s; +1434.724op/s] or [+28.014%; +28.478%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark net472

  • 🟩 execution_time [-148.699µs; -144.873µs] or [-30.530%; -29.744%]
  • 🟩 throughput [+873.687op/s; +898.594op/s] or [+42.553%; +43.766%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark net6.0

  • 🟩 execution_time [-137.395µs; -110.780µs] or [-31.512%; -25.407%]
  • 🟩 throughput [+845.610op/s; +966.820op/s] or [+36.764%; +42.034%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark netcoreapp3.1

  • 🟩 execution_time [-144.434µs; -122.482µs] or [-30.945%; -26.242%]
  • 🟩 throughput [+793.489op/s; +875.475op/s] or [+36.629%; +40.414%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net472

  • 🟩 execution_time [-128.986µs; -124.294µs] or [-34.825%; -33.559%]
  • 🟩 throughput [+1375.503op/s; +1434.387op/s] or [+50.942%; +53.123%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net6.0

  • 🟩 execution_time [-98.211µs; -74.588µs] or [-31.354%; -23.812%]
  • 🟩 throughput [+1100.616op/s; +1303.306op/s] or [+34.309%; +40.628%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack netcoreapp3.1

  • 🟩 execution_time [-139.123µs; -116.765µs] or [-38.059%; -31.942%]
  • 🟩 throughput [+1354.824op/s; +1490.363op/s] or [+48.619%; +53.483%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net472

  • 🟥 execution_time [+299.742ms; +300.438ms] or [+149.602%; +149.949%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net6.0

  • unstable execution_time [+196.819ms; +276.768ms] or [+213.852%; +300.720%]
  • 🟩 throughput [+737.188op/s; +977.235op/s] or [+6.058%; +8.030%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest netcoreapp3.1

  • 🟥 execution_time [+367.320ms; +371.109ms] or [+278.903%; +281.780%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟥 allocated_mem [+2.847KB; +2.852KB] or [+5.057%; +5.067%]
  • unstable execution_time [+264.645ms; +330.986ms] or [+121.681%; +152.184%]
  • 🟥 throughput [-633.233op/s; -580.393op/s] or [-57.377%; -52.589%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net6.0

  • unstable execution_time [+147.346ms; +293.503ms] or [+62.793%; +125.079%]
  • 🟥 throughput [-669.839op/s; -586.370op/s] or [-44.678%; -39.111%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1

  • 🟥 execution_time [+355.812ms; +368.405ms] or [+212.817%; +220.349%]
  • 🟥 throughput [-467.695op/s; -432.667op/s] or [-32.565%; -30.126%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice net6.0

  • 🟩 execution_time [-170.891µs; -114.998µs] or [-8.657%; -5.825%]
  • 🟩 throughput [+33.549op/s; +48.414op/s] or [+6.623%; +9.557%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net472

  • 🟥 execution_time [+300.619ms; +302.919ms] or [+151.386%; +152.544%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net6.0

  • 🟥 execution_time [+300.441ms; +306.238ms] or [+150.551%; +153.456%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch netcoreapp3.1

  • 🟥 execution_time [+301.048ms; +304.756ms] or [+151.234%; +153.097%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net472

  • 🟥 execution_time [+302.509ms; +304.535ms] or [+151.910%; +152.927%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net6.0

  • 🟥 execution_time [+297.657ms; +305.619ms] or [+147.178%; +151.115%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync netcoreapp3.1

  • 🟥 execution_time [+303.029ms; +307.130ms] or [+153.588%; +155.667%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net472

  • 🟥 execution_time [+300.225ms; +301.974ms] or [+150.686%; +151.564%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net6.0

  • 🟥 execution_time [+302.499ms; +319.392ms] or [+150.768%; +159.188%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync netcoreapp3.1

  • 🟥 execution_time [+301.322ms; +304.576ms] or [+149.905%; +151.524%]

scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net6.0

  • 🟩 execution_time [-16.385ms; -12.733ms] or [-7.619%; -5.921%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net472

  • unstable execution_time [+7.260µs; +49.843µs] or [+1.793%; +12.312%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net6.0

  • 🟩 allocated_mem [-20.368KB; -20.344KB] or [-7.430%; -7.421%]
  • unstable execution_time [-25.172µs; +33.654µs] or [-4.975%; +6.652%]
  • unstable throughput [-119.410op/s; +87.180op/s] or [-5.959%; +4.350%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark netcoreapp3.1

  • unstable execution_time [-79.659µs; -19.618µs] or [-13.804%; -3.400%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net6.0

  • unstable execution_time [+8.682µs; +13.496µs] or [+20.522%; +31.902%]
  • 🟥 throughput [-5775.169op/s; -3907.547op/s] or [-24.312%; -16.450%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark netcoreapp3.1

  • unstable execution_time [-14.753µs; -7.033µs] or [-22.888%; -10.912%]
  • unstable throughput [+1804.739op/s; +3471.809op/s] or [+11.073%; +21.301%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net472

  • 🟥 execution_time [+301.506ms; +302.808ms] or [+152.398%; +153.056%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net6.0

  • 🟥 execution_time [+303.555ms; +306.311ms] or [+154.509%; +155.911%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog netcoreapp3.1

  • 🟥 execution_time [+302.088ms; +304.119ms] or [+151.232%; +152.249%]

scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net472

  • 🟥 throughput [-32629.202op/s; -30518.338op/s] or [-9.033%; -8.448%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net472

  • 🟥 execution_time [+298.565ms; +301.570ms] or [+148.808%; +150.305%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net6.0

  • 🟥 execution_time [+301.948ms; +315.991ms] or [+151.624%; +158.676%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog netcoreapp3.1

  • 🟥 execution_time [+300.409ms; +308.873ms] or [+152.348%; +156.640%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net472

  • 🟥 execution_time [+299.732ms; +301.079ms] or [+149.508%; +150.180%]
  • 🟩 throughput [+60978535.405op/s; +61389703.852op/s] or [+44.408%; +44.708%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net6.0

  • unstable execution_time [+339.552ms; +397.900ms] or [+422.293%; +494.860%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore netcoreapp3.1

  • 🟥 execution_time [+299.624ms; +300.768ms] or [+149.446%; +150.016%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net6.0

  • 🟩 throughput [+62927.215op/s; +76544.630op/s] or [+5.875%; +7.147%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope netcoreapp3.1

  • 🟩 throughput [+51392.510op/s; +70588.875op/s] or [+5.949%; +8.171%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan netcoreapp3.1

  • 🟩 throughput [+71318.574op/s; +81486.624op/s] or [+7.083%; +8.093%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net6.0

  • 🟩 throughput [+36346.419op/s; +42182.246op/s] or [+6.600%; +7.660%]

scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net6.0

  • 🟩 throughput [+59114.707op/s; +80860.375op/s] or [+6.605%; +9.034%]

Known flaky benchmarks without significant changes:

  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_AddEvent_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_AddEvent_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_AddEvent_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_GetContext_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_GetContext_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_GetContext_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetAttributes_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetAttributes_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetAttributes_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetStatus_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetStatus_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetStatus_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_UpdateName_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_UpdateName_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_UpdateName_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_AddEvent_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_AddEvent_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_AddEvent_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_GetContext_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_GetContext_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_GetContext_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_RecordException_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_RecordException_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_RecordException_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetAttributes_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetAttributes_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetAttributes_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetStatus_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetStatus_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetStatus_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_UpdateName_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_UpdateName_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_UpdateName_Sampled netcoreapp3.1
  • scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net6.0
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net6.0
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net6.0
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice netcoreapp3.1
  • scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net472
  • scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog netcoreapp3.1
  • scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net472
  • scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net6.0
  • scenario:Benchmarks.Trace.RedisBenchmark.SendReceive netcoreapp3.1
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan net6.0
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes netcoreapp3.1
  • scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net472
  • scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin netcoreapp3.1

@e-n-0 e-n-0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This head is now 40 commits behind the repository's current master, and a merge simulation reports a conflict in SecurityCoordinator.Framework.cs. Please update the branch and preserve both this PR's removal of the request-phase ResponseStatus and master's newer _localRootSpan.GetHttpClientIp() ?? _localRootSpan.GetNetworkClientIp() accessors, then rerun CI.

The main behavior is otherwise coherent, but the late ASP.NET session-cookie path currently reads cookies before the session-ID access that the PR says creates that cookie.

Comment thread tracer/test/Datadog.Trace.Security.Unit.Tests/WafAddressReuseTests.cs Outdated
Comment thread tracer/src/Datadog.Trace/AppSec/AppSecRequestContext.cs
@dromanol
dromanol force-pushed the dani/aap/waf-response-status-repro branch from 612eb10 to b6d35be Compare September 2, 2026 14:18
@dromanol
dromanol requested review from a team as code owners September 2, 2026 14:18
@dromanol
dromanol requested review from zacharycmontoya and removed request for a team September 2, 2026 14:18
@dromanol

dromanol commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on master (b6d35be), keeping both sides of the SecurityCoordinator.Framework.cs conflict: the OTel accessors from #8995 (GetHttpClientIp()/GetNetworkClientIp()) stay, and only the fabricated server.response.status this PR removes is gone.

Review feedback addressed in the same push:

  • session id read before the cookie snapshot at end of request;
  • coordinator-level tests (SecurityCoordinatorAddressesTests) for the one-shot request addresses and the end-of-request status, Core and Framework;
  • WafAddressReuseTests summary fixed.

Security unit tests: 1082 passed on net8.0, 1066 on net48. Replied inline on the AppSecRequestContext partial suggestion.

@e-n-0 e-n-0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please make these last updates before merge:

  • The PR summary says server.response.status is sent on the last run only. For endpoint-less Core requests, Scan(lastTime: true) can supply the status and CheckReturnedHeaders can perform a later response scan, so the status may be sent twice even though the WAF does not report the same match twice. Please describe the guarantee as omitting the status during request-phase scans and supplying it once the real response status is available.
  • The summary's "once per request" address claim applies to Core's one-shot collection. Framework intentionally refreshes the basic addresses on each BeginRequest, including the second pipeline created by TransferRequest. Please qualify the claim so it does not imply the Framework path uses the same lifetime.

Comment thread tracer/src/Datadog.Trace/AppSec/Coordinator/SecurityCoordinator.cs Outdated
Comment thread tracer/src/Datadog.Trace/AppSec/Coordinator/SecurityCoordinator.Framework.cs Outdated
@dromanol

dromanol commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Both wording updates are in (4a8a983), and the PR description is updated for the two summary points:

  • the status guarantee now reads as "never during the request-phase scans, sent once the real response status is known", with the endpoint-less Core case spelled out: Scan(lastTime: true) and the later response scan can both carry it, and the WAF doesn't report the same match twice;
  • the "once per request" address claim is scoped to ASP.NET Core, with the Framework BeginRequest/TransferRequest refresh called out as deliberate.

Comment-only changes on top of the previous push, net461/net6.0 still build clean.

@datadog-datadog-prod-us1-2

This comment has been minimized.

@dromanol
dromanol force-pushed the dani/aap/waf-response-status-repro branch from 4a8a983 to a6248ef Compare September 7, 2026 14:46

@e-n-0 e-n-0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed at the current head. The earlier correctness and documentation findings are resolved: the late session-cookie ordering, the TransferRequest handling, the contradictory test summary, and the address-lifetime wording all look fixed now.

Two things I'd still like covered, neither of them blocking:

  1. The two lifecycle behaviors this PR introduces are untested end to end. ResponseStartHookTests pins the IHttpResponseFeature type-name check, but nothing covers the response-start/end fallback ownership (when CheckResponseAtRequestEnd is allowed to scan versus leaving it to the hook), and nothing covers the lazy Framework session-cookie materialization in GetEndRequestArgsForWaf.

  2. The title "scan each request once" is a bit misleading. The change makes ASP.NET Core request-address collection one-shot; it does not reduce a request to one WAF invocation. Path, body, and response runs still happen, and endpoint-less requests can carry the status twice, from Scan(lastTime: true) and again from CheckReturnedHeaders. Something like "send request addresses once" would be closer to what the code does.

On benchmarks: the latest execution-time report shows no regressions. BenchmarkDotNet flags DbCommand.ExecuteNonQuery net472 at roughly -5.4% to -6.2%, but that path isn't touched here, so it looks unrelated.

Comment thread tracer/test/Datadog.Trace.Security.Unit.Tests/WafAddressReuseTests.cs Outdated
Comment thread tracer/test/Datadog.Trace.Security.Unit.Tests/WafAddressReuseTests.cs Outdated
@dromanol dromanol changed the title [AppSec] Send the real response status to the WAF and scan each request once [AppSec] Send the real response status to the WAF and stop resending the request addresses Sep 8, 2026
@dromanol

dromanol commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Wording and test-fixture points are in (4f7fe5c), and the title is now "Send the real response status to the WAF and stop resending the request addresses" — you're right that the old one promised one WAF run per request, which isn't what this does.

On the two remaining points:

1. End-to-end coverage. Agreed that both are unit-level only right now, and neither can go further in a unit test:

  • Fallback ownership: what's covered is the type-name check (ResponseStartHookTests) and the one-shot claim (ShouldScanResponse, in SecurityCoordinatorAddressesTests), so double-scanning is excluded by construction. Proving the ownership split end to end needs an HTTP.sys-hosted app on one side and a Kestrel/IIS one on the other; the repo has no HTTP.sys integration test host today, so that's a new test app rather than a new test.
  • Lazy Framework session cookie: a synthetic HttpContext.Session is always null, so this needs a net48 integration test — a session-enabled endpoint hit without cookies, asserting the cookie halves of _dd.appsec.fp.session are populated.

Neither is in this PR; I'd rather do them as a follow-up than bolt an integration host onto it. Happy to open the issue if you want it tracked.

2. Benchmarks. Same read here. DbCommand.ExecuteNonQuery net472 is the chronic flag on this pipeline and nothing in the diff goes near ADO.NET; the execution-time report is clean.

@dromanol
dromanol enabled auto-merge (squash) September 8, 2026 14:31
@dromanol
dromanol disabled auto-merge September 8, 2026 18:04

@andrewlock andrewlock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just approving the tracing side, haven't reviewed the ASM side thoroughly, but just wondering why we're not using the OnStarting hook for aspnetcore? Unless we already are, and it's just not visibile in this diff 😄

@dromanol

dromanol commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

@andrewlock good question — it's not visible in the diff because the response-start hook predates this PR: it's a CallTarget on HttpProtocol.FireOnStarting (Kestrel) and IISHttpContext.FireOnStarting (IIS), shared with IAST (FireOnStartCommon).

The reason it isn't a registered OnStarting callback is blocking. Both servers run the callbacks inside a try/catch that turns any exception into an application error — Kestrel's HttpProtocol.ProcessEvents does catch (Exception ex) { protocol.ReportApplicationError(ex); } (with the upstream comment "If an OnStarting callback throws we can go through our normal error handling in ProduceEnd"), and IISHttpContext.FireOnStarting does the same before ThrowResponseAbortedException. A BlockException thrown from a callback would become a 500 / aborted response and never reach BlockingMiddleware. Throwing from the CallTarget's OnMethodEnd puts the throw outside that try/catch, in the caller's frame (InitializeResponseAsync / FirstWriteAsync, i.e. the app's first write), so it unwinds through the pipeline and the middleware emits the configured block response.

That said, you're right that OnStarting is worth using — as a complement, not a replacement:

  • HTTP.sys, the server this PR's fallback exists for, does not swallow callback exceptions (RequestContext.FeatureCollection.NotifiyOnStartingAsync), so there a registered callback could scan and block, which is strictly better than the report-only end-of-request fallback.
  • On Kestrel, FireOnStarting is only called from ProcessRequests when _onStarting?.Count > 0, and ProduceEnd starts the response via ProduceStart(appCompleted: true) without firing it — so a body-less response on an app where nothing registered a callback never reaches our hook. Registering our own would guarantee it fires.

Tracked in APPSEC-70098, with the detail above and the scope (one-shot guard so the callback and the hook can't both scan, HTTP.sys test host).

@e-n-0 the two end-to-end coverage gaps from your review are now tracked in APPSEC-70099 (HTTP.sys vs Kestrel/IIS scan ownership, and the lazy Framework session cookie), cross-linked with APPSEC-70098 since the first one changes shape if the HTTP.sys path moves to OnStarting.

…st once

server.response.status came from the request-phase address set, where
HttpContext.Response.StatusCode is still the default 200. It is now sent only on
the last run of the request, together with the response headers.

The request addresses are supplied once: the WAF keeps them for the life of its
context, so a later run re-evaluates rules and processors against the stored
values instead of paying for the whole set again. ASP.NET's session cookie is the
exception, since it only lands in Request.Cookies once the session id is read, so
the end of request run re-reads the cookies.

Servers without the instrumented response start hook (HTTP.sys) never saw a real
status at all; they now get a report-only scan at the end of the pipeline.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
dromanol and others added 5 commits September 9, 2026 16:21
A Server.TransferRequest pipeline shares the trace context, so the one-shot
flag swallowed the transferred request's addresses. EndRequest starts from an
empty set instead. Also pins that a re-supplied status can't report twice.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Read the ASP.NET session id before snapshotting the request cookies, so the
session cookie is in there when the fingerprint is built. Add coordinator-level
tests for the one-shot request addresses and the end-of-request status, and fix
the WafAddressReuseTests summary.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The one-shot address collection is the Core path only, and the session id read
at end of request is a guard for hosts where SessionStateModule hasn't made the
cookie visible yet.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ture

The coordinator tests mock the WAF, so they don't need the native library
initialised by WafLibraryRequiredTest, only the sequential collection.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
#9090 changed IWaf.CreateContext to report a typed outcome through an out
parameter; the tests added here still used the old overload.
@dromanol
dromanol force-pushed the dani/aap/waf-response-status-repro branch from 4f7fe5c to 3924a44 Compare September 9, 2026 14:37
@dromanol
dromanol merged commit 11b1709 into master Sep 9, 2026
144 checks passed
@dromanol
dromanol deleted the dani/aap/waf-response-status-repro branch September 9, 2026 16:03
@github-actions github-actions Bot added this to the vNext-v3 milestone Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants