Skip to content

Commit 9958ad9

Browse files
committed
thesame
1 parent 28288e0 commit 9958ad9

File tree

1 file changed

+56
-29
lines changed

1 file changed

+56
-29
lines changed

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

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
string packagePath() { result = package("github.com/rs/cors", "") }
1313

1414
/**
15-
* A new function create a new Handler that passed to handler chain as middleware
15+
* A new function create a new gin Handler that passed to gin as middleware
1616
*/
1717
class New extends Function {
1818
New() { exists(Function f | f.hasQualifiedName(packagePath(), "New") | this = f) }
@@ -22,75 +22,102 @@
2222
* A write to the value of Access-Control-Allow-Credentials header
2323
*/
2424
class AllowCredentialsWrite extends DataFlow::ExprNode {
25-
RsOptions rs;
25+
DataFlow::Node base;
2626

2727
AllowCredentialsWrite() {
28-
exists(Field f, Write w, DataFlow::Node base |
28+
exists(Field f, Write w |
2929
f.hasQualifiedName(packagePath(), "Options", "AllowCredentials") and
3030
w.writesField(base, f, this) and
31-
this.getType() instanceof BoolType and
32-
(
33-
rs.getV().getBaseVariable().getDefinition().(SsaExplicitDefinition).getRhs() =
34-
base.asInstruction() or
35-
rs.getV().getAUse() = base
36-
)
31+
this.getType() instanceof BoolType
3732
)
3833
}
3934

35+
/**
36+
* Get config struct holding header values
37+
*/
38+
DataFlow::Node getBase() { result = base }
39+
4040
/**
4141
* Get config variable holding header values
4242
*/
43-
RsOptions getConfig() { result = rs }
43+
RsOptions getConfig() {
44+
exists(RsOptions gc |
45+
(
46+
gc.getV().getBaseVariable().getDefinition().(SsaExplicitDefinition).getRhs() =
47+
base.asInstruction() or
48+
gc.getV().getAUse() = base
49+
) and
50+
result = gc
51+
)
52+
}
4453
}
4554

4655
/**
4756
* A write to the value of Access-Control-Allow-Origins header
4857
*/
4958
class AllowOriginsWrite extends DataFlow::ExprNode {
50-
RsOptions rs;
59+
DataFlow::Node base;
5160

5261
AllowOriginsWrite() {
53-
exists(Field f, Write w, DataFlow::Node base |
62+
exists(Field f, Write w |
5463
f.hasQualifiedName(packagePath(), "Options", "AllowedOrigins") and
5564
w.writesField(base, f, this) and
56-
this.asExpr() instanceof SliceLit and
57-
(
58-
rs.getV().getBaseVariable().getDefinition().(SsaExplicitDefinition).getRhs() =
59-
base.asInstruction() or
60-
rs.getV().getAUse() = base
61-
)
65+
this.asExpr() instanceof SliceLit
6266
)
6367
}
6468

69+
/**
70+
* Get config struct holding header values
71+
*/
72+
DataFlow::Node getBase() { result = base }
73+
6574
/**
6675
* Get config variable holding header values
6776
*/
68-
RsOptions getConfig() { result = rs }
77+
RsOptions getConfig() {
78+
exists(RsOptions gc |
79+
(
80+
gc.getV().getBaseVariable().getDefinition().(SsaExplicitDefinition).getRhs() =
81+
base.asInstruction() or
82+
gc.getV().getAUse() = base
83+
) and
84+
result = gc
85+
)
86+
}
6987
}
7088

7189
/**
7290
* A write to the value of Access-Control-Allow-Origins of value "*", overriding AllowOrigins
7391
*/
7492
class AllowAllOriginsWrite extends DataFlow::ExprNode {
75-
RsOptions rs;
93+
DataFlow::Node base;
7694

7795
AllowAllOriginsWrite() {
78-
exists(Field f, Write w, DataFlow::Node base |
96+
exists(Field f, Write w |
7997
f.hasQualifiedName(packagePath(), "Options", "AllowAllOrigins") and
8098
w.writesField(base, f, this) and
81-
this.getType() instanceof BoolType and
82-
(
83-
rs.getV().getBaseVariable().getDefinition().(SsaExplicitDefinition).getRhs() =
84-
base.asInstruction() or
85-
rs.getV().getAUse() = base
86-
)
99+
this.getType() instanceof BoolType
87100
)
88101
}
89102

103+
/**
104+
* Get config struct holding header values
105+
*/
106+
DataFlow::Node getBase() { result = base }
107+
90108
/**
91109
* Get config variable holding header values
92110
*/
93-
RsOptions getConfig() { result = rs }
111+
RsOptions getConfig() {
112+
exists(RsOptions gc |
113+
(
114+
gc.getV().getBaseVariable().getDefinition().(SsaExplicitDefinition).getRhs() =
115+
base.asInstruction() or
116+
gc.getV().getAUse() = base
117+
) and
118+
result = gc
119+
)
120+
}
94121
}
95122

96123
/**
@@ -105,7 +132,7 @@
105132
}
106133

107134
/**
108-
* Get variable declaration of RsOptions
135+
* Get variable declaration of GinConfig
109136
*/
110137
SsaWithFields getV() { result = v }
111138
}

0 commit comments

Comments
 (0)