Skip to content

Commit 1f2e8d8

Browse files
committed
Address Feedback
1 parent 3697ef7 commit 1f2e8d8

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ module GinCors {
2222
* A write to the value of Access-Control-Allow-Credentials header
2323
*/
2424
class AllowCredentialsWrite extends DataFlow::ExprNode {
25-
DataFlow::Node base;
2625
GinConfig gc;
2726

2827
AllowCredentialsWrite() {
29-
exists(Field f, Write w |
28+
exists(Field f, Write w, DataFlow::Node base |
3029
f.hasQualifiedName(packagePath(), "Config", "AllowCredentials") and
3130
w.writesField(base, f, this) and
3231
this.getType() instanceof BoolType and
@@ -48,11 +47,10 @@ module GinCors {
4847
* A write to the value of Access-Control-Allow-Origins header
4948
*/
5049
class AllowOriginsWrite extends DataFlow::ExprNode {
51-
DataFlow::Node base;
5250
GinConfig gc;
5351

5452
AllowOriginsWrite() {
55-
exists(Field f, Write w |
53+
exists(Field f, Write w, DataFlow::Node base |
5654
f.hasQualifiedName(packagePath(), "Config", "AllowOrigins") and
5755
w.writesField(base, f, this) and
5856
this.asExpr() instanceof SliceLit and
@@ -74,11 +72,10 @@ module GinCors {
7472
* A write to the value of Access-Control-Allow-Origins of value "*", overriding AllowOrigins
7573
*/
7674
class AllowAllOriginsWrite extends DataFlow::ExprNode {
77-
DataFlow::Node base;
7875
GinConfig gc;
7976

8077
AllowAllOriginsWrite() {
81-
exists(Field f, Write w |
78+
exists(Field f, Write w, DataFlow::Node base |
8279
f.hasQualifiedName(packagePath(), "Config", "AllowAllOrigins") and
8380
w.writesField(base, f, this) and
8481
this.getType() instanceof BoolType and

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ predicate allowCredentialsIsSetToTrue(DataFlow::ExprNode allowOriginHW) {
103103
)
104104
or
105105
exists(GinCors::AllowCredentialsWrite allowCredentialsGin |
106-
allowCredentialsGin.toString() = "true"
106+
allowCredentialsGin.getExpr().getBoolValue() = true
107107
|
108108
//flow only goes in one direction so fix this before PR
109109
allowCredentialsGin.getConfig() = allowOriginHW.(GinCors::AllowOriginsWrite).getConfig() and
110110
not exists(GinCors::AllowAllOriginsWrite allowAllOrigins |
111-
allowAllOrigins.toString() = "true" and
111+
allowAllOrigins.getExpr().getBoolValue() = true and
112112
allowCredentialsGin.getConfig() = allowAllOrigins.getConfig()
113113
)
114114
)
@@ -149,8 +149,8 @@ predicate allowOriginIsNull(DataFlow::ExprNode allowOriginHW, string message) {
149149
.asExpr()
150150
.(SliceLit)
151151
.getAnElement()
152-
.toString()
153-
.toLowerCase() = "\"null\"" and
152+
.getStringValue()
153+
.toLowerCase() = "null" and
154154
message =
155155
headerAllowOrigin() + " header is set to `" + "null" + "`, and " + headerAllowCredentials() +
156156
" is set to `true`"

go/ql/test/experimental/CWE-942/vendor/github.com/gin-contrib/cors/stub.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)