Skip to content

Commit e9dee3a

Browse files
committed
Move actions/github-script out of Actions.qll
1 parent 599ec5a commit e9dee3a

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

javascript/ql/lib/semmle/javascript/Actions.qll

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -359,44 +359,6 @@ module Actions {
359359
bindingset[name]
360360
string getEnvName(string name) { result = name.regexpCapture("env\\.([A-Za-z0-9_]+)", 1) }
361361

362-
/**
363-
* A `script:` field within an Actions `with:` specific to `actions/github-script` action.
364-
*
365-
* For example:
366-
* ```
367-
* uses: actions/github-script@v3
368-
* with:
369-
* script: console.log('${{ github.event.pull_request.head.sha }}')
370-
* ```
371-
*/
372-
class GitHubScript extends YamlNode, YamlString {
373-
GitHubScriptWith with;
374-
375-
GitHubScript() { with.lookup("script") = this }
376-
377-
/** Gets the `with` field this field belongs to. */
378-
GitHubScriptWith getWith() { result = with }
379-
}
380-
381-
/**
382-
* A step that uses `actions/github-script` action.
383-
*/
384-
class GitHubScriptStep extends Step {
385-
GitHubScriptStep() { this.getUses().getGitHubRepository() = "actions/github-script" }
386-
}
387-
388-
/**
389-
* A `with:` field sibling to `uses: actions/github-script`.
390-
*/
391-
class GitHubScriptWith extends YamlNode, YamlMapping {
392-
GitHubScriptStep step;
393-
394-
GitHubScriptWith() { step.lookup("with") = this }
395-
396-
/** Gets the step this field belongs to. */
397-
GitHubScriptStep getStep() { result = step }
398-
}
399-
400362
/**
401363
* A `run` field within an Actions job step, which runs command-line programs using an operating system shell.
402364
* See https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsrun.

javascript/ql/src/Security/CWE-094/ExpressionInjection.ql

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,44 @@
1515
import javascript
1616
import semmle.javascript.Actions
1717

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+
1856
bindingset[context]
1957
private predicate isExternalUserControlledIssue(string context) {
2058
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) {
133171
* Holds if the `actions/github-script` contains any expression interpolation `${{ e }}`.
134172
* Sets `context` to the initial untrusted value assignment in case of `${{ env... }}` interpolation
135173
*/
136-
predicate isScriptInjectable(Actions::GitHubScript script, string injection, string context) {
174+
predicate isScriptInjectable(GitHubScript script, string injection, string context) {
137175
Actions::getASimpleReferenceExpression(script) = injection and
138176
(
139177
injection = context
@@ -152,7 +190,7 @@ YamlNode getInjectableCompositeActionNode(Actions::Runs runs, string injection,
152190
run.getStep().getRuns() = runs
153191
)
154192
or
155-
exists(Actions::GitHubScript script |
193+
exists(GitHubScript script |
156194
isScriptInjectable(script, injection, context) and
157195
result = script and
158196
script.getWith().getStep().getRuns() = runs
@@ -169,7 +207,7 @@ YamlNode getInjectableWorkflowNode(Actions::On on, string injection, string cont
169207
run.getStep().getJob().getWorkflow().getOn() = on
170208
)
171209
or
172-
exists(Actions::GitHubScript script |
210+
exists(GitHubScript script |
173211
isScriptInjectable(script, injection, context) and
174212
result = script and
175213
script.getWith().getStep().getJob().getWorkflow().getOn() = on

0 commit comments

Comments
 (0)