Skip to content

Commit c6110ed

Browse files
Split SecureCookies into query specific files
1 parent 5b702d9 commit c6110ed

File tree

4 files changed

+46
-41
lines changed

4 files changed

+46
-41
lines changed

go/ql/lib/semmle/go/security/SecureCookies.qll renamed to go/ql/lib/semmle/go/security/CookieWithoutHttpOnly.qll

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** Provides classes and predicates for identifying HTTP cookies with insecure attributes. */
1+
/** Provides classes and predicates for identifying HTTP cookies without the `HttpOnly` attribute. */
22

33
import go
44
import semmle.go.concepts.HTTP
@@ -31,21 +31,6 @@ private module SensitiveCookieNameConfig implements DataFlow::ConfigSig {
3131
/** Tracks flow from sensitive names to HTTP cookie writes. */
3232
module SensitiveCookieNameFlow = TaintTracking::Global<SensitiveCookieNameConfig>;
3333

34-
private module BooleanCookieSecureConfig implements DataFlow::ConfigSig {
35-
predicate isSource(DataFlow::Node source) {
36-
source.getType().getUnderlyingType() instanceof BoolType
37-
}
38-
39-
predicate isSink(DataFlow::Node sink) { exists(Http::CookieWrite cw | sink = cw.getSecure()) }
40-
41-
predicate isAdditionalFlowStep(DataFlow::Node pred, DataFlow::Node succ) {
42-
exists(Http::CookieOptionWrite co | co.getSecure() = pred and co.getCookieOutput() = succ)
43-
}
44-
}
45-
46-
/** Tracks flow from boolean expressions to the `Secure` attribute of HTTP cookie writes. */
47-
module BooleanCookieSecureFlow = TaintTracking::Global<BooleanCookieSecureConfig>;
48-
4934
private module BooleanCookieHttpOnlyConfig implements DataFlow::ConfigSig {
5035
predicate isSource(DataFlow::Node source) {
5136
source.getType().getUnderlyingType() instanceof BoolType
@@ -61,23 +46,6 @@ private module BooleanCookieHttpOnlyConfig implements DataFlow::ConfigSig {
6146
/** Tracks flow from boolean expressions to the `HttpOnly` attribute of HTTP cookie writes. */
6247
module BooleanCookieHttpOnlyFlow = TaintTracking::Global<BooleanCookieHttpOnlyConfig>;
6348

64-
/** Holds if `cw` has the `Secure` attribute left at its default value of `false`. */
65-
predicate isInsecureDefault(Http::CookieWrite cw) {
66-
not BooleanCookieSecureFlow::flow(_, cw.getSecure())
67-
}
68-
69-
/** Holds if `cw` has the `Secure` attribute explicitly set to `false`, from the expression `boolFalse`. */
70-
predicate isInsecureDirect(Http::CookieWrite cw, Expr boolFalse) {
71-
BooleanCookieSecureFlow::flow(DataFlow::exprNode(boolFalse), cw.getSecure()) and
72-
boolFalse.getBoolValue() = false
73-
}
74-
75-
/** Holds if `cw` has the `Secure` attribute set to `false`, either explicitly or by default. */
76-
predicate isInsecureCookie(Http::CookieWrite cw) {
77-
isInsecureDefault(cw) or
78-
isInsecureDirect(cw, _)
79-
}
80-
8149
/** Holds if `cw` has the `HttpOnly` attribute left at its default value of `false`. */
8250
predicate isNonHttpOnlyDefault(Http::CookieWrite cw) {
8351
not BooleanCookieHttpOnlyFlow::flow(_, cw.getHttpOnly())
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/** Provides classes and predicates for identifying HTTP cookies without the `Secure` attribute. */
2+
3+
import go
4+
import semmle.go.concepts.HTTP
5+
import semmle.go.dataflow.DataFlow
6+
7+
private module BooleanCookieSecureConfig implements DataFlow::ConfigSig {
8+
predicate isSource(DataFlow::Node source) {
9+
source.getType().getUnderlyingType() instanceof BoolType
10+
}
11+
12+
predicate isSink(DataFlow::Node sink) { exists(Http::CookieWrite cw | sink = cw.getSecure()) }
13+
14+
predicate isAdditionalFlowStep(DataFlow::Node pred, DataFlow::Node succ) {
15+
exists(Http::CookieOptionWrite co | co.getSecure() = pred and co.getCookieOutput() = succ)
16+
}
17+
}
18+
19+
/** Tracks flow from boolean expressions to the `Secure` attribute of HTTP cookie writes. */
20+
module BooleanCookieSecureFlow = TaintTracking::Global<BooleanCookieSecureConfig>;
21+
22+
/** Holds if `cw` has the `Secure` attribute left at its default value of `false`. */
23+
predicate isInsecureDefault(Http::CookieWrite cw) {
24+
not BooleanCookieSecureFlow::flow(_, cw.getSecure())
25+
}
26+
27+
/** Holds if `cw` has the `Secure` attribute explicitly set to `false`, from the expression `boolFalse`. */
28+
predicate isInsecureDirect(Http::CookieWrite cw, Expr boolFalse) {
29+
BooleanCookieSecureFlow::flow(DataFlow::exprNode(boolFalse), cw.getSecure()) and
30+
boolFalse.getBoolValue() = false
31+
}
32+
33+
/** Holds if `cw` has the `Secure` attribute set to `false`, either explicitly or by default. */
34+
predicate isInsecureCookie(Http::CookieWrite cw) {
35+
isInsecureDefault(cw) or
36+
isInsecureDirect(cw, _)
37+
}

go/ql/src/Security/CWE-1004/CookieWithoutHttpOnly.ql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
*/
1313

1414
import go
15-
import semmle.go.security.SecureCookies
15+
import semmle.go.security.CookieWithoutHttpOnly
1616
import SensitiveCookieNameFlow::PathGraph
1717

1818
from
19-
Http::CookieWrite cw, Expr sensitiveNameExpr, string name,
20-
SensitiveCookieNameFlow::PathNode source, SensitiveCookieNameFlow::PathNode sink
19+
Http::CookieWrite cw, string name, SensitiveCookieNameFlow::PathNode source,
20+
SensitiveCookieNameFlow::PathNode sink
2121
where
22-
isSensitiveCookie(cw, sensitiveNameExpr, name, source, sink) and
22+
isSensitiveCookie(cw, name, source, sink) and
2323
isNonHttpOnlyCookie(cw)
24-
select cw, source, sink, "Sensitive cookie $@ does not set HttpOnly attribute to true.",
25-
sensitiveNameExpr, name
24+
select cw, source, sink, "Sensitive cookie $@ does not set HttpOnly attribute to true.", source,
25+
name

go/ql/src/Security/CWE-614/CookieWithoutSecure.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
* @kind problem
66
* @problem.severity warning
77
* @precision high
8-
* @security-severity 5.0
8+
* @security-severity 4.0
99
* @id go/cookie-secure-not-set
1010
* @tags security
1111
* external/cwe/cwe-614
1212
*/
1313

1414
import go
15-
import semmle.go.security.SecureCookies
15+
import semmle.go.security.CookieWithoutSecure
1616

1717
from Http::CookieWrite cw
1818
where isInsecureCookie(cw)

0 commit comments

Comments
 (0)