@@ -100,18 +100,21 @@ DataFlow::CallNode csrfMiddlewareCreation() {
100100}
101101
102102/**
103- * Gets a data flow node that flows to the base of a write to `cookies`, `session`, or `user`,
104- * where the written property has `csrf` or `xsrf` in its name.
103+ * Gets a data flow node that flows to the base of a reference to `cookies`, `session`, or `user`,
104+ * where the references property has `csrf` or `xsrf` in its name,
105+ * and a property is either written or part of a comparison.
105106 */
106- private DataFlow:: SourceNode nodeLeadingToCsrfWrite ( DataFlow:: TypeBackTracker t ) {
107+ private DataFlow:: SourceNode nodeLeadingToCsrfWriteOrCheck ( DataFlow:: TypeBackTracker t ) {
107108 t .start ( ) and
108- result
109- .getAPropertyRead ( cookieProperty ( ) )
110- .getAPropertyWrite ( )
111- .getPropertyName ( )
112- .regexpMatch ( "(?i).*(csrf|xsrf).*" )
109+ exists ( DataFlow:: PropRef ref |
110+ ref = result .getAPropertyRead ( cookieProperty ( ) ) .getAPropertyReference ( ) and
111+ ref .getPropertyName ( ) .regexpMatch ( "(?i).*(csrf|xsrf).*" )
112+ |
113+ ref instanceof DataFlow:: PropWrite or
114+ ref .( DataFlow:: PropRead ) .asExpr ( ) = any ( EqualityTest c ) .getAnOperand ( )
115+ )
113116 or
114- exists ( DataFlow:: TypeBackTracker t2 | result = nodeLeadingToCsrfWrite ( t2 ) .backtrack ( t2 , t ) )
117+ exists ( DataFlow:: TypeBackTracker t2 | result = nodeLeadingToCsrfWriteOrCheck ( t2 ) .backtrack ( t2 , t ) )
115118}
116119
117120/**
@@ -131,7 +134,7 @@ private Express::RouteHandler getAHandlerSettingCsrfCookie() {
131134 */
132135predicate isCsrfProtectionRouteHandler ( Express:: RouteHandler handler ) {
133136 DataFlow:: parameterNode ( handler .getRequestParameter ( ) ) =
134- nodeLeadingToCsrfWrite ( DataFlow:: TypeBackTracker:: end ( ) )
137+ nodeLeadingToCsrfWriteOrCheck ( DataFlow:: TypeBackTracker:: end ( ) )
135138 or
136139 handler = getAHandlerSettingCsrfCookie ( )
137140}
0 commit comments