Skip to content

fix(instrumentation): wrap lazily defined fs.opendir on Node 20#9094

Merged
szegedi merged 1 commit into
masterfrom
BridgeAR/2026-06-26-fix-iast-opendir-node20
Jun 30, 2026
Merged

fix(instrumentation): wrap lazily defined fs.opendir on Node 20#9094
szegedi merged 1 commit into
masterfrom
BridgeAR/2026-06-26-fix-iast-opendir-node20

Conversation

@BridgeAR

@BridgeAR BridgeAR commented Jun 26, 2026

Copy link
Copy Markdown
Member

Summary

On Node 20, fs.opendir and fs.opendirSync are lazy get+set accessor properties: the getter resolves the real function (and self-replaces with a data property) on first read. The fs instrumentation mass-wrapped these names with shimmer.wrap, which received the getter and instrumented the property access (get opendir) instead of the method. The real call then ran uninstrumented, apm:fs:operation:start never fired with the directory path, and IAST reported no PATH_TRAVERSAL vulnerability (and RASP no LFI) for fs.opendir / opendirSync requests. Node 18 and 22 define both as plain data properties, so the operation was lost only on Node 20 — surfacing as an intermittent failure of the fs.opendir / fs.opendirSync cases in path-traversal-analyzer.spec.js.

  1. shimmer.wrap's replaceGetter option now also handles a getter+setter accessor: it resolves the value once through the getter and redefines the property as a wrapped data property, dropping the accessor. It previously threw for a get+set pair.
  2. The fs instrumentation passes replaceGetter when wrapping fs methods, so the lazy accessors resolve to the real function. A no-op for the data properties on Node 18 and 22.

Test plan

  • packages/datadog-shimmer/test/shimmer.spec.js gains a case for the getter+setter replaceGetter path (asserts the property is redefined as a wrapped data property) and one for the getter+setter rejection without the option. The first fails on the pre-fix shimmer.
  • packages/datadog-instrumentations/test/fs.spec.js asserts fs.opendir / opendirSync are wrapped as methods (not accessors) and that apm:fs:operation:start publishes the method's own operation and path. Both fail on master under Node 20.
  • packages/dd-trace/test/appsec/iast/analyzers/path-traversal-analyzer.spec.js — the opendir cases now pass deterministically (10 consecutive runs on Node 20).
  • Green on Node 18, 20, and 22 for the shimmer spec, the fs instrumentation spec, the IAST path-traversal spec, and the RASP fs-plugin / lfi specs.

@dd-octo-sts

dd-octo-sts Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 6.4 MB
Deduped: 7.46 MB
No deduping: 7.46 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.2.0 | 104.26 kB | 843.44 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

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.69%. Comparing base (27dcc31) to head (0b0f79c).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9094   +/-   ##
=======================================
  Coverage   93.69%   93.69%           
=======================================
  Files         889      889           
  Lines       50856    50858    +2     
  Branches    11830    11829    -1     
