/** * @name Incomplete multi-character sanitization * @description A sanitizer that removes a sequence of characters may reintroduce the dangerous sequence. * @kind problem * @problem.severity warning * @security-severity 7.8 * @precision high * @id js/incomplete-multi-character-sanitization * @tags correctness * security * external/cwe/cwe-020 * external/cwe/cwe-080 * external/cwe/cwe-116 */ import javascript /** * A regexp term that matches substrings that should be replaced with the empty string. */ class EmptyReplaceRegExpTerm extends RegExpTerm { EmptyReplaceRegExpTerm() { exists(StringReplaceCall replace | [replace.getRawReplacement(), replace.getCallback(1).getAReturn()].mayHaveStringValue("") and this = replace.getRegExp().getRoot().getAChild*() ) } } /** * A prefix that may be dangerous to sanitize explicitly. * * Note that this class exists solely as a (necessary) optimization for this query. */ class DangerousPrefix extends string { DangerousPrefix() { this = ["/..", "../"] or this = "