Skip to content

Commit d7add29

Browse files
authored
Merge pull request #4359 from erik-krogh/cookieWrites
Approved by esbena
2 parents 910c19e + 51f1f03 commit d7add29

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

change-notes/1.26/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
| Unsafe shell command constructed from library input (`js/shell-command-constructed-from-input`) | More results | This query now recognizes more commands where colon, dash, and underscore are used. |
4141
| Unsafe jQuery plugin (`js/unsafe-jquery-plugin`) | More results | This query now detects more unsafe uses of nested option properties. |
4242
| Client-side URL redirect (`js/client-side-unvalidated-url-redirection`) | More results | This query now recognizes some unsafe uses of `importScripts()` inside WebWorkers. |
43+
| Missing CSRF middleware (`js/missing-token-validation`) | More results | This query now recognizes writes to cookie and session variables as potentially vulnerable to CSRF attacks. |
4344

4445

4546
## Changes to libraries

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ string cookieProperty() { result = "session" or result = "cookies" or result = "
1818
/** Gets a data flow node that flows to the base of an access to `cookies`, `session`, or `user`. */
1919
private DataFlow::SourceNode nodeLeadingToCookieAccess(DataFlow::TypeBackTracker t) {
2020
t.start() and
21-
exists(DataFlow::PropRead value |
22-
value = result.getAPropertyRead(cookieProperty()).getAPropertyRead() and
21+
exists(DataFlow::PropRef value |
22+
value = result.getAPropertyRead(cookieProperty()).getAPropertyReference() and
2323
// Ignore accesses to values that are part of a CSRF or captcha check
2424
not value.getPropertyName().regexpMatch("(?i).*(csrf|xsrf|captcha).*") and
2525
// Ignore calls like `req.session.save()`

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
| MissingCsrfMiddlewareBad.js:7:9:7:22 | cookieParser() | This cookie middleware is serving a request handler $@ without CSRF protection. | MissingCsrfMiddlewareBad.js:10:26:12:1 | functio ... il"];\\n} | here |
22
| MissingCsrfMiddlewareBad.js:17:13:17:26 | cookieParser() | This cookie middleware is serving a request handler $@ without CSRF protection. | MissingCsrfMiddlewareBad.js:25:30:27:6 | errorCa ... \\n }) | here |
33
| MissingCsrfMiddlewareBad.js:33:13:33:26 | cookieParser() | This cookie middleware is serving a request handler $@ without CSRF protection. | MissingCsrfMiddlewareBad.js:41:30:43:6 | errorCa ... \\n }) | here |
4+
| MissingCsrfMiddlewareBad.js:33:13:33:26 | cookieParser() | This cookie middleware is serving a request handler $@ without CSRF protection. | MissingCsrfMiddlewareBad.js:45:31:47:6 | errorCa ... \\n }) | here |
45
| csurf_api_example.js:42:37:42:50 | cookieParser() | This cookie middleware is serving a request handler $@ without CSRF protection. | csurf_api_example.js:42:53:45:3 | functio ... e')\\n } | here |
56
| csurf_example.js:18:9:18:22 | cookieParser() | This cookie middleware is serving a request handler $@ without CSRF protection. | csurf_example.js:31:40:34:1 | functio ... sed')\\n} | here |
67
| 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 |

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@ app.post('/changeEmail', function (req, res) {
4141
app.post('/changeEmail', errorCatch(async function (req, res) {
4242
let newEmail = req.cookies["newEmail"];
4343
}));
44+
45+
app.post('/doLoginStuff', errorCatch(async function (req, res) {
46+
req.session.user = loginStuff(req);
47+
}));
4448
})

0 commit comments

Comments
 (0)