@@ -31,16 +31,19 @@ abstract class RemoteFlowSource extends SourceNode {
31
31
class GitHubCtxSource extends RemoteFlowSource {
32
32
string flag ;
33
33
string event ;
34
+ GitHubExpression e ;
34
35
35
36
GitHubCtxSource ( ) {
36
- exists ( Expression e , string context , string context_prefix |
37
- this .asExpr ( ) = e and
38
- context = e .getExpression ( ) and
39
- normalizeExpr ( context ) = "github.head_ref" and
40
- event = e .getEnclosingWorkflow ( ) .getATriggerEvent ( ) .getName ( ) and
41
- contextTriggerDataModel ( event , context_prefix ) and
42
- normalizeExpr ( context ) .matches ( "%" + context_prefix + "%" ) and
43
- flag = "branch"
37
+ this .asExpr ( ) = e and
38
+ // github.head_ref
39
+ e .getFieldName ( ) = "head_ref" and
40
+ flag = "branch" and
41
+ (
42
+ event = e .getATriggerEvent ( ) .getName ( ) and
43
+ event = "pull_request_target"
44
+ or
45
+ not exists ( e .getATriggerEvent ( ) ) and
46
+ event = "unknown"
44
47
)
45
48
}
46
49
@@ -58,15 +61,16 @@ class GitHubEventCtxSource extends RemoteFlowSource {
58
61
exists ( Expression e , string regexp |
59
62
this .asExpr ( ) = e and
60
63
context = e .getExpression ( ) and
61
- event = e .getATriggerEvent ( ) .getName ( ) and
62
64
(
63
65
// the context is available for the job trigger events
66
+ event = e .getATriggerEvent ( ) .getName ( ) and
64
67
exists ( string context_prefix |
65
68
contextTriggerDataModel ( event , context_prefix ) and
66
69
normalizeExpr ( context ) .matches ( "%" + context_prefix + "%" )
67
70
)
68
71
or
69
- exists ( e .getEnclosingCompositeAction ( ) )
72
+ not exists ( e .getATriggerEvent ( ) ) and
73
+ event = "unknown"
70
74
) and
71
75
untrustedEventPropertiesDataModel ( regexp , flag ) and
72
76
not flag = "json" and
@@ -182,20 +186,24 @@ class GitHubEventJsonSource extends RemoteFlowSource {
182
186
exists ( Expression e , string context , string regexp |
183
187
this .asExpr ( ) = e and
184
188
context = e .getExpression ( ) and
185
- event = e .getEnclosingWorkflow ( ) .getATriggerEvent ( ) .getName ( ) and
186
189
untrustedEventPropertiesDataModel ( regexp , _) and
187
190
(
188
191
// only contexts for the triggering events are considered tainted.
189
192
// eg: for `pull_request`, we only consider `github.event.pull_request`
193
+ event = e .getEnclosingWorkflow ( ) .getATriggerEvent ( ) .getName ( ) and
190
194
exists ( string context_prefix |
191
195
contextTriggerDataModel ( event , context_prefix ) and
192
196
normalizeExpr ( context ) .matches ( "%" + context_prefix + "%" )
193
197
) and
194
198
normalizeExpr ( context ) .regexpMatch ( "(?i).*" + wrapJsonRegexp ( regexp ) + ".*" )
195
199
or
196
- // github.event is taintes for all triggers
200
+ // github.event is tainted for all triggers
201
+ event = e .getEnclosingWorkflow ( ) .getATriggerEvent ( ) .getName ( ) and
197
202
contextTriggerDataModel ( e .getEnclosingWorkflow ( ) .getATriggerEvent ( ) .getName ( ) , _) and
198
203
normalizeExpr ( context ) .regexpMatch ( "(?i).*" + wrapJsonRegexp ( "\\bgithub.event\\b" ) + ".*" )
204
+ or
205
+ not exists ( e .getATriggerEvent ( ) ) and
206
+ event = "unknown"
199
207
) and
200
208
flag = "json"
201
209
)
0 commit comments