JS: Share more code with Ruby

This commit is contained in:
Harry Maclean
2022-08-09 11:21:56 +12:00
parent f2384a6a8f
commit e48158b9ad
3 changed files with 51 additions and 26 deletions

View File

@@ -13,29 +13,4 @@
* external/cwe/cwe-116
*/
import javascript
private import semmle.javascript.security.IncompleteMultiCharacterSanitization
from
StringReplaceCall replace, EmptyReplaceRegExpTerm regexp, EmptyReplaceRegExpTerm dangerous,
string prefix, string kind
where
regexp = replace.getRegExp().getRoot() and
dangerous.getRootTerm() = regexp and
// skip leading optional elements
not dangerous.isNullable() and
// only warn about the longest match (presumably the most descriptive)
prefix = max(string m | matchesDangerousPrefix(dangerous, m, kind) | m order by m.length(), m) and
// only warn once per kind
not exists(EmptyReplaceRegExpTerm other |
other = dangerous.getAChild+() or other = dangerous.getPredecessor+()
|
matchesDangerousPrefix(other, _, kind) and
not other.isNullable()
) and
// don't flag replace operations in a loop
not replace.getAMethodCall*().flowsTo(replace.getReceiver()) and
// avoid anchored terms
not exists(RegExpAnchor a | regexp = a.getRootTerm())
select replace, "This string may still contain $@, which may cause a " + kind + " vulnerability.",
dangerous, prefix
import semmle.javascript.security.IncompleteMultiCharacterSanitization