-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement common taint tracking operations (#4239)
* Lodash trim implementation * Implement CSI for toLowerCase and toUpperCase * Fix lint * Implement Array.join CSI * Instrument lodash string case methods to propagate taint valuesh * Instrument lodash array join method to propagate taint valuesh * Refactor * Move test to a plugin test * Sort methods alphabetically * Reformat lodash taint tracking handler + test * Fix this loosing in lodash instrumentation * Add blankline * Prevent tainting empty strings for lodash * Bump iast-rewriter to 2.3.1 with array expression test * Sort fn alphabetically + fix lint * Fix tainted instance replacement + test * Appsec propagation test with node 21 instead of latest * Change job title for lodash plugin test Co-authored-by: Ugaitz Urien <ugaitz.urien@datadoghq.com> * Add use strict in lodash fn file Co-authored-by: Ugaitz Urien <ugaitz.urien@datadoghq.com> --------- Co-authored-by: Ugaitz Urien <ugaitz.urien@datadoghq.com>
- Loading branch information
Showing
13 changed files
with
330 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict' | ||
|
||
const { channel, addHook } = require('./helpers/instrument') | ||
|
||
const shimmer = require('../../datadog-shimmer') | ||
|
||
addHook({ name: 'lodash', versions: ['>=4'] }, lodash => { | ||
const lodashOperationCh = channel('datadog:lodash:operation') | ||
|
||
const instrumentedLodashFn = ['trim', 'trimStart', 'trimEnd', 'toLower', 'toUpper', 'join'] | ||
|
||
shimmer.massWrap( | ||
lodash, | ||
instrumentedLodashFn, | ||
lodashFn => { | ||
return function () { | ||
if (!lodashOperationCh.hasSubscribers) { | ||
return lodashFn.apply(this, arguments) | ||
} | ||
|
||
const result = lodashFn.apply(this, arguments) | ||
const message = { operation: lodashFn.name, arguments, result } | ||
lodashOperationCh.publish(message) | ||
|
||
return message.result | ||
} | ||
} | ||
) | ||
|
||
return lodash | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/dd-trace/test/appsec/iast/taint-tracking/resources/propagationLodashFunctions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict' | ||
|
||
function trimLodash (_, str) { | ||
return _.trim(str) | ||
} | ||
|
||
function trimStartLodash (_, str) { | ||
return _.trimStart(str) | ||
} | ||
|
||
function trimEndLodash (_, str) { | ||
return _.trimEnd(str) | ||
} | ||
|
||
function toLowerLodash (_, str) { | ||
return _.toLower(str) | ||
} | ||
|
||
function toUpperLodash (_, str) { | ||
return _.toUpper(str) | ||
} | ||
|
||
function arrayJoinLodashWithoutSeparator (_, str) { | ||
return _.join([str, str]) | ||
} | ||
|
||
function arrayJoinLodashWithSeparator (_, str) { | ||
return _.join([str, str], str) | ||
} | ||
|
||
function startCaseLodash (_, str) { | ||
return _.startCase(str) | ||
} | ||
|
||
module.exports = { | ||
arrayJoinLodashWithoutSeparator, | ||
arrayJoinLodashWithSeparator, | ||
toLowerLodash, | ||
toUpperLodash, | ||
startCaseLodash, | ||
trimEndLodash, | ||
trimLodash, | ||
trimStartLodash | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.