Skip to content

Commit 6732493

Browse files
committed
add model for jwt-decode
1 parent 1e048d8 commit 6732493

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

javascript/ql/src/javascript.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import semmle.javascript.frameworks.EventEmitter
8585
import semmle.javascript.frameworks.Files
8686
import semmle.javascript.frameworks.Firebase
8787
import semmle.javascript.frameworks.jQuery
88+
import semmle.javascript.frameworks.JWT
8889
import semmle.javascript.frameworks.Handlebars
8990
import semmle.javascript.frameworks.LazyCache
9091
import semmle.javascript.frameworks.LodashUnderscore
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Provides classes for working with JWT libraries.
3+
*/
4+
5+
import javascript
6+
7+
/**
8+
* Provides classes and predicates modelling the `jwt-decode` libary.
9+
*/
10+
private module JwtDecode {
11+
/**
12+
* A taint-step for `succ = require("jwt-decode")(pred)`.
13+
*/
14+
private class JwtDecodeStep extends TaintTracking::AdditionalTaintStep, DataFlow::CallNode {
15+
JwtDecodeStep() { this = DataFlow::moduleImport("jwt-decode").getACall() }
16+
17+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
18+
pred = this.getArgument(0) and
19+
succ = this
20+
}
21+
}
22+
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ nodes
125125
| jquery.js:16:38:16:52 | window.location |
126126
| jquery.js:16:38:16:52 | window.location |
127127
| jquery.js:16:38:16:63 | window. ... tring() |
128+
| jwt.js:4:36:4:39 | data |
129+
| jwt.js:4:36:4:39 | data |
130+
| jwt.js:5:9:5:34 | decoded |
131+
| jwt.js:5:19:5:34 | jwt_decode(data) |
132+
| jwt.js:5:30:5:33 | data |
133+
| jwt.js:6:14:6:20 | decoded |
134+
| jwt.js:6:14:6:20 | decoded |
128135
| nodemailer.js:13:11:13:69 | `Hi, yo ... sage}.` |
129136
| nodemailer.js:13:11:13:69 | `Hi, yo ... sage}.` |
130137
| nodemailer.js:13:50:13:66 | req.query.message |
@@ -720,6 +727,12 @@ edges
720727
| jquery.js:16:38:16:52 | window.location | jquery.js:16:38:16:63 | window. ... tring() |
721728
| jquery.js:16:38:16:63 | window. ... tring() | jquery.js:16:19:16:64 | decodeU ... ring()) |
722729
| jquery.js:16:38:16:63 | window. ... tring() | jquery.js:16:19:16:64 | decodeU ... ring()) |
730+
| jwt.js:4:36:4:39 | data | jwt.js:5:30:5:33 | data |
731+
| jwt.js:4:36:4:39 | data | jwt.js:5:30:5:33 | data |
732+
| jwt.js:5:9:5:34 | decoded | jwt.js:6:14:6:20 | decoded |
733+
| jwt.js:5:9:5:34 | decoded | jwt.js:6:14:6:20 | decoded |
734+
| jwt.js:5:19:5:34 | jwt_decode(data) | jwt.js:5:9:5:34 | decoded |
735+
| jwt.js:5:30:5:33 | data | jwt.js:5:19:5:34 | jwt_decode(data) |
723736
| nodemailer.js:13:50:13:66 | req.query.message | nodemailer.js:13:11:13:69 | `Hi, yo ... sage}.` |
724737
| nodemailer.js:13:50:13:66 | req.query.message | nodemailer.js:13:11:13:69 | `Hi, yo ... sage}.` |
725738
| nodemailer.js:13:50:13:66 | req.query.message | nodemailer.js:13:11:13:69 | `Hi, yo ... sage}.` |
@@ -1165,4 +1178,5 @@ edges
11651178
| winjs.js:2:17:2:40 | documen ... .search | winjs.js:2:17:2:53 | documen ... ring(1) |
11661179
| winjs.js:2:17:2:53 | documen ... ring(1) | winjs.js:2:7:2:53 | tainted |
11671180
#select
1181+
| jwt.js:6:14:6:20 | decoded | jwt.js:4:36:4:39 | data | jwt.js:6:14:6:20 | decoded | Cross-site scripting vulnerability due to $@. | jwt.js:4:36:4:39 | data | user-provided value |
11681182
| typeahead.js:10:16:10:18 | loc | typeahead.js:9:28:9:30 | loc | typeahead.js:10:16:10:18 | loc | Cross-site scripting vulnerability due to $@. | typeahead.js:9:28:9:30 | loc | user-provided value |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import jwt_decode from "jwt-decode";
2+
import $ from "jquery"
3+
4+
$.post(loginUrl(), {data: "foo"}, (data, xhr) => {
5+
var decoded = jwt_decode(data);
6+
$.jGrowl(decoded); // NOT OK - but only flagged with additional sources [INCONSISTENCY]
7+
});

0 commit comments

Comments
 (0)