=======================================
+ Hits        47647    47650    +3     
+ Misses       3209     3208    -1     
Flag Coverage Δ
aiguard 34.88% <71.42%> (-0.08%) ⬇️
aiguard-integration 41.80% <85.71%> (+<0.01%) ⬆️
apm-bucket-0 34.85% <71.42%> (-0.08%) ⬇️
apm-bucket-1 40.34% <71.42%> (-0.07%) ⬇️
apm-bucket-2 37.35% <71.42%> (-0.07%) ⬇️
apm-capabilities-tracing 48.29% <71.42%> (+<0.01%) ⬆️
apm-integrations-aerospike 33.13% <71.42%> (-0.08%) ⬇️
apm-integrations-confluentinc-kafka-javascript 40.04% <71.42%> (-0.08%) ⬇️
apm-integrations-couchbase 33.25% <71.42%> (-0.35%) ⬇️
apm-integrations-http 42.05% <71.42%> (-0.07%) ⬇️
apm-integrations-kafkajs 40.27% <71.42%> (-0.07%) ⬇️
apm-integrations-next 29.51% <71.42%> (-0.07%) ⬇️
apm-integrations-prisma 35.04% <71.42%> (-0.07%) ⬇️
apm-integrations-tedious 33.90% <71.42%> (-0.07%) ⬇️
appsec 57.30% <71.42%> (-0.15%) ⬇️
appsec-express_fastify_graphql 53.76% <71.42%> (-0.04%) ⬇️
appsec-integration 36.26% <85.71%> (+<0.01%) ⬆️
appsec-kafka_ldapjs_lodash 43.60% <71.42%> (-0.07%) ⬇️
appsec-mongodb-core_mongoose_mysql 48.82% <71.42%> (-0.06%) ⬇️
appsec-next 28.01% <71.42%> (-0.07%) ⬇️
appsec-node-serialize_passport_postgres 48.01% <71.42%> (-0.06%) ⬇️
appsec-sourcing_stripe_template 45.56% <71.42%> (-0.06%) ⬇️
debugger 44.43% <85.71%> (+0.01%) ⬆️
instrumentations-bucket-0 28.16% <71.42%> (-0.08%) ⬇️
instrumentations-bucket-1 37.42% <71.42%> (-0.07%) ⬇️
instrumentations-bucket-10 40.44% <71.42%> (-0.07%) ⬇️
instrumentations-bucket-11 27.96% <71.42%> (-0.08%) ⬇️
instrumentations-bucket-12 28.68% <71.42%> (-0.07%) ⬇️
instrumentations-bucket-13 27.79% <71.42%> (-0.08%) ⬇️
instrumentations-bucket-2 30.24% <71.42%> (-0.07%) ⬇️
instrumentations-bucket-3 35.92% <71.42%> (-0.07%) ⬇️
instrumentations-bucket-4 28.57% <71.42%> (+0.42%) ⬆️
instrumentations-bucket-5 36.29% <71.42%> (-0.07%) ⬇️
instrumentations-bucket-6 38.26% <71.42%> (-0.07%) ⬇️
instrumentations-bucket-7 35.92% <71.42%> (-0.15%) ⬇️
instrumentations-bucket-8 36.96% <71.42%> (-0.07%) ⬇️
instrumentations-bucket-9 39.54% <71.42%> (-0.07%) ⬇️
instrumentations-instrumentation-couchbase 46.48% <25.00%> (-0.07%) ⬇️
instrumentations-integration-esbuild 24.88% <85.71%> (+<0.01%) ⬆️
llmobs-ai_anthropic_bedrock 39.54% <71.42%> (-0.06%) ⬇️
llmobs-google-genai_langchain_vertex-ai 36.86% <71.42%> (-0.18%) ⬇️
llmobs-openai 39.59% <71.42%> (-0.07%) ⬇️
llmobs-sdk 43.61% <71.42%> (-0.08%) ⬇️
master-coverage 93.69% <100.00%> (?)
openfeature 37.77% <85.71%> (+<0.01%) ⬆️
openfeature-unit 50.39% <ø> (ø)
platform-core_esbuild_instrumentations-misc 23.36% <71.42%> (+<0.01%) ⬆️
platform-integration 47.45% <85.71%> (+0.02%) ⬆️
platform-shimmer_unit-guardrails_webpack 18.90% <100.00%> (+0.01%) ⬆️
plugins-bucket-0 36.34% <71.42%> (-0.07%) ⬇️
plugins-bucket-1 39.61% <71.42%> (+<0.01%) ⬆️
plugins-bucket-11 38.47% <71.42%> (-0.07%) ⬇️
plugins-bucket-17 39.16% <71.42%> (-0.07%) ⬇️
plugins-bucket-18 42.01% <71.42%> (-0.07%) ⬇️
plugins-bucket-19 39.57% <71.42%> (-0.07%) ⬇️
plugins-bucket-20 43.29% <71.42%> (-0.07%) ⬇️
plugins-bucket-4 37.72% <71.42%> (-0.07%) ⬇️
plugins-bullmq_cassandra_cookie 39.77% <71.42%> (-0.07%) ⬇️
plugins-cookie-parser_crypto_dd-trace-api 33.23% <71.42%> (-0.08%) ⬇️
plugins-fetch_fs_generic-pool 36.06% <71.42%> (-0.07%) ⬇️
plugins-google-cloud-pubsub_grpc_handlebars 43.11% <71.42%> (-0.08%) ⬇️
plugins-hapi_hono_ioredis 37.79% <71.42%> (-0.07%) ⬇️
plugins-jest_knex_langgraph 32.61% <71.42%> (-0.08%) ⬇️
plugins-ldapjs_light-my-request_limitd-client 27.92% <71.42%> (-0.02%) ⬇️
plugins-lodash_mariadb_memcached 35.12% <71.42%> (-0.14%) ⬇️
plugins-mongodb_mongodb-core_mongoose 36.32% <71.42%> (-0.07%) ⬇️
plugins-multer_mysql_mysql2 35.16% <71.42%> (-0.08%) ⬇️
plugins-nats_node-serialize_opensearch 37.16% <71.42%> (-0.07%) ⬇️
plugins-passport-http_pino_postgres 35.54% <71.42%> (-0.08%) ⬇️
plugins-process_pug_redis 34.27% <71.42%> (-0.08%) ⬇️
plugins-undici_url_valkey 35.89% <71.42%> (-0.07%) ⬇️
plugins-vm_winston_ws 37.56% <71.42%> (-0.07%) ⬇️
profiling 43.63% <85.71%> (-0.06%) ⬇️
serverless-aws-sdk-aws-sdk 33.30% <71.42%> (-0.06%) ⬇️
serverless-aws-sdk-bedrockruntime 32.17% <71.42%> (-0.07%) ⬇️
serverless-aws-sdk-client 37.16% <0.00%> (-0.05%) ⬇️
serverless-aws-sdk-dynamodb 34.15% <71.42%> (-0.07%) ⬇️
serverless-aws-sdk-eventbridge 27.26% <71.42%> (-0.07%) ⬇️
serverless-aws-sdk-kinesis 37.41% <71.42%> (-0.07%) ⬇️
serverless-aws-sdk-lambda 34.60% <71.42%> (-0.07%) ⬇️
serverless-aws-sdk-s3 32.60% <71.42%> (-0.07%) ⬇️
serverless-aws-sdk-serverless-peer-service 39.47% <50.00%> (-0.08%) ⬇️
serverless-aws-sdk-sns 38.26% <71.42%> (-0.19%) ⬇️
serverless-aws-sdk-sqs 38.01% <71.42%> (-0.07%) ⬇️
serverless-aws-sdk-stepfunctions 33.19% <71.42%> (-0.07%) ⬇️
serverless-aws-sdk-util 47.95% <ø> (ø)
serverless-bucket-0 39.47% <71.42%> (+<0.01%) ⬆️
serverless-lambda 34.33% <71.42%> (-0.09%) ⬇️
test-optimization-cucumber 52.57% <71.42%> (+0.11%) ⬆️
test-optimization-cypress 49.62% <71.42%> (+0.07%) ⬆️
test-optimization-jest 55.67% <71.42%> (+0.11%) ⬆️
test-optimization-mocha 53.66% <71.42%> (+0.08%) ⬆️
test-optimization-playwright-playwright-atr 43.59% <71.42%> (+0.08%) ⬆️
test-optimization-playwright-playwright-efd 43.88% <71.42%> (+0.08%) ⬆️
test-optimization-playwright-playwright-final-status 43.93% <71.42%> (+0.08%) ⬆️
test-optimization-playwright-playwright-impacted-tests 43.41% <71.42%> (+<0.01%) ⬆️
test-optimization-playwright-playwright-reporting 43.50% <71.42%> (+0.08%) ⬆️
test-optimization-playwright-playwright-test-management 44.93% <71.42%> (+0.08%) ⬆️
test-optimization-playwright-playwright-test-span 44.78% <71.42%> (+0.08%) ⬆️
test-optimization-selenium 45.52% <71.42%> (+0.06%) ⬆️
test-optimization-testopt 48.29% <85.71%> (+0.09%) ⬆️
test-optimization-vitest 50.93% <71.42%> (+0.10%) ⬆️

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.

