From d764b89efdd79afe41ded233893a0eaca0921559 Mon Sep 17 00:00:00 2001 From: ishabi Date: Wed, 4 Dec 2024 21:03:27 +0100 Subject: [PATCH] use named function --- packages/datadog-instrumentations/src/router.js | 6 ++---- .../sources/taint-tracking.express.plugin.spec.js | 10 +++++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/datadog-instrumentations/src/router.js b/packages/datadog-instrumentations/src/router.js index fb94c6f986c..bc9ff6152e5 100644 --- a/packages/datadog-instrumentations/src/router.js +++ b/packages/datadog-instrumentations/src/router.js @@ -241,9 +241,7 @@ addHook({ function wrapParam (original) { return function wrappedProcessParams () { arguments[1] = shimmer.wrapFunction(arguments[1], (originalFn) => { - return (...args) => { - const [req, res] = args - + return function wrappedFn (req, res) { if (routerParamStartCh.hasSubscribers && Object.keys(req.params).length && !visitedParams.has(req.params)) { visitedParams.add(req.params) @@ -259,7 +257,7 @@ function wrapParam (original) { if (abortController.signal.aborted) return } - return originalFn.apply(this, args) + return originalFn.apply(this, arguments) } }) diff --git a/packages/dd-trace/test/appsec/iast/taint-tracking/sources/taint-tracking.express.plugin.spec.js b/packages/dd-trace/test/appsec/iast/taint-tracking/sources/taint-tracking.express.plugin.spec.js index 947e0fc0b8a..8fc32f1c03a 100644 --- a/packages/dd-trace/test/appsec/iast/taint-tracking/sources/taint-tracking.express.plugin.spec.js +++ b/packages/dd-trace/test/appsec/iast/taint-tracking/sources/taint-tracking.express.plugin.spec.js @@ -202,13 +202,21 @@ describe('Path params sourcing with express', () => { }) it('should taint path param on router.params callback with custom implementation', function (done) { + if (!semver.satisfies(expressVersion, '4')) { + this.skip() + } const app = express() app.use('/:parameter1/:parameter2', (req, res) => { res.status(200).send() }) - app.param(['parameter1', 'parameter2'], checkParamIsTaintedAndNext) + app.param((param, option) => { + return checkParamIsTaintedAndNext + }) + + app.param('parameter1') + app.param('parameter2') appListener = app.listen(0, 'localhost', () => { const port = appListener.address().port