15
15
import javascript
16
16
import semmle.javascript.Actions
17
17
18
+ /**
19
+ * A `script:` field within an Actions `with:` specific to `actions/github-script` action.
20
+ *
21
+ * For example:
22
+ * ```
23
+ * uses: actions/github-script@v3
24
+ * with:
25
+ * script: console.log('${{ github.event.pull_request.head.sha }}')
26
+ * ```
27
+ */
28
+ class GitHubScript extends YamlNode , YamlString {
29
+ GitHubScriptWith with ;
30
+
31
+ GitHubScript ( ) { with .lookup ( "script" ) = this }
32
+
33
+ /** Gets the `with` field this field belongs to. */
34
+ GitHubScriptWith getWith ( ) { result = with }
35
+ }
36
+
37
+ /**
38
+ * A step that uses `actions/github-script` action.
39
+ */
40
+ class GitHubScriptStep extends Actions:: Step {
41
+ GitHubScriptStep ( ) { this .getUses ( ) .getGitHubRepository ( ) = "actions/github-script" }
42
+ }
43
+
44
+ /**
45
+ * A `with:` field sibling to `uses: actions/github-script`.
46
+ */
47
+ class GitHubScriptWith extends YamlNode , YamlMapping {
48
+ GitHubScriptStep step ;
49
+
50
+ GitHubScriptWith ( ) { step .lookup ( "with" ) = this }
51
+
52
+ /** Gets the step this field belongs to. */
53
+ GitHubScriptStep getStep ( ) { result = step }
54
+ }
55
+
18
56
bindingset [ context]
19
57
private predicate isExternalUserControlledIssue ( string context ) {
20
58
context .regexpMatch ( "\\bgithub\\s*\\.\\s*event\\s*\\.\\s*issue\\s*\\.\\s*title\\b" ) or
@@ -133,7 +171,7 @@ predicate isRunInjectable(Actions::Run run, string injection, string context) {
133
171
* Holds if the `actions/github-script` contains any expression interpolation `${{ e }}`.
134
172
* Sets `context` to the initial untrusted value assignment in case of `${{ env... }}` interpolation
135
173
*/
136
- predicate isScriptInjectable ( Actions :: GitHubScript script , string injection , string context ) {
174
+ predicate isScriptInjectable ( GitHubScript script , string injection , string context ) {
137
175
Actions:: getASimpleReferenceExpression ( script ) = injection and
138
176
(
139
177
injection = context
@@ -152,7 +190,7 @@ YamlNode getInjectableCompositeActionNode(Actions::Runs runs, string injection,
152
190
run .getStep ( ) .getRuns ( ) = runs
153
191
)
154
192
or
155
- exists ( Actions :: GitHubScript script |
193
+ exists ( GitHubScript script |
156
194
isScriptInjectable ( script , injection , context ) and
157
195
result = script and
158
196
script .getWith ( ) .getStep ( ) .getRuns ( ) = runs
@@ -169,7 +207,7 @@ YamlNode getInjectableWorkflowNode(Actions::On on, string injection, string cont
169
207
run .getStep ( ) .getJob ( ) .getWorkflow ( ) .getOn ( ) = on
170
208
)
171
209
or
172
- exists ( Actions :: GitHubScript script |
210
+ exists ( GitHubScript script |
173
211
isScriptInjectable ( script , injection , context ) and
174
212
result = script and
175
213
script .getWith ( ) .getStep ( ) .getJob ( ) .getWorkflow ( ) .getOn ( ) = on
0 commit comments