Skip to content

Commit cf92022

Browse files
authored
Merge pull request #2420 from erik-krogh/safeStringSink
Approved by asgerf
2 parents 113df4e + 9fc20cd commit cf92022

File tree

6 files changed

+42
-0
lines changed

6 files changed

+42
-0
lines changed

change-notes/1.24/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Support for the following frameworks and libraries has been improved:
66
- [react](https://www.npmjs.com/package/react)
7+
- [Handlebars](https://www.npmjs.com/package/handlebars)
78

89
## New queries
910

javascript/ql/src/javascript.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import semmle.javascript.frameworks.Electron
7676
import semmle.javascript.frameworks.Files
7777
import semmle.javascript.frameworks.Firebase
7878
import semmle.javascript.frameworks.jQuery
79+
import semmle.javascript.frameworks.Handlebars
7980
import semmle.javascript.frameworks.LodashUnderscore
8081
import semmle.javascript.frameworks.Logging
8182
import semmle.javascript.frameworks.HttpFrameworks
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Provides classes for working with Handlebars code.
3+
*/
4+
5+
import javascript
6+
7+
module Handlebars {
8+
/**
9+
* A reference to the Handlebars library.
10+
*/
11+
class Handlebars extends DataFlow::SourceNode {
12+
Handlebars() {
13+
this.accessesGlobal("handlebars")
14+
or
15+
this.accessesGlobal("Handlebars")
16+
or
17+
this = DataFlow::moduleImport("handlebars")
18+
or
19+
this.hasUnderlyingType("Handlebars")
20+
}
21+
}
22+
23+
/**
24+
* A new instantiation of a Handlebars.SafeString.
25+
*/
26+
class SafeString extends DataFlow::NewNode {
27+
SafeString() { this = any(Handlebars h).getAConstructorInvocation("SafeString") }
28+
}
29+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ module DomBasedXss {
9595
mcn.getMethodName() = m and
9696
this = mcn.getArgument(1)
9797
)
98+
or
99+
this = any(Handlebars::SafeString s).getAnArgument()
98100
}
99101
}
100102

javascript/ql/test/query-tests/Security/CWE-079/Xss.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ nodes
315315
| tst.js:285:59:285:65 | tainted |
316316
| tst.js:285:59:285:65 | tainted |
317317
| tst.js:285:59:285:65 | tainted |
318+
| tst.js:297:35:297:42 | location |
319+
| tst.js:297:35:297:42 | location |
320+
| tst.js:297:35:297:42 | location |
318321
| v-html.vue:2:8:2:23 | v-html=tainted |
319322
| v-html.vue:2:8:2:23 | v-html=tainted |
320323
| v-html.vue:6:42:6:58 | document.location |
@@ -604,6 +607,7 @@ edges
604607
| tst.js:282:19:282:29 | window.name | tst.js:282:9:282:29 | tainted |
605608
| tst.js:282:19:282:29 | window.name | tst.js:282:9:282:29 | tainted |
606609
| tst.js:285:59:285:65 | tainted | tst.js:285:59:285:65 | tainted |
610+
| tst.js:297:35:297:42 | location | tst.js:297:35:297:42 | location |
607611
| v-html.vue:6:42:6:58 | document.location | v-html.vue:2:8:2:23 | v-html=tainted |
608612
| v-html.vue:6:42:6:58 | document.location | v-html.vue:2:8:2:23 | v-html=tainted |
609613
| v-html.vue:6:42:6:58 | document.location | v-html.vue:2:8:2:23 | v-html=tainted |
@@ -693,6 +697,7 @@ edges
693697
| tst.js:285:59:285:65 | tainted | tst.js:282:9:282:29 | tainted | tst.js:285:59:285:65 | tainted | Cross-site scripting vulnerability due to $@. | tst.js:282:9:282:29 | tainted | user-provided value |
694698
| tst.js:285:59:285:65 | tainted | tst.js:282:19:282:29 | window.name | tst.js:285:59:285:65 | tainted | Cross-site scripting vulnerability due to $@. | tst.js:282:19:282:29 | window.name | user-provided value |
695699
| tst.js:285:59:285:65 | tainted | tst.js:285:59:285:65 | tainted | tst.js:285:59:285:65 | tainted | Cross-site scripting vulnerability due to $@. | tst.js:285:59:285:65 | tainted | user-provided value |
700+
| tst.js:297:35:297:42 | location | tst.js:297:35:297:42 | location | tst.js:297:35:297:42 | location | Cross-site scripting vulnerability due to $@. | tst.js:297:35:297:42 | location | user-provided value |
696701
| v-html.vue:2:8:2:23 | v-html=tainted | v-html.vue:6:42:6:58 | document.location | v-html.vue:2:8:2:23 | v-html=tainted | Cross-site scripting vulnerability due to $@. | v-html.vue:6:42:6:58 | document.location | user-provided value |
697702
| winjs.js:3:43:3:49 | tainted | winjs.js:2:17:2:33 | document.location | winjs.js:3:43:3:49 | tainted | Cross-site scripting vulnerability due to $@. | winjs.js:2:17:2:33 | document.location | user-provided value |
698703
| winjs.js:4:43:4:49 | tainted | winjs.js:2:17:2:33 | document.location | winjs.js:4:43:4:49 | tainted | Cross-site scripting vulnerability due to $@. | winjs.js:2:17:2:33 | document.location | user-provided value |

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,7 @@ function flowThroughPropertyNames() {
292292
for (var p in obj)
293293
$(p); // OK
294294
}
295+
296+
function handlebarsSafeString() {
297+
return new Handlebars.SafeString(location); // NOT OK!
298+
}

0 commit comments

Comments
 (0)