Skip to content

Commit 020b4be

Browse files
committed
Finish up
1 parent e078268 commit 020b4be

File tree

4 files changed

+14
-33
lines changed

4 files changed

+14
-33
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added the [gin cors](https://github.com/gin-contrib/cors) library to the CorsMisconfiguration.ql query

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module GinCors {
6262
}
6363

6464
/**
65-
* A write to the value of Access-Control-Allow-Origins to "*"
65+
* A write to the value of Access-Control-Allow-Origins of value "*", overriding AllowOrigins
6666
*/
6767
class AllowAllOriginsWrite extends DataFlow::ExprNode {
6868
DataFlow::Node base;

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ module UntrustedToAllowOriginConfigConfig implements DataFlow::ConfigSig {
8383
*/
8484
module UntrustedToAllowOriginHeaderFlow = TaintTracking::Global<UntrustedToAllowOriginHeaderConfig>;
8585

86+
/**
87+
* Tracks taint flowfor reasoning about when an `UntrustedFlowSource` flows to
88+
* a `AllowOriginsWrite` that writes an `Access-Control-Allow-Origin` header's value.
89+
*/
8690
module UntrustedToAllowOriginConfigFlow = TaintTracking::Global<UntrustedToAllowOriginConfigConfig>;
8791

8892
/**
@@ -111,17 +115,17 @@ predicate allowCredentialsIsSetToTrue(DataFlow::ExprNode allowOrigin) {
111115
}
112116

113117
/**
114-
* Holds if the provided `allowOriginHW` HeaderWrite's value is set using an
118+
* Holds if the provided `allowOrigin` HeaderWrite's value is set using an
115119
* UntrustedFlowSource.
116120
* The `message` parameter is populated with the warning message to be returned by the query.
117121
*/
118-
predicate flowsFromUntrustedToAllowOrigin(DataFlow::ExprNode allowOriginHW, string message) {
122+
predicate flowsFromUntrustedToAllowOrigin(DataFlow::ExprNode allowOrigin, string message) {
119123
exists(DataFlow::Node sink |
120124
UntrustedToAllowOriginHeaderFlow::flowTo(sink) and
121-
UntrustedToAllowOriginHeaderConfig::isSinkHW(sink, allowOriginHW)
125+
UntrustedToAllowOriginHeaderConfig::isSinkHW(sink, allowOrigin)
122126
or
123127
UntrustedToAllowOriginConfigFlow::flowTo(sink) and
124-
UntrustedToAllowOriginConfigConfig::isSinkWrite(sink, allowOriginHW)
128+
UntrustedToAllowOriginConfigConfig::isSinkWrite(sink, allowOrigin)
125129
|
126130
message =
127131
headerAllowOrigin() + " header is set to a user-defined value, and " +
@@ -146,8 +150,7 @@ predicate allowOriginIsNull(DataFlow::ExprNode allowOrigin, string message) {
146150
.(SliceLit)
147151
.getAnElement()
148152
.toString()
149-
.toLowerCase()
150-
.matches("\"null\"") and
153+
.toLowerCase() = "\"null\"" and
151154
message =
152155
headerAllowOrigin() + " header is set to `" + "null" + "`, and " +
153156
//allowOrigin.(GinCors::AllowOriginsWrite).asExpr().(SliceLit).getAnElement().toString()

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

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)