Skip to content

Commit 66b1612

Browse files
committed
JS: Treat non-cookie based auth as CSRF preventer
1 parent b732193 commit 66b1612

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,27 @@ predicate isCsrfProtectionRouteHandler(Routing::RouteHandler handler) {
129129
handler = getAHandlerSettingCsrfCookie()
130130
}
131131

132+
/**
133+
* A call of form `passport.authenticate(..., { session: false })`, implying that the incoming
134+
* request must carry its credentials rather than relying on cookies.
135+
*
136+
* In principle such routes should not be preceded by a cookie-parsing middleware, but to
137+
* reduce noise we do not want to flag them.
138+
*/
139+
API::CallNode nonSessionBasedAuthMiddleware() {
140+
result = API::moduleImport("passport").getMember("authenticate").getACall() and
141+
result.getParameter(1).getMember("session").getARhs().mayHaveBooleanValue(false)
142+
}
143+
132144
/**
133145
* Gets an express route handler expression that is either a custom CSRF protection middleware,
134146
* or a CSRF protecting library.
135147
*/
136148
Routing::Node getACsrfMiddleware() {
137149
result = Routing::getNode(csrfMiddlewareCreation())
138150
or
151+
result = Routing::getNode(nonSessionBasedAuthMiddleware())
152+
or
139153
isCsrfProtectionRouteHandler(result)
140154
}
141155

0 commit comments

Comments
 (0)