Skip to content

Commit 5cab256

Browse files
committed
Address issues
1 parent 8ed1031 commit 5cab256

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

go/ql/lib/semmle/go/frameworks/GinCors.qll

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
/**
2-
* Provides classes for working with untrusted flow sources from the `github.com/gin-contrib/cors` package.
2+
* Provides classes for modeling the `github.com/gin-contrib/cors` package.
33
*/
44

55
import go
66

7+
/**
8+
* Provides classes for modeling the `github.com/gin-contrib/cors` package.
9+
*/
710
module GinCors {
811
/** Gets the package name `github.com/gin-gonic/gin`. */
912
string packagePath() { result = package("github.com/gin-contrib/cors", "") }
@@ -35,6 +38,9 @@ module GinCors {
3538
)
3639
}
3740

41+
/**
42+
* Get config variable holding header values
43+
*/
3844
GinConfig getConfig() { result = gc }
3945
}
4046

@@ -58,6 +64,9 @@ module GinCors {
5864
)
5965
}
6066

67+
/**
68+
* Get config variable holding header values
69+
*/
6170
GinConfig getConfig() { result = gc }
6271
}
6372

@@ -81,6 +90,9 @@ module GinCors {
8190
)
8291
}
8392

93+
/**
94+
* Get config variable holding header values
95+
*/
8496
GinConfig getConfig() { result = gc }
8597
}
8698

go/ql/src/experimental/CWE-942/CorsMisconfiguration.ql

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ predicate allowCredentialsIsSetToTrue(DataFlow::ExprNode allowOriginHW) {
9898
exists(AllowCredentialsHeaderWrite allowCredentialsHW |
9999
allowCredentialsHW.getHeaderValue().toLowerCase() = "true"
100100
|
101-
allowOriginHW.(AllowOriginHeaderWrite).getResponseWriter() =
101+
allowOriginHW.(AllowOriginHeaderWrite).getResponseWriter() =
102102
allowCredentialsHW.getResponseWriter()
103103
)
104104
or
@@ -141,8 +141,8 @@ predicate allowOriginIsNull(DataFlow::ExprNode allowOriginHW, string message) {
141141
allowOriginHW.(AllowOriginHeaderWrite).getHeaderValue().toLowerCase() = "null" and
142142
message =
143143
headerAllowOrigin() + " header is set to `" +
144-
allowOriginHW.(AllowOriginHeaderWrite).getHeaderValue() + "`, and " + headerAllowCredentials() +
145-
" is set to `true`"
144+
allowOriginHW.(AllowOriginHeaderWrite).getHeaderValue() + "`, and " + headerAllowCredentials()
145+
+ " is set to `true`"
146146
or
147147
allowOriginHW
148148
.(GinCors::AllowOriginsWrite)
@@ -152,8 +152,8 @@ predicate allowOriginIsNull(DataFlow::ExprNode allowOriginHW, string message) {
152152
.toString()
153153
.toLowerCase() = "\"null\"" and
154154
message =
155-
headerAllowOrigin() + " header is set to `" + "null" + "`, and " +
156-
headerAllowCredentials() + " is set to `true`"
155+
headerAllowOrigin() + " header is set to `" + "null" + "`, and " + headerAllowCredentials() +
156+
" is set to `true`"
157157
}
158158

159159
/**
@@ -219,18 +219,18 @@ predicate flowsToGuardedByCheckOnUntrusted(DataFlow::ExprNode allowOriginHW) {
219219
)
220220
}
221221

222-
from DataFlow::ExprNode allowOrigin, string message
222+
from DataFlow::ExprNode allowOriginHW, string message
223223
where
224-
allowCredentialsIsSetToTrue(allowOrigin) and
224+
allowCredentialsIsSetToTrue(allowOriginHW) and
225225
(
226-
flowsFromUntrustedToAllowOrigin(allowOrigin, message)
226+
flowsFromUntrustedToAllowOrigin(allowOriginHW, message)
227227
or
228-
allowOriginIsNull(allowOrigin, message)
228+
allowOriginIsNull(allowOriginHW, message)
229229
) and
230-
not flowsToGuardedByCheckOnUntrusted(allowOrigin) and
230+
not flowsToGuardedByCheckOnUntrusted(allowOriginHW) and
231231
not exists(ControlFlow::ConditionGuardNode cgn |
232232
cgn.ensures(any(AllowedFlag f).getAFlag().getANode(), _)
233233
|
234-
cgn.dominates(allowOrigin.getBasicBlock())
234+
cgn.dominates(allowOriginHW.getBasicBlock())
235235
)
236-
select allowOrigin, message
236+
select allowOriginHW, message

0 commit comments

Comments
 (0)