diff --git a/dd-java-agent/agent-iast/src/main/java/com/datadog/iast/model/json/EvidenceAdapter.java b/dd-java-agent/agent-iast/src/main/java/com/datadog/iast/model/json/EvidenceAdapter.java index f90f7d68a67..d6da0e76561 100644 --- a/dd-java-agent/agent-iast/src/main/java/com/datadog/iast/model/json/EvidenceAdapter.java +++ b/dd-java-agent/agent-iast/src/main/java/com/datadog/iast/model/json/EvidenceAdapter.java @@ -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 diff --git a/dd-java-agent/agent-iast/src/test/resources/redaction/evidence-redaction-suite.yml b/dd-java-agent/agent-iast/src/test/resources/redaction/evidence-redaction-suite.yml index 485afe29f2c..cf92538ae54 100644 --- a/dd-java-agent/agent-iast/src/test/resources/redaction/evidence-redaction-suite.yml +++ b/dd-java-agent/agent-iast/src/test/resources/redaction/evidence-redaction-suite.yml @@ -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: @@ -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: >