@@ -308,19 +308,22 @@ class CompositeActionImpl extends AstNodeImpl, TCompositeAction {
308
308
LocalJobImpl getACallerJob ( ) { result = this .getACallerStep ( ) .getEnclosingJob ( ) }
309
309
310
310
UsesStepImpl getACallerStep ( ) {
311
- exists ( UsesStepImpl caller , string gwf_path , string path |
312
- // the workflow files may not be rooted in the parent directory of .github/workflows
313
- // extract the offset so we can remove it from the action path
314
- gwf_path =
315
- caller
316
- .getLocation ( )
311
+ exists ( DataFlow:: CallNode call |
312
+ call .getCalleeNode ( ) = this and
313
+ result = call .getCfgNode ( ) .getAstNode ( )
314
+ )
315
+ }
316
+
317
+ string getResolvedPath ( ) {
318
+ result =
319
+ [ "" , "./" ] +
320
+ this .getLocation ( )
317
321
.getFile ( )
318
322
.getRelativePath ( )
319
- .prefix ( caller .getLocation ( ) .getFile ( ) .getRelativePath ( ) .indexOf ( ".github/workflows/" ) ) and
320
- path = this .getLocation ( ) .getFile ( ) .getRelativePath ( ) .replaceAll ( gwf_path , "" ) and
321
- caller .getCallee ( ) = [ "" , "./" ] + path .prefix ( path .indexOf ( [ "/action.yml" , "/action.yaml" ] ) ) and
322
- result = caller
323
- )
323
+ .replaceAll ( getRepoRoot ( ) , "" )
324
+ .replaceAll ( "/action.yml" , "" )
325
+ .replaceAll ( "/action.yaml" , "" )
326
+ .replaceAll ( ".github/reusable_workflows/" , "" )
324
327
}
325
328
326
329
private predicate hasExplicitSecretAccess ( ) {
@@ -352,6 +355,8 @@ class CompositeActionImpl extends AstNodeImpl, TCompositeAction {
352
355
)
353
356
}
354
357
358
+ EventImpl getATriggerEvent ( ) { result = this .getACallerJob ( ) .getATriggerEvent ( ) }
359
+
355
360
/** Holds if the action is privileged and externally triggerable. */
356
361
predicate isPrivilegedExternallyTriggerable ( ) {
357
362
// the action is externally triggerable
@@ -447,6 +452,16 @@ class ReusableWorkflowImpl extends AstNodeImpl, WorkflowImpl {
447
452
result = call .getCfgNode ( ) .getAstNode ( )
448
453
)
449
454
}
455
+
456
+ string getResolvedPath ( ) {
457
+ result =
458
+ [ "" , "./" ] +
459
+ this .getLocation ( )
460
+ .getFile ( )
461
+ .getRelativePath ( )
462
+ .replaceAll ( getRepoRoot ( ) , "" )
463
+ .replaceAll ( ".github/reusable_workflows/" , "" )
464
+ }
450
465
}
451
466
452
467
class InputsImpl extends AstNodeImpl , TInputsNode {
@@ -1229,15 +1244,6 @@ abstract class UsesImpl extends AstNodeImpl {
1229
1244
}
1230
1245
}
1231
1246
1232
- /**
1233
- * Gets a regular expression that parses an `owner/repo@version` reference within a `uses` field in an Actions job step.
1234
- * The capture groups are:
1235
- * 1: The owner of the repository where the Action comes from, e.g. `actions` in `actions/checkout@v2`
1236
- * 2: The name of the repository where the Action comes from, e.g. `checkout` in `actions/checkout@v2`.
1237
- * 3: The version reference used when checking out the Action, e.g. `v2` in `actions/checkout@v2`.
1238
- */
1239
- private string usesParser ( ) { result = "([^/]+)/([^/@]+)@(.+)" }
1240
-
1241
1247
/** A Uses step represents a call to an action that is defined in a GitHub repository. */
1242
1248
class UsesStepImpl extends StepImpl , UsesImpl {
1243
1249
YamlScalar u ;
@@ -1249,19 +1255,14 @@ class UsesStepImpl extends StepImpl, UsesImpl {
1249
1255
/** Gets the owner and name of the repository where the Action comes from, e.g. `actions/checkout` in `actions/checkout@v2`. */
1250
1256
override string getCallee ( ) {
1251
1257
if u .getValue ( ) .indexOf ( "@" ) > 0
1252
- then
1253
- result =
1254
- (
1255
- u .getValue ( ) .regexpCapture ( usesParser ( ) , 1 ) + "/" +
1256
- u .getValue ( ) .regexpCapture ( usesParser ( ) , 2 )
1257
- ) .toLowerCase ( )
1258
+ then result = u .getValue ( ) .prefix ( u .getValue ( ) .indexOf ( "@" ) )
1258
1259
else result = u .getValue ( )
1259
1260
}
1260
1261
1261
1262
override ScalarValueImpl getCalleeNode ( ) { result .getNode ( ) = u }
1262
1263
1263
1264
/** Gets the version reference used when checking out the Action, e.g. `v2` in `actions/checkout@v2`. */
1264
- override string getVersion ( ) { result = u .getValue ( ) .regexpCapture ( usesParser ( ) , 3 ) }
1265
+ override string getVersion ( ) { result = u .getValue ( ) .suffix ( u . getValue ( ) . indexOf ( "@" ) + 1 ) }
1265
1266
1266
1267
override string toString ( ) {
1267
1268
if exists ( this .getId ( ) ) then result = "Uses Step: " + this .getId ( ) else result = "Uses Step"
0 commit comments