@datadog-prod-us1-3

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

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 87.99% (+0.01%)

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

@pr-commenter

pr-commenter Bot commented Jun 26, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-06-27 15:21:26

Comparing candidate commit 0b0f79c in PR branch BridgeAR/2026-06-26-fix-iast-opendir-node20 with baseline commit 27dcc31 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 [-190.824ms; +181.210ms] or [-7.254%; +6.888%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-209.905ms; +206.907ms] or [-8.337%; +8.218%]

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

  • unstable execution_time [-155605.617µs; +155195.183µs] or [-5.425%; +5.411%]

scenario:appsec-control-20

  • unstable execution_time [-144.131ms; +166.084ms] or [-8.283%; +9.544%]

scenario:appsec-control-24

  • unstable execution_time [-105926.927µs; +106078.827µs] or [-8.690%; +8.702%]

scenario:appsec-control-26

  • unstable execution_time [-111529.307µs; +113192.873µs] or [-9.237%; +9.375%]

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

  • unstable cpu_user_time [-1692.657ms; +569.809ms] or [-21.390%; +7.201%]
  • unstable execution_time [-1710.033ms; +590.151ms] or [-19.883%; +6.862%]
  • unstable instructions [-14.5G instructions; +4.8G instructions] or [-22.380%; +7.390%]
  • unstable throughput [-177.862op/s; +492.936op/s] or [-4.627%; +12.823%]

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

  • unstable cpu_user_time [-2.152s; +4.693s] or [-21.704%; +47.320%]
  • unstable execution_time [-2.145s; +4.717s] or [-20.218%; +44.463%]
  • unstable instructions [-19.0G instructions; +42.0G instructions] or [-23.048%; +50.909%]
  • unstable max_rss_usage [-6.470MB; +13.450MB] or [-3.996%; +8.306%]
  • unstable throughput [-1047.296op/s; +470.369op/s] or [-33.133%; +14.881%]

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

  • unstable cpu_user_time [-1680.037ms; +523.083ms] or [-21.171%; +6.592%]
  • unstable execution_time [-1687.331ms; +532.803ms] or [-19.584%; +6.184%]
  • unstable instructions [-14.2G instructions; +4.6G instructions] or [-22.040%; +7.140%]
  • unstable throughput [-154.699op/s; +497.519op/s] or [-4.038%; +12.986%]

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

  • unstable cpu_user_time [-3700.082ms; +2416.100ms] or [-34.963%; +22.830%]
  • unstable execution_time [-3750.094ms; +2455.253ms] or [-33.264%; +21.778%]
  • unstable instructions [-33.1G instructions; +21.5G instructions] or [-37.163%; +24.125%]
  • unstable max_rss_usage [-11.188MB; +7.824MB] or [-6.861%; +4.798%]
  • unstable throughput [-533.964op/s; +827.553op/s] or [-17.773%; +27.546%]

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

  • unstable cpu_user_time [-1932.706ms; +3054.968ms] or [-24.442%; +38.634%]
  • unstable execution_time [-1972.171ms; +3095.003ms] or [-22.943%; +36.005%]
  • unstable instructions [-16.4G instructions; +26.0G instructions] or [-25.447%; +40.321%]
  • unstable max_rss_usage [-6.828MB; +11.087MB] or [-4.317%; +7.010%]
  • unstable throughput [-905.504op/s; +582.465op/s] or [-23.560%; +15.155%]

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

  • unstable cpu_user_time [-2.530s; +5.332s] or [-25.138%; +52.972%]
  • unstable execution_time [-2.580s; +5.399s] or [-23.989%; +50.201%]
  • unstable instructions [-21.8G instructions; +46.9G instructions] or [-25.911%; +55.818%]
  • unstable max_rss_usage [-7.434MB; +15.933MB] or [-4.606%; +9.872%]
  • unstable throughput [-1121.479op/s; +542.960op/s] or [-35.633%; +17.251%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-272.437ms; +429.583ms] or [-5.493%; +8.662%]
  • unstable execution_time [-272.559ms; +426.480ms] or [-5.417%; +8.475%]
  • unstable throughput [-147263.728op/s; +92929.215op/s] or [-8.819%; +5.565%]

