Sitelet https://web.archive.org/web/20260305070930/https://github.com/github/codeql/pull/4478
Skip to content

JS: add support for custom CSRF protecting middlewares in js/missing-token-validation#4478

Merged
codeql-ci merged 6 commits intogithub:mainfrom
erik-krogh:homegrownCsrf
Oct 19, 2020
Merged

JS: add support for custom CSRF protecting middlewares in js/missing-token-validation#4478
codeql-ci merged 6 commits intogithub:mainfrom
erik-krogh:homegrownCsrf

Conversation

@erik-krogh
Copy link
Contributor

@erik-krogh erik-krogh commented Oct 14, 2020 •

Gets a TN for CVE-2020-15135

Adds detection for custom made CSFR protecting route-handlers in js/missing-token-validation.
A CSFR protecting route-handler is detected by it having some write to a CSFR related cookie or session variable.

Here are some example CSRF protecting route-handlers found with GitHub grep: https://lgtm.com/query/4468160787766813050/

An evaluation looks ok.

@erik-krogh erik-krogh changed the title JS: add support for home made CSRF protection middlewares in js/missing-token-validation JS: add support for custom CSRF protecting middlewares in js/missing-token-validation Oct 16, 2020
@erik-krogh erik-krogh marked this pull request as ready for review October 16, 2020 08:38
@erik-krogh erik-krogh requested a review from a team as a code owner October 16, 2020 08:38
*/
private DataFlow::SourceNode nodeLeadingToCsrfWrite(DataFlow::TypeBackTracker t) {
t.start() and
exists(DataFlow::PropRef value |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be simpler if we inline value? (Or if not, change its type to PropWrite)

setCsrfToken: setCsrfToken
};

app.use(express.csrf({ value: csrf.getCsrfToken }));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is express.csrf? Does that offer CSRF protection? Because it looks like the test has two CSRF middlewares now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does half of the CSRF protection.
express.csrf is responsible for checking the CSRF token.
And csrf.setCsrfToken is responsible for setting the CSRF cookie.

express.csrf has been deprecated in favor of csurf, so you will only see this pattern in older codebases.
(Altough it is easy to find uses on github).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add express.csrf to csrfMiddlewareCreation then? If it's the one that performs the check, then it's the half that matters for security.

Co-authored-by: Asger F <asgerf@github.com>
Copy link
Contributor

@asgerf asgerf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants