Skip to content

Commit 8076e8c

Browse files
CarlesDDuurien
authored andcommitted
Fix IAST evidence redaction (#3160)
* Add test for vulnerability evidence scrubber * Fix IAST SQL redaction with tainted contained in sensitive
1 parent f21de3d commit 8076e8c

File tree

2 files changed

+147
-1
lines changed

2 files changed

+147
-1
lines changed

packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class SensitiveHandler {
102102
if (entry.start === i) {
103103
nextSensitive = entry
104104
} else {
105-
sensitive.push(entry)
105+
sensitive.unshift(entry)
106106
}
107107
}
108108
}

packages/dd-trace/test/appsec/iast/vulnerability-formatter/resources/evidence-redaction-suite.json

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,61 @@
300300
]
301301
}
302302
},
303+
{
304+
"type": "VULNERABILITIES",
305+
"description": "Query with string literal $1",
306+
"parameters": {
307+
"$1": [
308+
"john",
309+
"username with 🌉 surrogate"
310+
]
311+
},
312+
"input": [
313+
{
314+
"type": "SQL_INJECTION",
315+
"evidence": {
316+
"dialect": "MYSQL",
317+
"value": "select * from users where username = \"$1\" and last_name = 'another surrogate 😃'",
318+
"ranges": [
319+
{
320+
"start": 14,
321+
"end": 19,
322+
"iinfo": {
323+
"type": "http.request.parameter",
324+
"parameterName": "table",
325+
"parameterValue": "users"
326+
}
327+
}
328+
]
329+
}
330+
}
331+
],
332+
"expected": {
333+
"sources": [
334+
{
335+
"origin": "http.request.parameter",
336+
"name": "table",
337+
"value": "users"
338+
}
339+
],
340+
"vulnerabilities": [
341+
{
342+
"type": "SQL_INJECTION",
343+
"evidence": {
344+
"valueParts": [
345+
{ "value": "select * from " },
346+
{ "source": 0, "value": "users" },
347+
{ "value": " where username = \"" },
348+
{ "redacted": true },
349+
{ "value": "\" and last_name = '" },
350+
{ "redacted": true },
351+
{ "value": "'" }
352+
]
353+
}
354+
}
355+
]
356+
}
357+
},
303358
{
304359
"type": "VULNERABILITIES",
305360
"description": "POSTGRES Query with escaped string literal",
@@ -929,6 +984,53 @@
929984
]
930985
}
931986
},
987+
{
988+
"type": "VULNERABILITIES",
989+
"description": "Query with string literal containing tainted range",
990+
"input": [
991+
{
992+
"type": "SQL_INJECTION",
993+
"evidence": {
994+
"dialect": "POSTGRES",
995+
"value": "select * from users where username = 'john:doe:ADMIN'",
996+
"ranges": [
997+
{
998+
"start": 43,
999+
"end": 46,
1000+
"iinfo": {
1001+
"type": "http.request.parameter",
1002+
"parameterName": "last_name",
1003+
"parameterValue": "doe"
1004+
}
1005+
}
1006+
]
1007+
}
1008+
}
1009+
],
1010+
"expected": {
1011+
"sources": [
1012+
{
1013+
"origin": "http.request.parameter",
1014+
"name": "last_name",
1015+
"redacted": true
1016+
}
1017+
],
1018+
"vulnerabilities": [
1019+
{
1020+
"type": "SQL_INJECTION",
1021+
"evidence": {
1022+
"valueParts": [
1023+
{ "value": "select * from users where username = '" },
1024+
{ "redacted": true },
1025+
{ "source": 0, "redacted": true },
1026+
{ "redacted": true },
1027+
{ "value": "'" }
1028+
]
1029+
}
1030+
}
1031+
]
1032+
}
1033+
},
9321034
{
9331035
"type": "VULNERABILITIES",
9341036
"description": "Query with string literal and tainted range crossing boundaries",
@@ -978,6 +1080,50 @@
9781080
]
9791081
}
9801082
},
1083+
{
1084+
"type": "VULNERABILITIES",
1085+
"description": "Query with tainted range in two LIKEs with not tainted % char",
1086+
"input": [
1087+
{
1088+
"type": "SQL_INJECTION",
1089+
"evidence": {
1090+
"dialect": "MYSQL",
1091+
"value": "select * from table where name LIKE '%searchparam%' OR description LIKE '%searchparam%'",
1092+
"ranges": [
1093+
{
1094+
"start": 38, "end": 49, "iinfo": { "type": "http.request.parameter", "parameterName": "query", "parameterValue": "searchparam" }
1095+
},
1096+
{
1097+
"start": 74, "end": 85, "iinfo": { "type": "http.request.parameter", "parameterName": "query", "parameterValue": "searchparam" }
1098+
}
1099+
]
1100+
}
1101+
}
1102+
],
1103+
"expected": {
1104+
"sources": [
1105+
{ "origin": "http.request.parameter", "name": "query", "redacted": true }
1106+
],
1107+
"vulnerabilities": [
1108+
{
1109+
"type": "SQL_INJECTION",
1110+
"evidence": {
1111+
"valueParts": [
1112+
{ "value": "select * from table where name LIKE '" },
1113+
{ "redacted": true },
1114+
{ "source": 0, "redacted": true },
1115+
{ "redacted": true },
1116+
{ "value": "' OR description LIKE '" },
1117+
{ "redacted": true },
1118+
{ "source": 0, "redacted": true },
1119+
{ "redacted": true },
1120+
{ "value": "'" }
1121+
]
1122+
}
1123+
}
1124+
]
1125+
}
1126+
},
9811127
{
9821128
"type": "VULNERABILITIES",
9831129
"description": "Query with string literal and weird tainted range crossing boundaries",

0 commit comments

Comments
 (0)