scenario:plugin-graphql-long-with-depth-and-collapse-off-20

  • unstable max_rss_usage [-18.566MB; +38.555MB] or [-4.971%; +10.323%]

scenario:plugin-graphql-long-with-depth-off-20

  • unstable max_rss_usage [-7153.438KB; +8428.295KB] or [-5.493%; +6.471%]

scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-5603.498KB; +5638.165KB] or [-6.916%; +6.958%]

@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-06-26-fix-iast-opendir-node20 branch 2 times, most recently from effe9cf to 2535576 Compare June 26, 2026 17:55
Node 20 defines `fs.opendir` / `fs.opendirSync` as lazy getter+setter accessor
properties that resolve the real function on first read. Handing such a property
to `shimmer.wrap` instrumented the getter, so the property access was traced
while the real call ran uninstrumented — IAST then saw no `opendir` operation
and reported no PATH_TRAVERSAL vulnerability. Node 18/22 define these as plain
data properties, which is why the gap was Node-20-only.

Extend `shimmer.wrap`'s existing `replaceGetter` option to cover the lazy
getter+setter case: resolve the value once through the getter and wrap that,
rather than re-implementing the resolution in the fs instrumentation. The
property keeps its original shape — a getter+setter pair stays a getter+setter
pair whose setter still materializes a writable data property on assignment, so
the descriptor remains observationally identical for a downstream consumer that
inspects or overwrites it on that Node.js version.

