@@ -109,6 +109,23 @@ private string getCookieValue(string s, string attribute) {
109
109
result = s .regexpCapture ( "(?i).*;\\s*" + attribute + "=(\\w+)\\b\\s*;?.*$" , 1 )
110
110
}
111
111
112
+ /**
113
+ * Gets the "SameSite" value for a given `node`.
114
+ * Converts boolean values to the corresponding string value.
115
+ *
116
+ * Not all libraries support boolean values for the `SameSite` attribute,
117
+ * but here we assume that they do.
118
+ */
119
+ private string getSameSiteValue ( DataFlow:: Node node ) {
120
+ node .mayHaveStringValue ( result )
121
+ or
122
+ node .mayHaveBooleanValue ( true ) and
123
+ result = "Strict"
124
+ or
125
+ node .mayHaveBooleanValue ( false ) and
126
+ result = "Lax"
127
+ }
128
+
112
129
/**
113
130
* A model of the `js-cookie` library (https://github.com/js-cookie/js-cookie).
114
131
*/
@@ -150,7 +167,7 @@ private module JsCookie {
150
167
override predicate isSensitive ( ) { canHaveSensitiveCookie ( this .getArgument ( 0 ) ) }
151
168
152
169
override string getSameSite ( ) {
153
- this .getOptionArgument ( 2 , "sameSite" ) . mayHaveStringValue ( result )
170
+ result = getSameSiteValue ( this .getOptionArgument ( 2 , "sameSite" ) )
154
171
}
155
172
}
156
173
}
@@ -195,7 +212,7 @@ private module BrowserCookies {
195
212
override predicate isSensitive ( ) { canHaveSensitiveCookie ( this .getArgument ( 0 ) ) }
196
213
197
214
override string getSameSite ( ) {
198
- this .getOptionArgument ( 2 , "samesite" ) . mayHaveStringValue ( result )
215
+ result = getSameSiteValue ( this .getOptionArgument ( 2 , "samesite" ) )
199
216
or
200
217
// or, an explicit default has been set
201
218
DataFlow:: moduleMember ( "browser-cookies" , "defaults" )
@@ -242,10 +259,7 @@ private module LibCookie {
242
259
override predicate isSensitive ( ) { canHaveSensitiveCookie ( this .getArgument ( 0 ) ) }
243
260
244
261
override string getSameSite ( ) {
245
- this .getOptionArgument ( 2 , "sameSite" ) .mayHaveStringValue ( result )
246
- or
247
- this .getOptionArgument ( 2 , "sameSite" ) .mayHaveBooleanValue ( true ) and
248
- result = "Strict"
262
+ result = getSameSiteValue ( this .getOptionArgument ( 2 , "sameSite" ) )
249
263
}
250
264
}
251
265
}
@@ -280,10 +294,7 @@ private module ExpressCookies {
280
294
}
281
295
282
296
override string getSameSite ( ) {
283
- this .getOptionArgument ( 2 , "sameSite" ) .mayHaveStringValue ( result )
284
- or
285
- this .getOptionArgument ( 2 , "sameSite" ) .mayHaveBooleanValue ( true ) and
286
- result = "Strict"
297
+ result = getSameSiteValue ( this .getOptionArgument ( 2 , "sameSite" ) )
287
298
}
288
299
}
289
300
@@ -312,12 +323,7 @@ private module ExpressCookies {
312
323
not this .getCookieFlagValue ( CookieWrites:: httpOnly ( ) ) .mayHaveBooleanValue ( false )
313
324
}
314
325
315
- override string getSameSite ( ) {
316
- this .getCookieFlagValue ( "sameSite" ) .mayHaveStringValue ( result )
317
- or
318
- this .getCookieFlagValue ( "sameSite" ) .mayHaveBooleanValue ( true ) and
319
- result = "Strict"
320
- }
326
+ override string getSameSite ( ) { result = getSameSiteValue ( this .getCookieFlagValue ( "sameSite" ) ) }
321
327
}
322
328
323
329
/**
@@ -348,12 +354,7 @@ private module ExpressCookies {
348
354
not this .getCookieFlagValue ( CookieWrites:: httpOnly ( ) ) .mayHaveBooleanValue ( false )
349
355
}
350
356
351
- override string getSameSite ( ) {
352
- this .getCookieFlagValue ( "sameSite" ) .mayHaveStringValue ( result )
353
- or
354
- this .getCookieFlagValue ( "sameSite" ) .mayHaveBooleanValue ( true ) and
355
- result = "Strict"
356
- }
357
+ override string getSameSite ( ) { result = getSameSiteValue ( this .getCookieFlagValue ( "sameSite" ) ) }
357
358
}
358
359
}
359
360
0 commit comments