Skip to content

fix(appsec): support apollo v5 blocking#9007

Merged
IlyasShabi merged 7 commits into
masterfrom
ishabi/apollo-v5-blocking
Jul 7, 2026
Merged

fix(appsec): support apollo v5 blocking#9007
IlyasShabi merged 7 commits into
masterfrom
ishabi/apollo-v5-blocking

Conversation

@IlyasShabi

@IlyasShabi IlyasShabi commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR extends the HeaderMap.js hook from versions: ['4'] to ['>=4'] so it also fires for v5. It also adds an integration test that verifies blocking returns 403 with appsec.blocked: 'true' on Apollo v5.

Motivation

The previous PR adding Apollo Server v5 support (#6155) did not cover blocking on v5

Additional Notes

APPSEC-68543

@dd-octo-sts

dd-octo-sts Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 6.57 MB
Deduped: 7.23 MB
No deduping: 7.23 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.0 | 117.14 kB | 432.47 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@datadog-official

datadog-official Bot commented Jun 22, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 50.00%
Overall Coverage: 87.71% (-0.05%)

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

@pr-commenter

pr-commenter Bot commented Jun 22, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-07-07 08:23:18

Comparing candidate commit 3b4b681 in PR branch ishabi/apollo-v5-blocking with baseline commit 9bcb78f in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2246 metrics, 40 unstable metrics.

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 ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:appsec-appsec-enabled-24

  • unstable execution_time [-185.996ms; +181.783ms] or [-7.054%; +6.894%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-201.125ms; +210.905ms] or [-8.011%; +8.401%]

scenario:appsec-appsec-enabled-with-attacks-26

  • unstable execution_time [-156354.768µs; +156583.168µs] or [-5.406%; +5.414%]

scenario:appsec-control-20

  • unstable execution_time [-117.052ms; +113.762ms] or [-7.197%; +6.995%]

scenario:appsec-control-24

  • unstable execution_time [-107424.202µs; +106591.002µs] or [-8.782%; +8.714%]

scenario:appsec-control-26

  • unstable execution_time [-115.346ms; +118.657ms] or [-9.517%; +9.790%]

scenario:appsec-iast-no-vulnerability-iast-enabled-always-active-20

  • unstable execution_time [-11.094ms; +15.643ms] or [-4.477%; +6.313%]

scenario:debugger-line-probe-with-snapshot-default-24

  • unstable cpu_user_time [-1451.148ms; +545.189ms] or [-16.922%; +6.358%]
  • unstable execution_time [-1461.714ms; +538.163ms] or [-15.763%; +5.804%]
  • unstable instructions [-12.5G instructions; +4.5G instructions] or [-17.854%; +6.356%]
  • unstable throughput [-183.316op/s; +425.037op/s] or [-5.200%; +12.057%]

scenario:debugger-line-probe-with-snapshot-default-26

  • unstable cpu_user_time [-2127.870ms; +3390.302ms] or [-22.603%; +36.013%]
  • unstable execution_time [-2120.494ms; +3417.774ms] or [-20.971%; +33.801%]
  • unstable instructions [-18.7G instructions; +30.0G instructions] or [-23.935%; +38.303%]
  • unstable max_rss_usage [-6.699MB; +11.469MB] or [-4.218%; +7.222%]
  • unstable throughput [-736.482op/s; +454.112op/s] or [-22.668%; +13.977%]

scenario:debugger-line-probe-with-snapshot-minimal-24

  • unstable cpu_user_time [-1517.845ms; +2714.006ms] or [-18.127%; +32.412%]
  • unstable execution_time [-1540.999ms; +2744.606ms] or [-17.025%; +30.322%]
  • unstable instructions [-12.6G instructions; +22.7G instructions] or [-18.379%; +33.275%]
  • unstable max_rss_usage [-6.299MB; +9.996MB] or [-4.020%; +6.380%]
  • unstable throughput [-789.151op/s; +415.462op/s] or [-21.808%; +11.481%]

scenario:debugger-line-probe-with-snapshot-minimal-26

  • unstable cpu_user_time [-2136.375ms; +3267.233ms] or [-22.870%; +34.976%]
  • unstable execution_time [-2154.026ms; +3306.955ms] or [-21.478%; +32.974%]
  • unstable instructions [-19.3G instructions; +29.4G instructions] or [-24.740%; +37.815%]
  • unstable max_rss_usage [-6.643MB; +11.611MB] or [-4.175%; +7.299%]
  • unstable throughput [-722.190op/s; +484.176op/s] or [-22.053%; +14.785%]

scenario:debugger-line-probe-without-snapshot-24

  • unstable cpu_user_time [-2020.796ms; +3426.331ms] or [-21.852%; +37.051%]
  • unstable execution_time [-2070.821ms; +3482.314ms] or [-20.815%; +35.003%]
  • unstable instructions [-16.9G instructions; +29.4G instructions] or [-22.285%; +38.731%]
  • unstable max_rss_usage [-10.155MB; +13.388MB] or [-6.273%; +8.270%]
  • unstable throughput [-1027.947op/s; +530.801op/s] or [-30.244%; +15.617%]

scenario:debugger-line-probe-without-snapshot-26

  • unstable cpu_user_time [-2887.541ms; +2977.448ms] or [-28.936%; +29.837%]
  • unstable execution_time [-2860.065ms; +2975.072ms] or [-26.764%; +27.840%]
  • unstable instructions [-25683.5M instructions; +26731.3M instructions] or [-30.761%; +32.016%]
  • unstable max_rss_usage [-8778.000KB; +9419.600KB] or [-5.449%; +5.847%]
  • unstable throughput [-657.506op/s; +611.903op/s] or [-20.997%; +19.540%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-537.241ms; +35.245ms] or [-11.185%; +0.734%]
  • unstable execution_time [-532.845ms; +39.414ms] or [-10.924%; +0.808%]
  • unstable throughput [-14456.423op/s; +182547.322op/s] or [-0.840%; +10.607%]

scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-3.095MB; +8.568MB] or [-3.853%; +10.668%]

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.46%. Comparing base (9bcb78f) to head (3b4b681).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
packages/dd-trace/src/appsec/graphql.js 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9007      +/-   ##
==========================================
- Coverage   93.59%   93.46%   -0.13%     
==========================================
  Files         900      900              
  Lines       52679    52939     +260     
  Branches    12405    12492      +87     
