Skip to content

Commit

Permalink
support SourceTextModule class
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasShabi committed Jan 15, 2025
1 parent 2bfb603 commit a6f076c
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 122 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"test": "SERVICES=* yarn services && mocha --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
"test:appsec": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" \"packages/dd-trace/test/appsec/**/*.spec.js\"",
"test:appsec:ci": "nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" -- npm run test:appsec",
"test:appsec:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/appsec/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
"test:appsec:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" --experimental-vm-modules \"packages/dd-trace/test/appsec/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
"test:appsec:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" -- npm run test:appsec:plugins",
"test:debugger": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/dd-trace/test/debugger/**/*.spec.js'",
"test:debugger:ci": "nyc --no-clean --include 'packages/dd-trace/src/debugger/**/*.js' -- npm run test:debugger",
Expand Down
11 changes: 11 additions & 0 deletions packages/datadog-instrumentations/src/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const shimmer = require('../../datadog-shimmer')
const names = ['vm', 'node:vm']

const runScriptStartChannel = channel('datadog:vm:run-script:start')
const sourceTextModuleStartChannel = channel('datadog:vm:source-text-module:start')

addHook({ name: names }, function (vm) {
vm.Script = class extends vm.Script {
Expand All @@ -17,6 +18,16 @@ addHook({ name: names }, function (vm) {
}
}

vm.SourceTextModule = class extends vm.SourceTextModule {
constructor (sourceText) {
super(...arguments)

if (sourceTextModuleStartChannel.hasSubscribers && sourceText) {
sourceTextModuleStartChannel.publish({ sourceText })
}
}
}

shimmer.wrap(vm, 'runInContext', wrapVMMethod)
shimmer.wrap(vm, 'runInNewContext', wrapVMMethod)
shimmer.wrap(vm, 'runInThisContext', wrapVMMethod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class CodeInjectionAnalyzer extends InjectionAnalyzer {
onConfigure () {
this.addSub('datadog:eval:call', ({ script }) => this.analyze(script))
this.addSub('datadog:vm:run-script:start', ({ code }) => this.analyze(code))
this.addSub('datadog:vm:source-text-module:start', ({ sourceText }) => this.analyze(sourceText))
}

_areRangesVulnerable () {
Expand Down
Loading

0 comments on commit a6f076c

Please sign in to comment.