A getter+setter pair without `replaceGetter` keeps being wrapped in place — the
wrapper becomes the new getter and the original setter is left untouched, as the
`url` instrumentation relies on for the `URL.prototype` `host` / `hostname`
accessors. Only a setter-only property throws. Narrowing the guard to reject
every unguarded getter+setter pair would have thrown inside the `url` hook,
silently dropping that instrumentation and the AppSec / IAST coverage built on
it.

`fs.js` now passes `{ replaceGetter: true }` through its `wrap` / `massWrap`
helpers instead of carrying its own materialization helper.
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-06-26-fix-iast-opendir-node20 branch from 2535576 to 0b0f79c Compare June 27, 2026 15:08
@BridgeAR
BridgeAR marked this pull request as ready for review June 27, 2026 15:51
@BridgeAR
BridgeAR requested review from a team as code owners June 27, 2026 15:51
@BridgeAR
BridgeAR requested review from crysmags and removed request for a team June 27, 2026 15:51
}

const original = descriptor.value ?? options?.replaceGetter ? target[name] : descriptor.get
const original = (descriptor.value ?? options?.replaceGetter) ? target[name] : descriptor.get

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.

This looks cosmetic, but I guess helps comprehension, so let's leave it.

@szegedi
szegedi merged commit d07a623 into master Jun 30, 2026
1189 of 1191 checks passed
@szegedi
szegedi deleted the BridgeAR/2026-06-26-fix-iast-opendir-node20 branch June 30, 2026 16:10
dd-octo-sts Bot pushed a commit that referenced this pull request Jul 1, 2026
Node 20 defines `fs.opendir` / `fs.opendirSync` as lazy getter+setter accessor
properties that resolve the real function on first read. Handing such a property
to `shimmer.wrap` instrumented the getter, so the property access was traced
while the real call ran uninstrumented — IAST then saw no `opendir` operation
and reported no PATH_TRAVERSAL vulnerability. Node 18/22 define these as plain
data properties, which is why the gap was Node-20-only.

