Skip to content

Commit

Permalink
Fix NPE in IAST evidence redaction (#6099)
Browse files Browse the repository at this point in the history
When serializing vulnerability evidence, we could trigger an NPE when
the data source has no value (e.g. this happens with request body as
source).
  • Loading branch information
smola authored Oct 25, 2023
1 parent 4b83850 commit 1d3d236
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ private void addValuePart(
valueParts.add(new TaintedValuePart(adapter, source, chunk, false));
} else {
final int length = chunk.length();
final int matching = source.getValue().indexOf(chunk);
final String sourceValue = source.getValue();
final int matching = (sourceValue == null) ? -1 : sourceValue.indexOf(chunk);
final String pattern;
if (matching >= 0) {
// if matches append the matching part from the redacted value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,38 @@ suite:
}
]
}
- type: 'VULNERABILITIES'
description: 'Query with single quoted string literal and null source'
input: >
[
{
"type": "SQL_INJECTION",
"evidence": {
"value": "select * from users where username = 'user'",
"ranges": [
{ "start" : 38, "length" : 4, "source": { "origin": "http.request.body" } }
]
}
}
]
expected: >
{
"sources": [
{ "origin": "http.request.body" }
],
"vulnerabilities": [
{
"type": "SQL_INJECTION",
"evidence": {
"valueParts": [
{ "value": "select * from users where username = '" },
{ "redacted": true, "source": 0, "pattern": "****" },
{ "value": "'" }
]
}
}
]
}
- type: 'VULNERABILITIES'
description: '$1 query with double quoted string literal $2'
parameters:
Expand Down Expand Up @@ -1753,6 +1785,40 @@ suite:
]
}
- type: 'VULNERABILITIES'
description: 'Tainted range based redaction - with null source '
input: >
[
{
"type": "XSS",
"evidence": {
"value": "this could be a super long text, so we need to reduce it before send it to the backend. This redaction strategy applies to XSS vulnerability but can be extended to future ones",
"ranges": [
{ "start" : 123, "length" : 3, "source": { "origin": "http.request.body" } }
]
}
}
]
expected: >
{
"sources": [
{ "origin": "http.request.body" }
],
"vulnerabilities": [
{
"type": "XSS",
"evidence": {
"valueParts": [
{ "redacted": true },
{ "source": 0, "value": "XSS" },
{ "redacted": true }
]
}
}
]
}
- type: 'VULNERABILITIES'
description: 'Tainted range based redaction - multiple ranges'
input: >
Expand Down

0 comments on commit 1d3d236

Please sign in to comment.