Skip to content

Commit b98db62

Browse files
committed
JS: Recognize req.user a cookie access
1 parent a68bb9f commit b98db62

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

javascript/ql/src/Security/CWE-352/MissingCsrfMiddleware.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212

1313
import javascript
1414

15-
/** Gets the string `session` or `cookies`, the parts of `req` containing cookie data. */
16-
string sessionOrCookies() {
17-
result = "session" or result = "cookies"
15+
/** Gets a property name of `req` which refers to data usually derived from cookie data. */
16+
string cookieProperty() {
17+
result = "session" or result = "cookies" or result = "user"
1818
}
1919

2020
/** Gets a data flow node that flows to the base of an access to `cookies` or `session`. */
2121
private DataFlow::SourceNode nodeLeadingToCookieAccess(DataFlow::TypeBackTracker t) {
2222
t.start() and
2323
exists(DataFlow::PropRead value |
24-
value = result.getAPropertyRead(sessionOrCookies()).getAPropertyRead() and
24+
value = result.getAPropertyRead(cookieProperty()).getAPropertyRead() and
2525

2626
// Ignore accesses to values that are part of a CSRF or captcha check
2727
not value.getPropertyName().regexpMatch("(?i).*(csrf|xsrf|captcha).*") and

javascript/ql/test/query-tests/Security/CWE-352/MissingCsrfMiddleware.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
| lusca_example.js:9:9:9:22 | cookieParser() | This cookie middleware is serving a request handler $@ without CSRF protection. | lusca_example.js:26:42:29:1 | functio ... sed')\\n} | here |
55
| lusca_example.js:9:9:9:22 | cookieParser() | This cookie middleware is serving a request handler $@ without CSRF protection. | lusca_example.js:31:40:34:1 | functio ... sed')\\n} | here |
66
| unused_cookies.js:6:9:6:22 | cookieParser() | This cookie middleware is serving a request handler $@ without CSRF protection. | unused_cookies.js:8:34:13:1 | (req, r ... Ok');\\n} | here |
7+
| unused_cookies.js:6:9:6:22 | cookieParser() | This cookie middleware is serving a request handler $@ without CSRF protection. | unused_cookies.js:29:19:32:1 | (req, r ... Ok');\\n} | here |
8+
| unused_cookies.js:6:9:6:22 | cookieParser() | This cookie middleware is serving a request handler $@ without CSRF protection. | unused_cookies.js:34:22:37:1 | (req, r ... Ok');\\n} | here |

javascript/ql/test/query-tests/Security/CWE-352/unused_cookies.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,14 @@ app.post('/doWithCaptcha', (req, res) => { // OK - attacker can't guess the capt
2626
res.end('Ok');
2727
});
2828

29+
app.post('/user', (req, res) => { // NOT OK - access to req.user is unprotected
30+
somethingElse(req.user.name);
31+
res.end('Ok');
32+
});
33+
34+
app.post('/session', (req, res) => { // NOT OK - access to req.session is unprotected
35+
somethingElse(req.session.name);
36+
res.end('Ok');
37+
});
38+
2939
app.listen();

0 commit comments

Comments
 (0)