Skip to content

Commit

Permalink
Upgrade iast rewriter to 2.5.0 (#4761)
Browse files Browse the repository at this point in the history
* Upgrade iast rewriter version to 2.5.0

* Implement tplOperator tracking method
  • Loading branch information
iunanua authored Oct 8, 2024
1 parent 7f93d36 commit a11a1fd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
},
"dependencies": {
"@datadog/native-appsec": "8.1.1",
"@datadog/native-iast-rewriter": "2.4.1",
"@datadog/native-iast-rewriter": "2.5.0",
"@datadog/native-iast-taint-tracking": "3.1.0",
"@datadog/native-metrics": "^2.0.0",
"@datadog/pprof": "5.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const csiMethods = [
{ src: 'substring' },
{ src: 'toLowerCase', dst: 'stringCase' },
{ src: 'toUpperCase', dst: 'stringCase' },
{ src: 'tplOperator', operator: true },
{ src: 'trim' },
{ src: 'trimEnd' },
{ src: 'trimStart', dst: 'trim' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const TaintTrackingNoop = {
substr: noop,
substring: noop,
stringCase: noop,
tplOperator: noop,
trim: noop,
trimEnd: noop
}
Expand Down Expand Up @@ -117,6 +118,20 @@ function csiMethodsOverrides (getContext) {
return res
},

tplOperator: function (res, ...rest) {
try {
const iastContext = getContext()
const transactionId = getTransactionId(iastContext)
if (transactionId) {
return TaintedUtils.concat(transactionId, res, ...rest)
}
} catch (e) {
iastLog.error('Error invoking CSI tplOperator')
.errorAndPublish(e)
}
return res
},

stringCase: getCsiFn(
(transactionId, res, target) => TaintedUtils.stringCase(transactionId, res, target),
getContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ function templateLiteralEndingWithNumberParams (str) {
return `${str}Literal${num1}${num2}`
}

function templateLiteralWithTaintedAtTheEnd (str) {
const num1 = 1
const num2 = 2
const hello = 'world'
return `Literal${num1}${num2}-${hello}-${str}`
}

function appendStr (str) {
let pre = 'pre_'
pre += str
Expand Down Expand Up @@ -108,6 +115,7 @@ module.exports = {
substrStr,
substringStr,
templateLiteralEndingWithNumberParams,
templateLiteralWithTaintedAtTheEnd,
toLowerCaseStr,
toUpperCaseStr,
trimEndStr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const propagationFns = [
'substrStr',
'substringStr',
'templateLiteralEndingWithNumberParams',
'templateLiteralWithTaintedAtTheEnd',
'toLowerCaseStr',
'toUpperCaseStr',
'trimEndStr',
Expand Down Expand Up @@ -137,7 +138,8 @@ describe('TaintTracking', () => {
'concatSuffix',
'concatTaintedStr',
'insertStr',
'templateLiteralEndingWithNumberParams'
'templateLiteralEndingWithNumberParams',
'templateLiteralWithTaintedAtTheEnd'
]
propagationFns.forEach((propFn) => {
if (filtered.includes(propFn)) return
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,10 @@
dependencies:
node-gyp-build "^3.9.0"

"@datadog/native-iast-rewriter@2.4.1":
version "2.4.1"
resolved "https://registry.yarnpkg.com/@datadog/native-iast-rewriter/-/native-iast-rewriter-2.4.1.tgz#e8211f78c818906513fb96a549374da0382c7623"
integrity sha512-j3auTmyyn63e2y+SL28CGNy/l+jXQyh+pxqoGTacWaY5FW/dvo5nGQepAismgJ3qJ8VhQfVWRdxBSiT7wu9clw==
"@datadog/native-iast-rewriter@2.5.0":
version "2.5.0"
resolved "https://registry.yarnpkg.com/@datadog/native-iast-rewriter/-/native-iast-rewriter-2.5.0.tgz#b613defe86e78168f750d1f1662d4ffb3cf002e6"
integrity sha512-WRu34A3Wwp6oafX8KWNAbedtDaaJO+nzfYQht7pcJKjyC2ggfPeF7SoP+eDo9wTn4/nQwEOscSR4hkJqTRlpXQ==
dependencies:
lru-cache "^7.14.0"
node-gyp-build "^4.5.0"
Expand Down

0 comments on commit a11a1fd

Please sign in to comment.