Skip to content

Commit 236b623

Browse files
edvraaowen-mc
authored andcommitted
Get rid of NetHttpCookieTrackingConfiguration
1 parent 031a79b commit 236b623

File tree

3 files changed

+92
-64
lines changed

3 files changed

+92
-64
lines changed

ql/src/experimental/CWE-1004/AuthCookie.qll

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private class GorillaSessionOptionsField extends Field {
2525
*
2626
* This should cover most typical patterns...
2727
*/
28-
DataFlow::Node getValueForFieldWrite(StructLit sl, string field) {
28+
private DataFlow::Node getValueForFieldWrite(StructLit sl, string field) {
2929
exists(Write w, DataFlow::Node base, Field f |
3030
f.getName() = field and
3131
w.writesField(base, f, result) and
@@ -64,32 +64,10 @@ private class SetCookieSink extends DataFlow::Node {
6464
}
6565
}
6666

67-
/**
68-
* Tracks `net/http.Cookie` creation to `net/http.SetCookie`.
69-
*/
70-
class NetHttpCookieTrackingConfiguration extends TaintTracking::Configuration {
71-
NetHttpCookieTrackingConfiguration() { this = "NetHttpCookieTrackingConfiguration" }
72-
73-
override predicate isSource(DataFlow::Node source) {
74-
exists(StructLit sl |
75-
source.asExpr() = sl and
76-
sl.getType() instanceof NetHttpCookieType
77-
)
78-
}
79-
80-
override predicate isSink(DataFlow::Node sink) {
81-
sink instanceof SetCookieSink and
82-
exists(NameToNetHttpCookieTrackingConfiguration cfg, DataFlow::Node nameArg |
83-
cfg.hasFlowTo(nameArg) and
84-
sink.asExpr() = nameArg.asExpr()
85-
)
86-
}
87-
}
88-
8967
/**
9068
* Tracks sensitive name to `net/http.SetCookie`.
9169
*/
92-
private class NameToNetHttpCookieTrackingConfiguration extends TaintTracking2::Configuration {
70+
class NameToNetHttpCookieTrackingConfiguration extends TaintTracking::Configuration {
9371
NameToNetHttpCookieTrackingConfiguration() { this = "NameToNetHttpCookieTrackingConfiguration" }
9472

9573
override predicate isSource(DataFlow::Node source) { isAuthVariable(source.asExpr()) }
@@ -106,12 +84,14 @@ private class NameToNetHttpCookieTrackingConfiguration extends TaintTracking2::C
10684
}
10785

10886
/**
109-
* Tracks `HttpOnly` set to `false` to `net/http.SetCookie`.
87+
* Tracks `bool` assigned to `HttpOnly` that flows into `net/http.SetCookie`.
11088
*/
11189
class BoolToNetHttpCookieTrackingConfiguration extends TaintTracking::Configuration {
11290
BoolToNetHttpCookieTrackingConfiguration() { this = "BoolToNetHttpCookieTrackingConfiguration" }
11391

114-
override predicate isSource(DataFlow::Node source) { source.asExpr().getBoolValue() = false }
92+
override predicate isSource(DataFlow::Node source) {
93+
source.asExpr().getType().getUnderlyingType() instanceof BoolType
94+
}
11595

11696
override predicate isSink(DataFlow::Node sink) { sink instanceof SetCookieSink }
11797

ql/src/experimental/CWE-1004/CookieWithoutHttpOnly.ql

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,20 @@ import DataFlow::PathGraph
1818

1919
/** Holds if `HttpOnly` of `net/http.SetCookie` is set to `false` or not set (default value is used). */
2020
predicate isNetHttpCookieFlow(DataFlow::PathNode source, DataFlow::PathNode sink) {
21-
exists(DataFlow::PathNode cookieCreate, DataFlow::PathNode setCookieSink |
22-
exists(NetHttpCookieTrackingConfiguration cfg | cfg.hasFlowPath(cookieCreate, setCookieSink)) and
21+
exists(DataFlow::PathNode sensitiveName, DataFlow::PathNode setCookieSink |
22+
exists(NameToNetHttpCookieTrackingConfiguration cfg |
23+
cfg.hasFlowPath(sensitiveName, setCookieSink)
24+
) and
2325
(
24-
not exists(getValueForFieldWrite(cookieCreate.getNode().asExpr(), "HttpOnly")) and
25-
source = cookieCreate and
26+
not exists(BoolToNetHttpCookieTrackingConfiguration cfg |
27+
cfg.hasFlowTo(setCookieSink.getNode())
28+
) and
29+
source = sensitiveName and
2630
sink = setCookieSink
2731
or
2832
exists(BoolToNetHttpCookieTrackingConfiguration cfg |
2933
cfg.hasFlow(source.getNode(), setCookieSink.getNode()) and
34+
source.getNode().getBoolValue() = false and
3035
sink = setCookieSink
3136
)
3237
)

0 commit comments

Comments
 (0)