JavaScript: Improve XSS sanitizer detection.

We now use local data flow to detect more regexp-based sanitizers.
This commit is contained in:
Max Schaefer
2019-09-23 16:53:08 +01:00
parent 22e57a6559
commit d4fca84898
3 changed files with 9 additions and 6 deletions

View File

@@ -34,7 +34,7 @@ module Shared {
MetacharEscapeSanitizer() {
getMethodName() = "replace" and
exists(RegExpConstant c |
c.getLiteral() = getArgument(0).asExpr() and
c.getLiteral() = getArgument(0).getALocalSource().asExpr() and
c.getValue().regexpMatch("['\"&<>]")
)
}

View File

@@ -1,8 +1,9 @@
function escapeHtml(s) {
var amp = /&/g, lt = /</g, gt = />/g;
return s.toString()
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
.replace(amp, '&amp;')
.replace(lt, '&lt;')
.replace(gt, '&gt;');
}
function escapeAttr(s) {