Extend `shimmer.wrap`'s existing `replaceGetter` option to cover the lazy
getter+setter case: resolve the value once through the getter and wrap that,
rather than re-implementing the resolution in the fs instrumentation. The
property keeps its original shape — a getter+setter pair stays a getter+setter
pair whose setter still materializes a writable data property on assignment, so
the descriptor remains observationally identical for a downstream consumer that
inspects or overwrites it on that Node.js version.

A getter+setter pair without `replaceGetter` keeps being wrapped in place — the
wrapper becomes the new getter and the original setter is left untouched, as the
`url` instrumentation relies on for the `URL.prototype` `host` / `hostname`
accessors. Only a setter-only property throws. Narrowing the guard to reject
every unguarded getter+setter pair would have thrown inside the `url` hook,
silently dropping that instrumentation and the AppSec / IAST coverage built on
it.

`fs.js` now passes `{ replaceGetter: true }` through its `wrap` / `massWrap`
helpers instead of carrying its own materialization helper.
This was referenced Jul 1, 2026
rochdev pushed a commit that referenced this pull request Jul 2, 2026
Node 20 defines `fs.opendir` / `fs.opendirSync` as lazy getter+setter accessor
properties that resolve the real function on first read. Handing such a property
to `shimmer.wrap` instrumented the getter, so the property access was traced
while the real call ran uninstrumented — IAST then saw no `opendir` operation
and reported no PATH_TRAVERSAL vulnerability. Node 18/22 define these as plain
data properties, which is why the gap was Node-20-only.

Extend `shimmer.wrap`'s existing `replaceGetter` option to cover the lazy
getter+setter case: resolve the value once through the getter and wrap that,
rather than re-implementing the resolution in the fs instrumentation. The
property keeps its original shape — a getter+setter pair stays a getter+setter
pair whose setter still materializes a writable data property on assignment, so
the descriptor remains observationally identical for a downstream consumer that
inspects or overwrites it on that Node.js version.

A getter+setter pair without `replaceGetter` keeps being wrapped in place — the
wrapper becomes the new getter and the original setter is left untouched, as the
`url` instrumentation relies on for the `URL.prototype` `host` / `hostname`
accessors. Only a setter-only property throws. Narrowing the guard to reject
every unguarded getter+setter pair would have thrown inside the `url` hook,
silently dropping that instrumentation and the AppSec / IAST coverage built on
it.

`fs.js` now passes `{ replaceGetter: true }` through its `wrap` / `massWrap`
helpers instead of carrying its own materialization helper.
rochdev pushed a commit that referenced this pull request Jul 2, 2026
Node 20 defines `fs.opendir` / `fs.opendirSync` as lazy getter+setter accessor
properties that resolve the real function on first read. Handing such a property
to `shimmer.wrap` instrumented the getter, so the property access was traced
while the real call ran uninstrumented — IAST then saw no `opendir` operation
and reported no PATH_TRAVERSAL vulnerability. Node 18/22 define these as plain
data properties, which is why the gap was Node-20-only.

Extend `shimmer.wrap`'s existing `replaceGetter` option to cover the lazy
getter+setter case: resolve the value once through the getter and wrap that,
rather than re-implementing the resolution in the fs instrumentation. The
property keeps its original shape — a getter+setter pair stays a getter+setter
pair whose setter still materializes a writable data property on assignment, so
the descriptor remains observationally identical for a downstream consumer that
inspects or overwrites it on that Node.js version.

A getter+setter pair without `replaceGetter` keeps being wrapped in place — the
wrapper becomes the new getter and the original setter is left untouched, as the
`url` instrumentation relies on for the `URL.prototype` `host` / `hostname`
accessors. Only a setter-only property throws. Narrowing the guard to reject
every unguarded getter+setter pair would have thrown inside the `url` hook,
silently dropping that instrumentation and the AppSec / IAST coverage built on
it.

`fs.js` now passes `{ replaceGetter: true }` through its `wrap` / `massWrap`
helpers instead of carrying its own materialization helper.
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.

2 participants