Skip to content

Commit ed8d025

Browse files
edvraaowen-mc
authored andcommitted
Dedicated types
1 parent cba4f04 commit ed8d025

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
import go
22

3+
private class NetHttpCookieType extends Type {
4+
NetHttpCookieType() { this.hasQualifiedName(package("net/http", ""), "Cookie") }
5+
}
6+
7+
private class GinContextSetCookieMethod extends Method {
8+
GinContextSetCookieMethod() {
9+
this.hasQualifiedName(package("github.com/gin-gonic/gin", ""), "Context", "SetCookie")
10+
}
11+
}
12+
13+
private class GorillaSessionOptionsField extends Field {
14+
GorillaSessionOptionsField() {
15+
this.hasQualifiedName(package("github.com/gorilla/sessions", ""), "Session", "Options")
16+
}
17+
}
18+
319
/**
420
* A simplistic points-to alternative: given a struct creation and a field name, get the values that field can be assigned.
521
*
@@ -57,7 +73,7 @@ class NetHttpCookieTrackingConfiguration extends TaintTracking::Configuration {
5773
override predicate isSource(DataFlow::Node source) {
5874
exists(StructLit sl |
5975
source.asExpr() = sl and
60-
sl.getType().hasQualifiedName(package("net/http", ""), "Cookie")
76+
sl.getType() instanceof NetHttpCookieType
6177
)
6278
}
6379

@@ -82,7 +98,7 @@ private class NameToNetHttpCookieTrackingConfiguration extends TaintTracking2::C
8298

8399
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
84100
exists(StructLit sl |
85-
sl.getType().hasQualifiedName(package("net/http", ""), "Cookie") and
101+
sl.getType() instanceof NetHttpCookieType and
86102
getValueForFieldWrite(sl, "Name") = pred and
87103
sl = succ.asExpr()
88104
)
@@ -101,7 +117,7 @@ class BoolToNetHttpCookieTrackingConfiguration extends TaintTracking::Configurat
101117

102118
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
103119
exists(StructLit sl |
104-
sl.getType().hasQualifiedName(package("net/http", ""), "Cookie") and
120+
sl.getType() instanceof NetHttpCookieType and
105121
getValueForFieldWrite(sl, "HttpOnly") = pred and
106122
sl = succ.asExpr()
107123
)
@@ -118,8 +134,7 @@ class BoolToGinSetCookieTrackingConfiguration extends DataFlow::Configuration {
118134

119135
override predicate isSink(DataFlow::Node sink) {
120136
exists(DataFlow::MethodCallNode mcn |
121-
mcn.getTarget()
122-
.hasQualifiedName(package("github.com/gin-gonic/gin", ""), "Context", "SetCookie") and
137+
mcn.getTarget() instanceof GinContextSetCookieMethod and
123138
mcn.getArgument(6) = sink and
124139
exists(NameToGinSetCookieTrackingConfiguration cfg, DataFlow::Node nameArg |
125140
cfg.hasFlow(_, nameArg) and
@@ -139,8 +154,7 @@ private class NameToGinSetCookieTrackingConfiguration extends DataFlow2::Configu
139154

140155
override predicate isSink(DataFlow::Node sink) {
141156
exists(DataFlow::MethodCallNode mcn |
142-
mcn.getTarget()
143-
.hasQualifiedName(package("github.com/gin-gonic/gin", ""), "Context", "SetCookie") and
157+
mcn.getTarget() instanceof GinContextSetCookieMethod and
144158
mcn.getArgument(0) = sink
145159
)
146160
}
@@ -204,8 +218,7 @@ class GorillaSessionOptionsTrackingConfiguration extends TaintTracking::Configur
204218
override predicate isSink(DataFlow::Node sink) { sink instanceof GorillaSessionSaveSink }
205219

206220
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
207-
exists(Field f, DataFlow::Write w, DataFlow::Node base |
208-
f.hasQualifiedName(package("github.com/gorilla/sessions", ""), "Session", "Options") and
221+
exists(GorillaSessionOptionsField f, DataFlow::Write w, DataFlow::Node base |
209222
w.writesField(base, f, pred) and
210223
succ = base
211224
)
@@ -230,8 +243,7 @@ class BoolToGorillaSessionOptionsTrackingConfiguration extends TaintTracking::Co
230243
sl = succ.asExpr()
231244
)
232245
or
233-
exists(Field f, DataFlow::Write w, DataFlow::Node base |
234-
f.hasQualifiedName(package("github.com/gorilla/sessions", ""), "Session", "Options") and
246+
exists(GorillaSessionOptionsField f, DataFlow::Write w, DataFlow::Node base |
235247
w.writesField(base, f, pred) and
236248
succ = base
237249
)

0 commit comments

Comments
 (0)