Skip to content

Commit

Permalink
Implement tplOperator tracking method
Browse files Browse the repository at this point in the history
  • Loading branch information
iunanua committed Oct 4, 2024
1 parent f143181 commit fbe90e4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
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

0 comments on commit fbe90e4

Please sign in to comment.