Skip to content

Commit 0d3edae

Browse files
authored
Merge pull request #2004 from xiemaisi/js/fix-xss-sanitisers
Approved by asger-semmle
2 parents 594a50e + d4fca84 commit 0d3edae

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

change-notes/1.23/analysis-javascript.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@
2222
| **Query** | **Expected impact** | **Change** |
2323
|--------------------------------|------------------------------|---------------------------------------------------------------------------|
2424
| Incomplete string escaping or encoding (`js/incomplete-sanitization`) | Fewer false-positive results | This rule now recognizes additional ways delimiters can be stripped away. |
25-
| Client-side cross-site scripting (`js/xss`) | More results | More potential vulnerabilities involving functions that manipulate DOM attributes are now recognized. |
25+
| Client-side cross-site scripting (`js/xss`) | More results, fewer false-positive results | More potential vulnerabilities involving functions that manipulate DOM attributes are now recognized, and more sanitizers are detected. |
2626
| Code injection (`js/code-injection`) | More results | More potential vulnerabilities involving functions that manipulate DOM event handler attributes are now recognized. |
2727
| Hard-coded credentials (`js/hardcoded-credentials`) | Fewer false-positive results | This rule now flags fewer password examples. |
2828
| Illegal invocation (`js/illegal-invocation`) | Fewer false-positive results | This rule now correctly handles methods named `call` and `apply`. |
29-
| Incorrect suffix check (`js/incorrect-suffix-check`) | Fewer false-positive results | The query recognizes valid checks in more cases.
29+
| Incorrect suffix check (`js/incorrect-suffix-check`) | Fewer false-positive results | The query recognizes valid checks in more cases. |
3030
| Network data written to file (`js/http-to-file-access`) | Fewer false-positive results | This query has been renamed to better match its intended purpose, and now only considers network data untrusted. |
3131
| Password in configuration file (`js/password-in-configuration-file`) | Fewer false-positive results | This rule now flags fewer password examples. |
3232
| Prototype pollution (`js/prototype-pollution`) | More results | The query now highlights vulnerable uses of jQuery and Angular, and the results are shown on LGTM by default. |
33+
| Reflected cross-site scripting (`js/reflected-xss`) | Fewer false-positive results | The query now recognizes more sanitizers. |
34+
| Stored cross-site scripting (`js/stored-xss`) | Fewer false-positive results | The query now recognizes more sanitizers. |
3335
| Uncontrolled command line (`js/command-line-injection`) | More results | This query now treats responses from servers as untrusted. |
3436

3537
## Changes to QL libraries

javascript/ql/src/semmle/javascript/security/dataflow/Xss.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module Shared {
3434
MetacharEscapeSanitizer() {
3535
getMethodName() = "replace" and
3636
exists(RegExpConstant c |
37-
c.getLiteral() = getArgument(0).asExpr() and
37+
c.getLiteral() = getArgument(0).getALocalSource().asExpr() and
3838
c.getValue().regexpMatch("['\"&<>]")
3939
)
4040
}

javascript/ql/test/query-tests/Security/CWE-079/sanitiser.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
function escapeHtml(s) {
2+
var amp = /&/g, lt = /</g, gt = />/g;
23
return s.toString()
3-
.replace(/&/g, '&amp;')
4-
.replace(/</g, '&lt;')
5-
.replace(/>/g, '&gt;');
4+
.replace(amp, '&amp;')
5+
.replace(lt, '&lt;')
6+
.replace(gt, '&gt;');
67
}
78

89
function escapeAttr(s) {

0 commit comments

Comments
 (0)