Skip to content

Commit 57bd3f3

Browse files
committed
Optimize the taint flow source
1 parent fe0e7f5 commit 57bd3f3

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

java/ql/src/experimental/Security/CWE/CWE-1004/SensitiveCookieNotHttpOnly.ql

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ predicate setHttpOnlyInCookie(MethodAccess ma) {
9797
class SetHttpOnlyInCookieConfiguration extends TaintTracking2::Configuration {
9898
SetHttpOnlyInCookieConfiguration() { this = "SetHttpOnlyInCookieConfiguration" }
9999

100-
override predicate isSource(DataFlow::Node source) { any() }
100+
override predicate isSource(DataFlow::Node source) {
101+
source.asExpr() =
102+
any(MethodAccess ma | setHttpOnlyInCookie(ma) or removeCookie(ma)).getQualifier()
103+
}
101104

102105
override predicate isSink(DataFlow::Node sink) {
103106
sink.asExpr() =
@@ -123,21 +126,11 @@ class CookieResponseSink extends DataFlow::ExprNode {
123126
(
124127
ma.getMethod() instanceof ResponseAddCookieMethod and
125128
this.getExpr() = ma.getArgument(0) and
126-
not exists(
127-
MethodAccess ma2 // a method or wrapper method that invokes cookie.setHttpOnly(true)
128-
|
129-
(
130-
setHttpOnlyInCookie(ma2) or
131-
removeCookie(ma2)
132-
) and
133-
exists(SetHttpOnlyInCookieConfiguration cc |
134-
cc.hasFlow(DataFlow::exprNode(ma2.getQualifier()), this)
135-
)
136-
)
129+
not exists(SetHttpOnlyInCookieConfiguration cc | cc.hasFlowTo(this))
137130
or
138131
ma instanceof SetCookieMethodAccess and
139132
this.getExpr() = ma.getArgument(1) and
140-
not exists(MatchesHttpOnlyConfiguration cc | cc.hasFlowToExpr(ma.getArgument(1))) // response.addHeader("Set-Cookie", "token=" +authId + ";HttpOnly;Secure")
133+
not exists(MatchesHttpOnlyConfiguration cc | cc.hasFlowTo(this)) // response.addHeader("Set-Cookie", "token=" +authId + ";HttpOnly;Secure")
141134
) and
142135
not isTestMethod(ma) // Test class or method
143136
)

0 commit comments

Comments
 (0)