@@ -5,23 +5,18 @@ import codeql.actions.dataflow.FlowSources
55private import codeql.actions.security.ArtifactPoisoningQuery
66import codeql.actions.DataFlow
77
8- predicate envPathInjectionFromExprSink ( DataFlow:: Node sink ) {
9- exists ( Expression expr , Run run , string value |
10- Utils:: writeToGitHubPath ( run , value ) and
11- expr = sink .asExpr ( ) and
12- run .getAnScriptExpr ( ) = expr and
13- value .indexOf ( expr .getExpression ( ) ) > 0
14- )
15- }
8+ abstract class EnvPathInjectionSink extends DataFlow:: Node { }
169
17- predicate envPathInjectionFromFileSink ( DataFlow:: Node sink ) {
18- exists ( Run run , UntrustedArtifactDownloadStep step , string value |
19- sink .asExpr ( ) = run and
20- step .getAFollowingStep ( ) = run and
21- Utils:: writeToGitHubPath ( run , value ) and
22- // TODO: add support for other commands like `<`, `jq`, ...
23- value .regexpMatch ( [ "\\$\\(" , "`" ] + [ "cat\\s+" , "<" ] + ".*" + [ "`" , "\\)" ] )
24- )
10+ class EnvPathInjectionFromFileReadSink extends EnvPathInjectionSink {
11+ EnvPathInjectionFromFileReadSink ( ) {
12+ exists ( Run run , UntrustedArtifactDownloadStep step , string value |
13+ this .asExpr ( ) = run .getScriptScalar ( ) and
14+ step .getAFollowingStep ( ) = run and
15+ Utils:: writeToGitHubPath ( run , value ) and
16+ // TODO: add support for other commands like `<`, `jq`, ...
17+ value .regexpMatch ( [ "\\$\\(" , "`" ] + [ "cat\\s+" , "<" ] + ".*" + [ "`" , "\\)" ] )
18+ )
19+ }
2520}
2621
2722/**
@@ -32,26 +27,23 @@ predicate envPathInjectionFromFileSink(DataFlow::Node sink) {
3227 * run: |
3328 * echo "$BODY" >> $GITHUB_PATH
3429 */
35- predicate envPathInjectionFromEnvSink ( DataFlow:: Node sink ) {
36- exists ( Run run , Expression expr , string varname , string value |
37- sink .asExpr ( ) .getInScopeEnvVarExpr ( varname ) = expr and
38- run = sink .asExpr ( ) and
39- Utils:: writeToGitHubPath ( run , value ) and
40- (
41- value = [ "$" + varname , "${" + varname + "}" , "$ENV{" + varname + "}" ]
42- or
43- value .matches ( "$(echo %" ) and value .indexOf ( varname ) > 0
30+ class EnvPathInjectionFromEnvVarSink extends EnvPathInjectionSink {
31+ EnvPathInjectionFromEnvVarSink ( ) {
32+ exists ( Run run , Expression expr , string varname , string value |
33+ this .asExpr ( ) .getInScopeEnvVarExpr ( varname ) = expr and
34+ run .getScriptScalar ( ) = this .asExpr ( ) and
35+ Utils:: writeToGitHubPath ( run , value ) and
36+ (
37+ value .matches ( "%$" + [ "" , "{" , "ENV{" ] + varname + "%" )
38+ or
39+ value .matches ( "$(echo %" ) and value .indexOf ( varname ) > 0
40+ )
4441 )
45- )
42+ }
4643}
4744
48- private class EnvPathInjectionSink extends DataFlow:: Node {
49- EnvPathInjectionSink ( ) {
50- envPathInjectionFromExprSink ( this ) or
51- envPathInjectionFromFileSink ( this ) or
52- envPathInjectionFromEnvSink ( this ) or
53- externallyDefinedSink ( this , "envpath-injection" )
54- }
45+ class EnvPathInjectionFromMaDSink extends EnvPathInjectionSink {
46+ EnvPathInjectionFromMaDSink ( ) { externallyDefinedSink ( this , "envpath-injection" ) }
5547}
5648
5749/**
0 commit comments