@@ -18,39 +18,47 @@ abstract class RemoteFlowSource extends SourceNode {
18
18
/** Gets a string that describes the type of this remote flow source. */
19
19
abstract string getSourceType ( ) ;
20
20
21
+ /** Gets the event that triggered the source. */
22
+ abstract Event getEvent ( ) ;
23
+
21
24
override string getThreatModel ( ) { result = "remote" }
22
25
}
23
26
24
27
class GitHubCtxSource extends RemoteFlowSource {
25
28
string flag ;
29
+ Event event ;
26
30
27
31
GitHubCtxSource ( ) {
28
32
exists ( Expression e , string context , string context_prefix |
29
33
this .asExpr ( ) = e and
30
34
context = e .getExpression ( ) and
35
+ event = e .getEnclosingWorkflow ( ) .getATriggerEvent ( ) and
31
36
normalizeExpr ( context ) = "github.head_ref" and
32
- contextTriggerDataModel ( e . getEnclosingWorkflow ( ) . getATriggerEvent ( ) .getName ( ) , context_prefix ) and
37
+ contextTriggerDataModel ( event .getName ( ) , context_prefix ) and
33
38
normalizeExpr ( context ) .matches ( "%" + context_prefix + "%" ) and
34
39
flag = "branch"
35
40
)
36
41
}
37
42
38
43
override string getSourceType ( ) { result = flag }
44
+
45
+ override Event getEvent ( ) { result = event }
39
46
}
40
47
41
48
class GitHubEventCtxSource extends RemoteFlowSource {
42
49
string flag ;
43
50
string context ;
51
+ Event event ;
44
52
45
53
GitHubEventCtxSource ( ) {
46
54
exists ( Expression e , string regexp |
47
55
this .asExpr ( ) = e and
48
56
context = e .getExpression ( ) and
57
+ event = e .getATriggerEvent ( ) and
49
58
(
50
59
// the context is available for the job trigger events
51
60
exists ( string context_prefix |
52
- contextTriggerDataModel ( e .getEnclosingWorkflow ( ) .getATriggerEvent ( ) .getName ( ) ,
53
- context_prefix ) and
61
+ contextTriggerDataModel ( event .getName ( ) , context_prefix ) and
54
62
normalizeExpr ( context ) .matches ( "%" + context_prefix + "%" )
55
63
)
56
64
or
@@ -65,12 +73,16 @@ class GitHubEventCtxSource extends RemoteFlowSource {
65
73
override string getSourceType ( ) { result = flag }
66
74
67
75
string getContext ( ) { result = context }
76
+
77
+ override Event getEvent ( ) { result = event }
68
78
}
69
79
70
80
abstract class CommandSource extends RemoteFlowSource {
71
81
abstract string getCommand ( ) ;
72
82
73
83
abstract Run getEnclosingRun ( ) ;
84
+
85
+ override Event getEvent ( ) { result = this .getEnclosingRun ( ) .getATriggerEvent ( ) }
74
86
}
75
87
76
88
class GitCommandSource extends RemoteFlowSource , CommandSource {
@@ -181,18 +193,19 @@ class GitHubEventPathSource extends RemoteFlowSource, CommandSource {
181
193
182
194
class GitHubEventJsonSource extends RemoteFlowSource {
183
195
string flag ;
196
+ Event event ;
184
197
185
198
GitHubEventJsonSource ( ) {
186
199
exists ( Expression e , string context , string regexp |
187
200
this .asExpr ( ) = e and
188
201
context = e .getExpression ( ) and
202
+ event = e .getEnclosingWorkflow ( ) .getATriggerEvent ( ) and
189
203
untrustedEventPropertiesDataModel ( regexp , _) and
190
204
(
191
205
// only contexts for the triggering events are considered tainted.
192
206
// eg: for `pull_request`, we only consider `github.event.pull_request`
193
207
exists ( string context_prefix |
194
- contextTriggerDataModel ( e .getEnclosingWorkflow ( ) .getATriggerEvent ( ) .getName ( ) ,
195
- context_prefix ) and
208
+ contextTriggerDataModel ( event .getName ( ) , context_prefix ) and
196
209
normalizeExpr ( context ) .matches ( "%" + context_prefix + "%" )
197
210
) and
198
211
normalizeExpr ( context ) .regexpMatch ( "(?i).*" + wrapJsonRegexp ( regexp ) + ".*" )
@@ -206,6 +219,8 @@ class GitHubEventJsonSource extends RemoteFlowSource {
206
219
}
207
220
208
221
override string getSourceType ( ) { result = flag }
222
+
223
+ override Event getEvent ( ) { result = event }
209
224
}
210
225
211
226
/**
@@ -217,6 +232,8 @@ class MaDSource extends RemoteFlowSource {
217
232
MaDSource ( ) { madSource ( this , sourceType , _) }
218
233
219
234
override string getSourceType ( ) { result = sourceType }
235
+
236
+ override Event getEvent ( ) { result = this .asExpr ( ) .getATriggerEvent ( ) }
220
237
}
221
238
222
239
abstract class FileSource extends RemoteFlowSource { }
@@ -228,12 +245,16 @@ class ArtifactSource extends RemoteFlowSource, FileSource {
228
245
ArtifactSource ( ) { this .asExpr ( ) instanceof UntrustedArtifactDownloadStep }
229
246
230
247
override string getSourceType ( ) { result = "artifact" }
248
+
249
+ override Event getEvent ( ) { result = this .asExpr ( ) .getATriggerEvent ( ) }
231
250
}
232
251
233
252
/**
234
253
* A file from an untrusted checkout.
235
254
*/
236
255
private class CheckoutSource extends RemoteFlowSource , FileSource {
256
+ Event event ;
257
+
237
258
CheckoutSource ( ) {
238
259
// This should be:
239
260
// source instanceof PRHeadCheckoutStep
@@ -245,7 +266,8 @@ private class CheckoutSource extends RemoteFlowSource, FileSource {
245
266
uses .getCallee ( ) = "actions/checkout" and
246
267
exists ( uses .getArgument ( "ref" ) ) and
247
268
not uses .getArgument ( "ref" ) .matches ( "%base%" ) and
248
- uses .getATriggerEvent ( ) .getName ( ) = checkoutTriggers ( )
269
+ event = uses .getATriggerEvent ( ) and
270
+ event .getName ( ) = checkoutTriggers ( )
249
271
)
250
272
or
251
273
this .asExpr ( ) instanceof GitMutableRefCheckout
@@ -258,6 +280,8 @@ private class CheckoutSource extends RemoteFlowSource, FileSource {
258
280
}
259
281
260
282
override string getSourceType ( ) { result = "artifact" }
283
+
284
+ override Event getEvent ( ) { result = event }
261
285
}
262
286
263
287
/**
@@ -273,6 +297,8 @@ class DornyPathsFilterSource extends RemoteFlowSource {
273
297
}
274
298
275
299
override string getSourceType ( ) { result = "filename" }
300
+
301
+ override Event getEvent ( ) { result = this .asExpr ( ) .getATriggerEvent ( ) }
276
302
}
277
303
278
304
/**
@@ -294,6 +320,8 @@ class TJActionsChangedFilesSource extends RemoteFlowSource {
294
320
}
295
321
296
322
override string getSourceType ( ) { result = "filename" }
323
+
324
+ override Event getEvent ( ) { result = this .asExpr ( ) .getATriggerEvent ( ) }
297
325
}
298
326
299
327
/**
@@ -315,6 +343,8 @@ class TJActionsVerifyChangedFilesSource extends RemoteFlowSource {
315
343
}
316
344
317
345
override string getSourceType ( ) { result = "filename" }
346
+
347
+ override Event getEvent ( ) { result = this .asExpr ( ) .getATriggerEvent ( ) }
318
348
}
319
349
320
350
class Xt0rtedSlashCommandSource extends RemoteFlowSource {
@@ -327,6 +357,22 @@ class Xt0rtedSlashCommandSource extends RemoteFlowSource {
327
357
}
328
358
329
359
override string getSourceType ( ) { result = "text" }
360
+
361
+ override Event getEvent ( ) { result = this .asExpr ( ) .getATriggerEvent ( ) }
362
+ }
363
+
364
+ class ZenteredIssueFormBodyParserSource extends RemoteFlowSource {
365
+ ZenteredIssueFormBodyParserSource ( ) {
366
+ exists ( UsesStep u |
367
+ u .getCallee ( ) = "zentered/issue-forms-body-parser" and
368
+ not exists ( u .getArgument ( "body" ) ) and
369
+ this .asExpr ( ) = u
370
+ )
371
+ }
372
+
373
+ override string getSourceType ( ) { result = "text" }
374
+
375
+ override Event getEvent ( ) { result = this .asExpr ( ) .getATriggerEvent ( ) }
330
376
}
331
377
332
378
class OctokitRequestActionSource extends RemoteFlowSource {
@@ -348,4 +394,6 @@ class OctokitRequestActionSource extends RemoteFlowSource {
348
394
}
349
395
350
396
override string getSourceType ( ) { result = "text" }
397
+
398
+ override Event getEvent ( ) { result = this .asExpr ( ) .getATriggerEvent ( ) }
351
399
}
0 commit comments