Skip to content

Commit d997eee

Browse files
joefarebrotheryoff
andauthored
Code review suggestions - make definitions clearer
Co-authored-by: yoff <[email protected]>
1 parent 8f714c6 commit d997eee

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

python/ql/lib/semmle/python/Concepts.qll

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,19 +1251,16 @@ module Http {
12511251
* Holds if the `Secure` flag of the cookie is known to have a value of `b`.
12521252
*/
12531253
predicate hasSecureFlag(boolean b) {
1254-
exists(this.getHeaderArg()) and
1255-
(
1256-
exists(StringLiteral sl |
1257-
sl.getText().regexpMatch("(?i).*;\\s*secure(;.*|\\s*)") and
1258-
TaintTracking::localTaint(DataFlow::exprNode(sl), this.getHeaderArg()) and
1259-
b = true
1260-
)
1254+
exists(StringLiteral sl |
1255+
// `sl` is likely a substring of the header
1256+
TaintTracking::localTaint(DataFlow::exprNode(sl), this.getHeaderArg()) and
1257+
sl.getText().regexpMatch("(?i).*;\\s*secure(;.*|\\s*)") and
1258+
b = true
12611259
or
1262-
exists(StringLiteral sl |
1263-
not sl.getText().regexpMatch("(?i).*;\\s*secure(;.*|\\s*)") and
1264-
DataFlow::localFlow(DataFlow::exprNode(sl), this.getHeaderArg()) and
1265-
b = false
1266-
)
1260+
// `sl` is the entire header
1261+
DataFlow::localFlow(DataFlow::exprNode(sl), this.getHeaderArg()) and
1262+
not sl.getText().regexpMatch("(?i).*;\\s*secure(;.*|\\s*)") and
1263+
b = false
12671264
)
12681265
}
12691266

@@ -1291,31 +1288,24 @@ module Http {
12911288
* Holds if the `SameSite` flag of the cookie is known to have a value of `v`.
12921289
*/
12931290
predicate hasSameSiteAttribute(SameSiteValue v) {
1294-
exists(this.getHeaderArg()) and
1295-
(
1296-
exists(StringLiteral sl |
1291+
exists(StringLiteral sl |
1292+
// `sl` is likely a substring of the header
1293+
TaintTracking::localTaint(DataFlow::exprNode(sl), this.getHeaderArg()) and
1294+
(
12971295
sl.getText().regexpMatch("(?i).*;\\s*samesite=strict(;.*|\\s*)") and
1298-
TaintTracking::localTaint(DataFlow::exprNode(sl), this.getHeaderArg()) and
12991296
v instanceof SameSiteStrict
1300-
)
1301-
or
1302-
exists(StringLiteral sl |
1297+
or
13031298
sl.getText().regexpMatch("(?i).*;\\s*samesite=lax(;.*|\\s*)") and
1304-
TaintTracking::localTaint(DataFlow::exprNode(sl), this.getHeaderArg()) and
13051299
v instanceof SameSiteLax
1306-
)
1307-
or
1308-
exists(StringLiteral sl |
1300+
or
13091301
sl.getText().regexpMatch("(?i).*;\\s*samesite=none(;.*|\\s*)") and
1310-
TaintTracking::localTaint(DataFlow::exprNode(sl), this.getHeaderArg()) and
13111302
v instanceof SameSiteNone
13121303
)
13131304
or
1314-
exists(StringLiteral sl |
1315-
not sl.getText().regexpMatch("(?i).*;\\s*samesite=(strict|lax|none)(;.*|\\s*)") and
1316-
DataFlow::localFlow(DataFlow::exprNode(sl), this.getHeaderArg()) and
1317-
v instanceof SameSiteLax // Lax is the default
1318-
)
1305+
// `sl` is the entire header
1306+
DataFlow::localFlow(DataFlow::exprNode(sl), this.getHeaderArg()) and
1307+
not sl.getText().regexpMatch("(?i).*;\\s*samesite=(strict|lax|none)(;.*|\\s*)") and
1308+
v instanceof SameSiteLax // Lax is the default
13191309
)
13201310
}
13211311
}

0 commit comments

Comments
 (0)