2
2
* Provides classes for modeling the `github.com/rs/cors` package.
3
3
*/
4
4
5
- import go
6
-
7
- /**
8
- * Provides classes for modeling the `github.com/rs/cors` package.
9
- */
10
- module RsCors {
11
- /** Gets the package name `github.com/gin-gonic/gin`. */
12
- string packagePath ( ) { result = package ( "github.com/rs/cors" , "" ) }
13
-
14
- /**
15
- * A new function create a new gin Handler that passed to gin as middleware
16
- */
17
- class New extends Function {
18
- New ( ) { exists ( Function f | f .hasQualifiedName ( packagePath ( ) , "New" ) | this = f ) }
19
- }
20
-
21
- /**
22
- * A write to the value of Access-Control-Allow-Credentials header
23
- */
24
- class AllowCredentialsWrite extends DataFlow:: ExprNode {
25
- DataFlow:: Node base ;
26
-
27
- AllowCredentialsWrite ( ) {
28
- exists ( Field f , Write w |
29
- f .hasQualifiedName ( packagePath ( ) , "Options" , "AllowCredentials" ) and
30
- w .writesField ( base , f , this ) and
31
- this .getType ( ) instanceof BoolType
32
- )
33
- }
34
-
35
- /**
36
- * Get config struct holding header values
37
- */
38
- DataFlow:: Node getBase ( ) { result = base }
39
-
40
- /**
41
- * Get config variable holding header values
42
- */
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
- }
53
- }
54
-
55
- /**
56
- * A write to the value of Access-Control-Allow-Origins header
57
- */
58
- class AllowOriginsWrite extends DataFlow:: ExprNode {
59
- DataFlow:: Node base ;
60
-
61
- AllowOriginsWrite ( ) {
62
- exists ( Field f , Write w |
63
- f .hasQualifiedName ( packagePath ( ) , "Options" , "AllowedOrigins" ) and
64
- w .writesField ( base , f , this ) and
65
- this .asExpr ( ) instanceof SliceLit
66
- )
67
- }
68
-
69
- /**
70
- * Get config struct holding header values
71
- */
72
- DataFlow:: Node getBase ( ) { result = base }
73
-
74
- /**
75
- * Get config variable holding header values
76
- */
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
- }
87
- }
88
-
89
- /**
90
- * A write to the value of Access-Control-Allow-Origins of value "*", overriding AllowOrigins
91
- */
92
- class AllowAllOriginsWrite extends DataFlow:: ExprNode {
93
- DataFlow:: Node base ;
94
-
95
- AllowAllOriginsWrite ( ) {
96
- exists ( Field f , Write w |
97
- f .hasQualifiedName ( packagePath ( ) , "Options" , "AllowAllOrigins" ) and
98
- w .writesField ( base , f , this ) and
99
- this .getType ( ) instanceof BoolType
100
- )
101
- }
102
-
103
- /**
104
- * Get config struct holding header values
105
- */
106
- DataFlow:: Node getBase ( ) { result = base }
107
-
108
- /**
109
- * Get config variable holding header values
110
- */
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
- }
121
- }
122
-
123
- /**
124
- * A variable of type Config that holds the headers to be set.
125
- */
126
- class RsOptions extends Variable {
127
- SsaWithFields v ;
128
-
129
- RsOptions ( ) {
130
- this = v .getBaseVariable ( ) .getSourceVariable ( ) and
131
- exists ( Type t | t .hasQualifiedName ( packagePath ( ) , "Options" ) | v .getType ( ) = t )
132
- }
133
-
134
- /**
135
- * Get variable declaration of GinConfig
136
- */
137
- SsaWithFields getV ( ) { result = v }
138
- }
139
- }
5
+ import go
6
+
7
+ /**
8
+ * Provides abstract class for modeling the Go CORS handler model origin write.
9
+ */
10
+ abstract class UniversalOriginWrite extends DataFlow:: ExprNode {
11
+ abstract DataFlow:: Node getBase ( ) ;
12
+
13
+ abstract Variable getConfig ( ) ;
14
+ }
15
+
16
+ /**
17
+ * Provides abstract class for modeling the Go CORS handler model allow all origins write.
18
+ */
19
+ abstract class UniversalAllowAllOriginsWrite extends DataFlow:: ExprNode {
20
+ abstract DataFlow:: Node getBase ( ) ;
21
+
22
+ abstract Variable getConfig ( ) ;
23
+ }
24
+
25
+ /**
26
+ * Provides abstract class for modeling the Go CORS handler model allow credentials write.
27
+ */
28
+ abstract class UniversalAllowCredentialsWrite extends DataFlow:: ExprNode {
29
+ abstract DataFlow:: Node getBase ( ) ;
30
+
31
+ abstract Variable getConfig ( ) ;
32
+ }
33
+
34
+ /**
35
+ * Provides classes for modeling the `github.com/rs/cors` package.
36
+ */
37
+ module RsCors {
38
+ /** Gets the package name `github.com/gin-gonic/gin`. */
39
+ string packagePath ( ) { result = package ( "github.com/rs/cors" , "" ) }
40
+
41
+ /**
42
+ * A new function create a new rs Handler
43
+ */
44
+ class New extends Function {
45
+ New ( ) { exists ( Function f | f .hasQualifiedName ( packagePath ( ) , "New" ) | this = f ) }
46
+ }
47
+
48
+ /**
49
+ * A write to the value of Access-Control-Allow-Credentials header
50
+ */
51
+ class AllowCredentialsWrite extends UniversalAllowCredentialsWrite {
52
+ DataFlow:: Node base ;
53
+
54
+ AllowCredentialsWrite ( ) {
55
+ exists ( Field f , Write w |
56
+ f .hasQualifiedName ( packagePath ( ) , "Options" , "AllowCredentials" ) and
57
+ w .writesField ( base , f , this ) and
58
+ this .getType ( ) instanceof BoolType
59
+ )
60
+ }
61
+
62
+ /**
63
+ * Get options struct holding header values
64
+ */
65
+ override DataFlow:: Node getBase ( ) { result = base }
66
+
67
+ /**
68
+ * Get options variable holding header values
69
+ */
70
+ override RsOptions getConfig ( ) {
71
+ exists ( RsOptions gc |
72
+ (
73
+ gc .getV ( ) .getBaseVariable ( ) .getDefinition ( ) .( SsaExplicitDefinition ) .getRhs ( ) =
74
+ base .asInstruction ( ) or
75
+ gc .getV ( ) .getAUse ( ) = base
76
+ ) and
77
+ result = gc
78
+ )
79
+ }
80
+ }
81
+
82
+ /**
83
+ * A write to the value of Access-Control-Allow-Origins header
84
+ */
85
+ class AllowOriginsWrite extends UniversalOriginWrite {
86
+ DataFlow:: Node base ;
87
+
88
+ AllowOriginsWrite ( ) {
89
+ exists ( Field f , Write w |
90
+ f .hasQualifiedName ( packagePath ( ) , "Options" , "AllowedOrigins" ) and
91
+ w .writesField ( base , f , this ) and
92
+ this .asExpr ( ) instanceof SliceLit
93
+ )
94
+ }
95
+
96
+ /**
97
+ * Get options struct holding header values
98
+ */
99
+ override DataFlow:: Node getBase ( ) { result = base }
100
+
101
+ /**
102
+ * Get options variable holding header values
103
+ */
104
+ override RsOptions getConfig ( ) {
105
+ exists ( RsOptions gc |
106
+ (
107
+ gc .getV ( ) .getBaseVariable ( ) .getDefinition ( ) .( SsaExplicitDefinition ) .getRhs ( ) =
108
+ base .asInstruction ( ) or
109
+ gc .getV ( ) .getAUse ( ) = base
110
+ ) and
111
+ result = gc
112
+ )
113
+ }
114
+ }
115
+
116
+ /**
117
+ * A write to the value of Access-Control-Allow-Origins of value "*", overriding AllowOrigins
118
+ */
119
+ class AllowAllOriginsWrite extends UniversalAllowAllOriginsWrite {
120
+ DataFlow:: Node base ;
121
+
122
+ AllowAllOriginsWrite ( ) {
123
+ exists ( Field f , Write w |
124
+ f .hasQualifiedName ( packagePath ( ) , "Options" , "AllowAllOrigins" ) and
125
+ w .writesField ( base , f , this ) and
126
+ this .getType ( ) instanceof BoolType
127
+ )
128
+ }
129
+
130
+ /**
131
+ * Get options struct holding header values
132
+ */
133
+ override DataFlow:: Node getBase ( ) { result = base }
134
+
135
+ /**
136
+ * Get options variable holding header values
137
+ */
138
+ override RsOptions getConfig ( ) {
139
+ exists ( RsOptions gc |
140
+ (
141
+ gc .getV ( ) .getBaseVariable ( ) .getDefinition ( ) .( SsaExplicitDefinition ) .getRhs ( ) =
142
+ base .asInstruction ( ) or
143
+ gc .getV ( ) .getAUse ( ) = base
144
+ ) and
145
+ result = gc
146
+ )
147
+ }
148
+ }
149
+
150
+ /**
151
+ * A variable of type Options that holds the headers to be set.
152
+ */
153
+ class RsOptions extends Variable {
154
+ SsaWithFields v ;
155
+
156
+ RsOptions ( ) {
157
+ this = v .getBaseVariable ( ) .getSourceVariable ( ) and
158
+ exists ( Type t | t .hasQualifiedName ( packagePath ( ) , "Options" ) | v .getType ( ) = t )
159
+ }
160
+
161
+ /**
162
+ * Get variable declaration of Options
163
+ */
164
+ SsaWithFields getV ( ) { result = v }
165
+ }
166
+ }
0 commit comments