Skip to content

Commit 9ad6c8c

Browse files
Implement cookie attributes for cases in which a raw header is set
1 parent 2df09f6 commit 9ad6c8c

File tree

3 files changed

+56
-90
lines changed

3 files changed

+56
-90
lines changed

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

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,17 +1250,70 @@ module Http {
12501250
/**
12511251
* Holds if the `Secure` flag of the cookie is known to have a value of `b`.
12521252
*/
1253-
predicate hasSecureFlag(boolean b) { none() }
1253+
predicate hasSecureFlag(boolean b) {
1254+
exists(this.getHeaderArg()) and
1255+
(
1256+
exists(StringLiteral sl |
1257+
sl.getText().regexpMatch("(?i).*;\\s*secure;.*") and
1258+
TaintTracking::localTaint(DataFlow::exprNode(sl), this.getHeaderArg()) and
1259+
b = true
1260+
)
1261+
or
1262+
exists(StringLiteral sl |
1263+
not sl.getText().regexpMatch("(?i).*;\\s*secure;.*") and
1264+
DataFlow::localFlow(DataFlow::exprNode(sl), this.getHeaderArg()) and
1265+
b = false
1266+
)
1267+
)
1268+
}
12541269

12551270
/**
12561271
* Holds if the `HttpOnly` flag of the cookie is known to have a value of `b`.
12571272
*/
1258-
predicate hasHttpOnlyFlag(boolean b) { none() }
1273+
predicate hasHttpOnlyFlag(boolean b) {
1274+
exists(this.getHeaderArg()) and
1275+
(
1276+
exists(StringLiteral sl |
1277+
sl.getText().regexpMatch("(?i).*;\\s*httponly;.*") and
1278+
TaintTracking::localTaint(DataFlow::exprNode(sl), this.getHeaderArg()) and
1279+
b = true
1280+
)
1281+
or
1282+
exists(StringLiteral sl |
1283+
not sl.getText().regexpMatch("(?i).*;\\s*httponly;.*") and
1284+
DataFlow::localFlow(DataFlow::exprNode(sl), this.getHeaderArg()) and
1285+
b = false
1286+
)
1287+
)
1288+
}
12591289

12601290
/**
12611291
* Holds if the `SameSite` flag of the cookie is known to have a value of `b`.
12621292
*/
1263-
predicate hasSameSiteFlag(boolean b) { none() }
1293+
// TODO: b could be a newtype with 3 values indicating Strict,Lax,or None
1294+
// currently, Strict and Lax are represented with true and None is represented with false.
1295+
predicate hasSameSiteFlag(boolean b) {
1296+
exists(this.getHeaderArg()) and
1297+
(
1298+
exists(StringLiteral sl |
1299+
sl.getText().regexpMatch("(?i).*;\\s*samesite=(strict|lax);.*") and
1300+
TaintTracking::localTaint(DataFlow::exprNode(sl), this.getHeaderArg()) and
1301+
b = true
1302+
)
1303+
or
1304+
exists(StringLiteral sl |
1305+
sl.getText().regexpMatch("(?i).*;\\s*samesite=none;.*") and
1306+
TaintTracking::localTaint(DataFlow::exprNode(sl), this.getHeaderArg()) and
1307+
b = false
1308+
)
1309+
or
1310+
exists(StringLiteral sl |
1311+
not sl.getText().regexpMatch("(?i).*;\\s*samesite=(strict|lax|none);.*") and
1312+
DataFlow::localFlow(DataFlow::exprNode(sl), this.getHeaderArg()) and
1313+
b = true // Lax is the default
1314+
)
1315+
)
1316+
}
12641317
}
12651318
}
12661319

python/ql/src/experimental/Security/CWE-614/InsecureCookie.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import python
1717
import semmle.python.dataflow.new.DataFlow
1818
import experimental.semmle.python.Concepts
1919
import semmle.python.Concepts
20-
import experimental.semmle.python.CookieHeader
2120

2221
from Http::Server::CookieWrite cookie, string alert
2322
where

python/ql/src/experimental/semmle/python/CookieHeader.qll

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)