==========================================
+ Hits        49306    49481     +175     
- Misses       3373     3458      +85     
Flag Coverage Δ
aiguard 34.97% <ø> (-0.09%) ⬇️
aiguard-integration 41.96% <ø> (-0.02%) ⬇️
apm-bucket-0 34.89% <ø> (-0.03%) ⬇️
apm-bucket-1 40.49% <ø> (-0.09%) ⬇️
apm-bucket-2 37.48% <ø> (-0.09%) ⬇️
apm-capabilities-tracing 48.94% <0.00%> (-0.02%) ⬇️
apm-integrations-aerospike 33.11% <ø> (-0.09%) ⬇️
apm-integrations-confluentinc-kafka-javascript 40.01% <ø> (-0.19%) ⬇️
apm-integrations-couchbase 33.39% <ø> (-0.09%) ⬇️
apm-integrations-http 42.03% <0.00%> (-0.09%) ⬇️
apm-integrations-kafkajs 40.25% <ø> (-0.09%) ⬇️
apm-integrations-next 29.58% <ø> (-0.12%) ⬇️
apm-integrations-prisma 35.17% <ø> (-0.09%) ⬇️
apm-integrations-tedious 34.03% <ø> (-0.09%) ⬇️
appsec 57.81% <71.42%> (-0.08%) ⬇️
appsec-express_fastify_graphql 53.85% <75.00%> (-0.07%) ⬇️
appsec-integration 35.55% <75.00%> (-0.06%) ⬇️
appsec-kafka_ldapjs_lodash 43.74% <ø> (-0.09%) ⬇️
appsec-mongodb-core_mongoose_mysql 48.88% <0.00%> (-0.08%) ⬇️
appsec-next 27.66% <ø> (-0.45%) ⬇️
appsec-node-serialize_passport_postgres 48.06% <0.00%> (-0.08%) ⬇️
appsec-sourcing_stripe_template 45.62% <0.00%> (-0.21%) ⬇️
debugger 44.61% <ø> (-0.03%) ⬇️
instrumentations-bucket-0 28.15% <ø> (-0.09%) ⬇️
instrumentations-bucket-1 37.59% <ø> (-0.05%) ⬇️
instrumentations-bucket-10 40.49% <0.00%> (-0.09%) ⬇️
instrumentations-bucket-11 27.95% <ø> (-0.09%) ⬇️
instrumentations-bucket-12 28.78% <ø> (-0.09%) ⬇️
instrumentations-bucket-13 ?
instrumentations-bucket-2 30.35% <ø> (-0.09%) ⬇️
instrumentations-bucket-3 ?
instrumentations-bucket-4 28.59% <ø> (-0.07%) ⬇️
instrumentations-bucket-5 ?
instrumentations-bucket-6 38.41% <ø> (-0.09%) ⬇️
instrumentations-bucket-7 36.13% <ø> (-0.10%) ⬇️
instrumentations-bucket-8 37.09% <ø> (-0.09%) ⬇️
instrumentations-bucket-9 39.59% <0.00%> (-0.09%) ⬇️
instrumentations-instrumentation-couchbase 46.48% <ø> (ø)
instrumentations-integration-esbuild 24.29% <100.00%> (-0.18%) ⬇️
llmobs-ai_anthropic_bedrock 39.67% <ø> (-0.08%) ⬇️
llmobs-google-genai_langchain_vertex-ai 36.97% <ø> (-0.19%) ⬇️
llmobs-openai 39.73% <ø> (-0.09%) ⬇️
llmobs-sdk 43.57% <ø> (-0.10%) ⬇️
master-coverage 93.46% <75.00%> (?)
openfeature 37.92% <ø> (-0.02%) ⬇️
openfeature-unit 50.47% <ø> (ø)
platform-core_esbuild_instrumentations-misc 22.72% <100.00%> (-0.20%) ⬇️
platform-integration 47.56% <ø> (-0.02%) ⬇️
platform-shimmer_unit-guardrails_webpack 18.25% <100.00%> (-0.19%) ⬇️
plugins-bucket-0 36.51% <ø> (-0.08%) ⬇️
plugins-bucket-1 39.76% <ø> (-0.02%) ⬇️
plugins-bucket-11 38.61% <ø> (-0.09%) ⬇️
plugins-bucket-17 39.20% <ø> (-0.09%) ⬇️
plugins-bucket-18 42.17% <100.00%> (-0.08%) ⬇️
plugins-bucket-19 39.96% <ø> (-0.09%) ⬇️
plugins-bucket-20 43.36% <ø> (-0.15%) ⬇️
plugins-bucket-4 37.88% <ø> (-0.07%) ⬇️
plugins-bullmq_cassandra_cookie 39.91% <ø> (-0.09%) ⬇️
plugins-cookie-parser_crypto_dd-trace-api 33.21% <ø> (-0.09%) ⬇️
plugins-fetch_fs_generic-pool 36.19% <ø> (-0.09%) ⬇️
plugins-google-cloud-pubsub_grpc_handlebars 43.07% <ø> (-0.09%) ⬇️
plugins-hapi_hono_ioredis 37.93% <ø> (-0.09%) ⬇️
plugins-jest_knex_langgraph 32.60% <ø> (-0.09%) ⬇️
plugins-ldapjs_light-my-request_limitd-client 27.91% <ø> (-0.03%) ⬇️
plugins-lodash_mariadb_memcached 35.16% <ø> (-0.09%) ⬇️
plugins-mongodb_mongodb-core_mongoose 36.45% <ø> (-0.09%) ⬇️
plugins-multer_mysql_mysql2 35.13% <ø> (-0.09%) ⬇️
plugins-nats_node-serialize_opensearch 37.29% <ø> (-0.09%) ⬇️
plugins-passport-http_pino_postgres 35.52% <ø> (-0.09%) ⬇️
plugins-process_pug_redis 34.25% <ø> (-0.10%) ⬇️
plugins-undici_url_valkey 36.02% <ø> (-0.09%) ⬇️
plugins-vm_winston_ws 37.70% <ø> (-0.09%) ⬇️
profiling 43.82% <ø> (-0.08%) ⬇️
serverless-aws-sdk-aws-sdk 33.31% <ø> (-0.08%) ⬇️
serverless-aws-sdk-bedrockruntime 32.18% <ø> (-0.08%) ⬇️
serverless-aws-sdk-client 37.16% <ø> (ø)
serverless-aws-sdk-dynamodb 34.18% <ø> (-0.03%) ⬇️
serverless-aws-sdk-eventbridge 27.35% <ø> (-0.08%) ⬇️
serverless-aws-sdk-kinesis 37.53% <ø> (-0.08%) ⬇️
serverless-aws-sdk-lambda 34.62% <ø> (-0.08%) ⬇️
serverless-aws-sdk-s3 32.62% <ø> (-0.08%) ⬇️
serverless-aws-sdk-serverless-peer-service 39.63% <ø> (-0.10%) ⬇️
serverless-aws-sdk-sns 38.39% <ø> (-0.08%) ⬇️
serverless-aws-sdk-sqs 38.13% <ø> (-0.08%) ⬇️
serverless-aws-sdk-stepfunctions 33.21% <ø> (-0.08%) ⬇️
serverless-aws-sdk-util 47.95% <ø> (ø)
serverless-bucket-0 39.62% <ø> (-0.02%) ⬇️
serverless-lambda 34.32% <ø> (-0.11%) ⬇️
test-optimization-cucumber 52.39% <ø> (+0.15%) ⬆️
test-optimization-cypress 50.14% <ø> (+0.15%) ⬆️
test-optimization-jest 55.87% <ø> (+0.43%) ⬆️
test-optimization-mocha 53.50% <ø> (+0.09%) ⬆️
test-optimization-playwright-playwright-atr 43.42% <ø> (+0.07%) ⬆️
test-optimization-playwright-playwright-efd 43.70% <ø> (+0.07%) ⬆️
test-optimization-playwright-playwright-final-status 43.82% <ø> (+0.07%) ⬆️
test-optimization-playwright-playwright-impacted-tests 43.25% <ø> (-0.02%) ⬇️
test-optimization-playwright-playwright-reporting 43.36% <ø> (+0.07%) ⬆️
test-optimization-playwright-playwright-test-management 44.81% <ø> (+0.07%) ⬆️
test-optimization-playwright-playwright-test-span 44.60% <ø> (+0.06%) ⬆️
test-optimization-selenium 45.35% <ø> (+<0.01%) ⬆️
test-optimization-testopt 46.67% <ø> (+0.01%) ⬆️
test-optimization-vitest 52.65% <ø> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@IlyasShabi
IlyasShabi marked this pull request as ready for review June 24, 2026 07:55
@IlyasShabi
IlyasShabi requested review from a team as code owners June 24, 2026 07:55
@IlyasShabi
IlyasShabi requested review from tlhunter and removed request for a team June 24, 2026 07:55

