Skip to content

Commit 7eabed6

Browse files
Split insecure cookies queries into 3 queries
1 parent 398f29a commit 7eabed6

File tree

3 files changed

+41
-34
lines changed

3 files changed

+41
-34
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @name Cookie missing `HttpOnly` attribute.
3+
* @description Cookies without the `HttpOnly` attribute set can be accessed by JS scripts, making them more vulnerable to XSS attacks.
4+
* @kind problem
5+
* @problem.severity warning
6+
* @security-severity 5.0
7+
* @precision high
8+
* @id py/client-exposed-cookie
9+
* @tags security
10+
* external/cwe/cwe-1004
11+
*/
12+
13+
import python
14+
import semmle.python.dataflow.new.DataFlow
15+
import semmle.python.Concepts
16+
17+
from Http::Server::CookieWrite cookie
18+
where cookie.hasHttpOnlyFlag(false)
19+
select cookie, "Cookie is added without the HttpOnly attribute properly set."
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @name Cookie with `SameSite` attribute set to `None`.
3+
* @description Cookies with `SameSite` set to `None` can allow for Cross-Site Request Forgery (CSRF) attacks.
4+
* @kind problem
5+
* @problem.severity warning
6+
* @security-severity 5.0
7+
* @precision high
8+
* @id py/samesite-none-cookie
9+
* @tags security
10+
* external/cwe/cwe-1275
11+
*/
12+
13+
import python
14+
import semmle.python.dataflow.new.DataFlow
15+
import semmle.python.Concepts
16+
17+
from Http::Server::CookieWrite cookie
18+
where cookie.hasSameSiteAttribute(any(Http::Server::CookieWrite::SameSiteNone v))
19+
select cookie, "Cookie is added with the SameSite attribute set to None."

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

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,12 @@
99
* @id py/insecure-cookie
1010
* @tags security
1111
* external/cwe/cwe-614
12-
* external/cwe/cwe-1004
13-
* external/cwe/cwe-1275
1412
*/
1513

1614
import python
1715
import semmle.python.dataflow.new.DataFlow
1816
import semmle.python.Concepts
1917

20-
predicate hasProblem(Http::Server::CookieWrite cookie, string alert, int idx) {
21-
cookie.hasSecureFlag(false) and
22-
alert = "Secure" and
23-
idx = 0
24-
or
25-
cookie.hasHttpOnlyFlag(false) and
26-
alert = "HttpOnly" and
27-
idx = 1
28-
or
29-
cookie.hasSameSiteAttribute(any(Http::Server::CookieWrite::SameSiteNone v)) and
30-
alert = "SameSite" and
31-
idx = 2
32-
}
33-
34-
predicate hasAlert(Http::Server::CookieWrite cookie, string alert) {
35-
exists(int numProblems | numProblems = strictcount(string p | hasProblem(cookie, p, _)) |
36-
numProblems = 1 and
37-
alert = any(string prob | hasProblem(cookie, prob, _)) + " attribute"
38-
or
39-
numProblems = 2 and
40-
alert =
41-
strictconcat(string prob, int idx | hasProblem(cookie, prob, idx) | prob, " and " order by idx)
42-
+ " attributes"
43-
or
44-
numProblems = 3 and
45-
alert = "Secure, HttpOnly, and SameSite attributes"
46-
)
47-
}
48-
49-
from Http::Server::CookieWrite cookie, string alert
50-
where hasAlert(cookie, alert)
51-
select cookie, "Cookie is added without the " + alert + " properly set."
18+
from Http::Server::CookieWrite cookie
19+
where cookie.hasSecureFlag(false)
20+
select cookie, "Cookie is added without the Secure attribute properly set."

0 commit comments

Comments
 (0)