@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: 2bdf60609e

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


addHook({ name: '@apollo/server', file: 'dist/cjs/utils/HeaderMap.js', versions: ['4'] }, apolloHeaderMapHook)
addHook(
{ name: '@apollo/server', file: 'dist/cjs/utils/HeaderMap.js', versions: ['>=4'] },

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 Preserve block status for Apollo v5 batched requests

When users enable Apollo Server's allowBatchedHttpRequests, this v5 hook now activates blocking inside runHttpQuery, which Apollo calls once per operation in a batch. The per-operation response returned by wrapExecuteHTTPGraphQLRequest carries the 403 status and block headers, but Apollo's batch combiner only uses each operation's response.body.string and keeps the shared HTTP head, so a blocked operation can be returned as part of a 200 batch response instead of blocking the HTTP request. The v5 path needs to wrap the whole HTTP request or propagate the blocking status/headers back to the shared batch response.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is correct, I'll fix it

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.

I'll set this PR as draft, feel free to undraft it once this comment is addressed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I addressed it but amended the commit sorry!

uurien
uurien previously approved these changes Jun 24, 2026
)

addHook(
{ name: '@apollo/server', file: 'dist/cjs/runHttpQuery.js', versions: ['>=5.0.0'] },

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.

why isn't this necessary anymore?

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.

I have the same question. All I can think is that the other now-version-uncapped hook handles this functionality.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed it because it's not needed for instrumentation of v5, executeHTTPGraphQLRequest is the public entry and I switched it to >=4.
The real between v4 and v5 was just that HeaderMap lives in a slightly different module load path. By removing previous v5 instrumentation we are relying on what we did for v4 for blocking

@tlhunter
tlhunter marked this pull request as draft June 24, 2026 15:33
@IlyasShabi
IlyasShabi marked this pull request as ready for review June 26, 2026 08:25

@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: 4600cd0207

ℹ️ 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 packages/datadog-instrumentations/src/apollo-server.js
@IlyasShabi
IlyasShabi requested a review from uurien June 30, 2026 08:59
Comment thread packages/dd-trace/test/appsec/graphql.spec.js Outdated
Comment on lines +182 to +184
assert.strictEqual(payload[1][0].name, 'web.request')
assert.strictEqual(payload[1][0].meta['appsec.blocked'], 'true')
assert.strictEqual(payload[1][0].meta['appsec.event'], 'true')

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.

The assertion collection here is smaller than the ones in the previous test cases. It'd be good to keep assertions consistent acroos all the cases... or is there a reason to use a smaller set here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did the same as previous test!

@IlyasShabi
IlyasShabi requested a review from CarlesDD July 6, 2026 14:51
@IlyasShabi
IlyasShabi merged commit 872f1a8 into master Jul 7, 2026
651 of 652 checks passed
@IlyasShabi
IlyasShabi deleted the ishabi/apollo-v5-blocking branch July 7, 2026 10:11
dd-octo-sts Bot pushed a commit that referenced this pull request Jul 7, 2026
* fix(appsec): support apollo v5 blocking
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Jul 7, 2026
dd-octo-sts Bot pushed a commit that referenced this pull request Jul 7, 2026
* fix(appsec): support apollo v5 blocking
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Jul 7, 2026
juan-fernandez pushed a commit that referenced this pull request Jul 8, 2026
* fix(appsec): support apollo v5 blocking
juan-fernandez pushed a commit that referenced this pull request Jul 8, 2026
* fix(appsec): support apollo v5 blocking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants