Skip to content

Commit 61797e9

Browse files
author
Alvaro Muñoz
committed
Add pull_request-comment-branch head_ref as a source
1 parent 795232e commit 61797e9

10 files changed

+72
-4
lines changed

ql/lib/codeql/actions/security/UntrustedCheckoutQuery.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ class ActionsSHACheckout extends SHACheckoutStep instanceof UsesStep {
133133
or
134134
// 3rd party actions returning the PR head sha/ref
135135
exists(UsesStep step |
136-
step.getCallee() = ["eficode/resolve-pr-refs", "xt0rted/pull-request-comment-branch"] and
136+
step.getCallee() =
137+
[
138+
"eficode/resolve-pr-refs", "xt0rted/pull-request-comment-branch",
139+
"alessbell/pull-request-comment-branch", "gotson/pull-request-comment-branch"
140+
] and
137141
this.getArgument("ref").regexpMatch(".*head_sha.*") and
138142
DataFlow::hasLocalFlowExpr(step, this.getArgumentExpr("ref"))
139143
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extensions:
2+
- addsTo:
3+
pack: github/actions-all
4+
extensible: actionsSourceModel
5+
data:
6+
- ["alessbell/pull-request-comment-branch", "*", "output.head_ref", "branch", "manual"]
7+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extensions:
2+
- addsTo:
3+
pack: github/actions-all
4+
extensible: actionsSourceModel
5+
data:
6+
- ["eficode/resolve-pr-refs", "*", "output.head_ref", "branch", "manual"]
7+
8+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extensions:
2+
- addsTo:
3+
pack: github/actions-all
4+
extensible: actionsSourceModel
5+
data:
6+
- ["gotson/pull-request-comment-branch", "*", "output.head_ref", "branch", "manual"]
7+

ql/lib/ext/manual/tj-actions_branch-names.model.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,3 @@ extensions:
66
# https://github.com/tj-actions/branch-names
77
- ["tj-actions/branch-names", "*", "output.current_branch", "branch", "manual"]
88
- ["tj-actions/branch-names", "*", "output.head_ref_branch", "branch", "manual"]
9-
- ["tj-actions/branch-names", "*", "output.ref_branch", "branch", "manual"]
10-
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extensions:
2+
- addsTo:
3+
pack: github/actions-all
4+
extensible: actionsSourceModel
5+
data:
6+
- ["xt0rted/pull-request-comment-branch", "*", "output.head_ref", "branch", "manual"]
7+

ql/test/library-tests/test.expected

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,12 +619,15 @@ scopes
619619
sources
620620
| ahmadnassri/action-changed-files | * | output.files | filename | manual |
621621
| ahmadnassri/action-changed-files | * | output.json | json | manual |
622+
| alessbell/pull-request-comment-branch | * | output.head_ref | branch | manual |
622623
| amannn/action-semantic-pull-request | * | output.error_message | text | manual |
623624
| cypress-io/github-action | * | env.GH_BRANCH | branch | manual |
624625
| dawidd6/action-download-artifact | * | output.artifacts | artifact | manual |
626+
| eficode/resolve-pr-refs | * | output.head_ref | branch | manual |
625627
| franzdiebold/github-env-vars-action | * | output.CI_PR_DESCRIPTION | text | manual |
626628
| franzdiebold/github-env-vars-action | * | output.CI_PR_TITLE | title | manual |
627629
| googlecloudplatform/magic-modules | * | output.changed-files | filename | manual |
630+
| gotson/pull-request-comment-branch | * | output.head_ref | branch | manual |
628631
| jitterbit/get-changed-files | * | output.added | filename | manual |
629632
| jitterbit/get-changed-files | * | output.added_modified | filename | manual |
630633
| jitterbit/get-changed-files | * | output.all | filename | manual |
@@ -639,12 +642,12 @@ sources
639642
| redhat-plumbers-in-action/download-artifact | * | output.* | artifact | manual |
640643
| tj-actions/branch-names | * | output.current_branch | branch | manual |
641644
| tj-actions/branch-names | * | output.head_ref_branch | branch | manual |
642-
| tj-actions/branch-names | * | output.ref_branch | branch | manual |
643645
| trilom/file-changes-action | * | output.files | filename | manual |
644646
| trilom/file-changes-action | * | output.files_added | filename | manual |
645647
| trilom/file-changes-action | * | output.files_modified | filename | manual |
646648
| trilom/file-changes-action | * | output.files_removed | filename | manual |
647649
| tzkhan/pr-update-action | * | output.headMatch | branch | manual |
650+
| xt0rted/pull-request-comment-branch | * | output.head_ref | branch | manual |
648651
| xt0rted/slash-command-action | * | output.command-arguments | text | manual |
649652
summaries
650653
| akhileshns/heroku-deploy | * | input.branch | output.status | taint | manual |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Test
2+
on: issue_comment
3+
permissions: write-all
4+
jobs:
5+
test:
6+
name: Test
7+
runs-on: ubuntu-latest
8+
steps:
9+
- id: comment-branch
10+
uses: xt0rted/pull-request-comment-branch@v2
11+
with:
12+
repo_token: ${{ github.token }}
13+
- id: refs
14+
uses: eficode/resolve-pr-refs@main
15+
with:
16+
token: ${{ github.token }}
17+
- run: |
18+
echo "HEAD_REF1 from PR: ${{ steps.comment-branch.outputs.head_ref }}"
19+
- run: |
20+
echo "HEAD_REF2 from PR: ${{ steps.refs.outputs.head_ref }}"

ql/test/query-tests/Security/CWE-094/CodeInjectionCritical.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ edges
6565
| .github/workflows/test3.yml:11:7:12:4 | Job outputs node [payload] | .github/workflows/test3.yml:60:27:60:66 | needs.parse-issue.outputs.payload | provenance | |
6666
| .github/workflows/test3.yml:11:17:11:70 | steps.issue_body_parser_request.outputs.payload | .github/workflows/test3.yml:11:7:12:4 | Job outputs node [payload] | provenance | |
6767
| .github/workflows/test3.yml:13:9:21:2 | Uses Step: issue_body_parser_request | .github/workflows/test3.yml:11:17:11:70 | steps.issue_body_parser_request.outputs.payload | provenance | |
68+
| .github/workflows/test7.yml:9:9:13:6 | Uses Step: comment-branch | .github/workflows/test7.yml:18:37:18:80 | steps.comment-branch.outputs.head_ref | provenance | |
69+
| .github/workflows/test7.yml:13:9:17:6 | Uses Step: refs | .github/workflows/test7.yml:20:37:20:70 | steps.refs.outputs.head_ref | provenance | |
6870
| .github/workflows/test.yml:8:7:10:4 | Job outputs node [job_output] | .github/workflows/test.yml:49:20:49:56 | needs.job1.outputs['job_output'] | provenance | |
6971
| .github/workflows/test.yml:8:20:8:50 | steps.step5.outputs.MSG5 | .github/workflows/test.yml:8:7:10:4 | Job outputs node [job_output] | provenance | |
7072
| .github/workflows/test.yml:12:9:18:6 | Uses Step: step0 [value] | .github/workflows/test.yml:20:18:20:48 | steps.step0.outputs.value | provenance | |
@@ -243,6 +245,10 @@ nodes
243245
| .github/workflows/test4.yml:19:21:19:53 | toJSON(github.event.issue) | semmle.label | toJSON(github.event.issue) |
244246
| .github/workflows/test4.yml:27:21:27:47 | toJSON(github.event) | semmle.label | toJSON(github.event) |
245247
| .github/workflows/test5.yml:12:21:12:64 | toJSON(github.event.comment.body).foo | semmle.label | toJSON(github.event.comment.body).foo |
248+
| .github/workflows/test7.yml:9:9:13:6 | Uses Step: comment-branch | semmle.label | Uses Step: comment-branch |
249+
| .github/workflows/test7.yml:13:9:17:6 | Uses Step: refs | semmle.label | Uses Step: refs |
250+
| .github/workflows/test7.yml:18:37:18:80 | steps.comment-branch.outputs.head_ref | semmle.label | steps.comment-branch.outputs.head_ref |
251+
| .github/workflows/test7.yml:20:37:20:70 | steps.refs.outputs.head_ref | semmle.label | steps.refs.outputs.head_ref |
246252
| .github/workflows/test.yml:8:7:10:4 | Job outputs node [job_output] | semmle.label | Job outputs node [job_output] |
247253
| .github/workflows/test.yml:8:20:8:50 | steps.step5.outputs.MSG5 | semmle.label | steps.step5.outputs.MSG5 |
248254
| .github/workflows/test.yml:12:9:18:6 | Uses Step: step0 [value] | semmle.label | Uses Step: step0 [value] |
@@ -340,6 +346,8 @@ subpaths
340346
| .github/workflows/test4.yml:19:21:19:53 | toJSON(github.event.issue) | .github/workflows/test4.yml:19:21:19:53 | toJSON(github.event.issue) | .github/workflows/test4.yml:19:21:19:53 | toJSON(github.event.issue) | Potential code injection in $@, which may be controlled by an external user. | .github/workflows/test4.yml:19:21:19:53 | toJSON(github.event.issue) | ${{ toJSON(github.event.issue) }} |
341347
| .github/workflows/test4.yml:27:21:27:47 | toJSON(github.event) | .github/workflows/test4.yml:27:21:27:47 | toJSON(github.event) | .github/workflows/test4.yml:27:21:27:47 | toJSON(github.event) | Potential code injection in $@, which may be controlled by an external user. | .github/workflows/test4.yml:27:21:27:47 | toJSON(github.event) | ${{ toJSON(github.event) }} |
342348
| .github/workflows/test5.yml:12:21:12:64 | toJSON(github.event.comment.body).foo | .github/workflows/test5.yml:12:21:12:64 | toJSON(github.event.comment.body).foo | .github/workflows/test5.yml:12:21:12:64 | toJSON(github.event.comment.body).foo | Potential code injection in $@, which may be controlled by an external user. | .github/workflows/test5.yml:12:21:12:64 | toJSON(github.event.comment.body).foo | ${{ toJSON(github.event.comment.body).foo }} |
349+
| .github/workflows/test7.yml:18:37:18:80 | steps.comment-branch.outputs.head_ref | .github/workflows/test7.yml:9:9:13:6 | Uses Step: comment-branch | .github/workflows/test7.yml:18:37:18:80 | steps.comment-branch.outputs.head_ref | Potential code injection in $@, which may be controlled by an external user. | .github/workflows/test7.yml:18:37:18:80 | steps.comment-branch.outputs.head_ref | ${{ steps.comment-branch.outputs.head_ref }} |
350+
| .github/workflows/test7.yml:20:37:20:70 | steps.refs.outputs.head_ref | .github/workflows/test7.yml:13:9:17:6 | Uses Step: refs | .github/workflows/test7.yml:20:37:20:70 | steps.refs.outputs.head_ref | Potential code injection in $@, which may be controlled by an external user. | .github/workflows/test7.yml:20:37:20:70 | steps.refs.outputs.head_ref | ${{ steps.refs.outputs.head_ref }} |
343351
| .github/workflows/workflow_run.yml:9:19:9:64 | github.event.workflow_run.display_title | .github/workflows/workflow_run.yml:9:19:9:64 | github.event.workflow_run.display_title | .github/workflows/workflow_run.yml:9:19:9:64 | github.event.workflow_run.display_title | Potential code injection in $@, which may be controlled by an external user. | .github/workflows/workflow_run.yml:9:19:9:64 | github.event.workflow_run.display_title | ${{ github.event.workflow_run.display_title }} |
344352
| .github/workflows/workflow_run.yml:10:19:10:70 | github.event.workflow_run.head_commit.message | .github/workflows/workflow_run.yml:10:19:10:70 | github.event.workflow_run.head_commit.message | .github/workflows/workflow_run.yml:10:19:10:70 | github.event.workflow_run.head_commit.message | Potential code injection in $@, which may be controlled by an external user. | .github/workflows/workflow_run.yml:10:19:10:70 | github.event.workflow_run.head_commit.message | ${{ github.event.workflow_run.head_commit.message }} |
345353
| .github/workflows/workflow_run.yml:11:19:11:75 | github.event.workflow_run.head_commit.author.email | .github/workflows/workflow_run.yml:11:19:11:75 | github.event.workflow_run.head_commit.author.email | .github/workflows/workflow_run.yml:11:19:11:75 | github.event.workflow_run.head_commit.author.email | Potential code injection in $@, which may be controlled by an external user. | .github/workflows/workflow_run.yml:11:19:11:75 | github.event.workflow_run.head_commit.author.email | ${{ github.event.workflow_run.head_commit.author.email }} |

ql/test/query-tests/Security/CWE-094/CodeInjectionMedium.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ edges
6565
| .github/workflows/test3.yml:11:7:12:4 | Job outputs node [payload] | .github/workflows/test3.yml:60:27:60:66 | needs.parse-issue.outputs.payload | provenance | |
6666
| .github/workflows/test3.yml:11:17:11:70 | steps.issue_body_parser_request.outputs.payload | .github/workflows/test3.yml:11:7:12:4 | Job outputs node [payload] | provenance | |
6767
| .github/workflows/test3.yml:13:9:21:2 | Uses Step: issue_body_parser_request | .github/workflows/test3.yml:11:17:11:70 | steps.issue_body_parser_request.outputs.payload | provenance | |
68+
| .github/workflows/test7.yml:9:9:13:6 | Uses Step: comment-branch | .github/workflows/test7.yml:18:37:18:80 | steps.comment-branch.outputs.head_ref | provenance | |
69+
| .github/workflows/test7.yml:13:9:17:6 | Uses Step: refs | .github/workflows/test7.yml:20:37:20:70 | steps.refs.outputs.head_ref | provenance | |
6870
| .github/workflows/test.yml:8:7:10:4 | Job outputs node [job_output] | .github/workflows/test.yml:49:20:49:56 | needs.job1.outputs['job_output'] | provenance | |
6971
| .github/workflows/test.yml:8:20:8:50 | steps.step5.outputs.MSG5 | .github/workflows/test.yml:8:7:10:4 | Job outputs node [job_output] | provenance | |
7072
| .github/workflows/test.yml:12:9:18:6 | Uses Step: step0 [value] | .github/workflows/test.yml:20:18:20:48 | steps.step0.outputs.value | provenance | |
@@ -243,6 +245,10 @@ nodes
243245
| .github/workflows/test4.yml:19:21:19:53 | toJSON(github.event.issue) | semmle.label | toJSON(github.event.issue) |
244246
| .github/workflows/test4.yml:27:21:27:47 | toJSON(github.event) | semmle.label | toJSON(github.event) |
245247
| .github/workflows/test5.yml:12:21:12:64 | toJSON(github.event.comment.body).foo | semmle.label | toJSON(github.event.comment.body).foo |
248+
| .github/workflows/test7.yml:9:9:13:6 | Uses Step: comment-branch | semmle.label | Uses Step: comment-branch |
249+
| .github/workflows/test7.yml:13:9:17:6 | Uses Step: refs | semmle.label | Uses Step: refs |
250+
| .github/workflows/test7.yml:18:37:18:80 | steps.comment-branch.outputs.head_ref | semmle.label | steps.comment-branch.outputs.head_ref |
251+
| .github/workflows/test7.yml:20:37:20:70 | steps.refs.outputs.head_ref | semmle.label | steps.refs.outputs.head_ref |
246252
| .github/workflows/test.yml:8:7:10:4 | Job outputs node [job_output] | semmle.label | Job outputs node [job_output] |
247253
| .github/workflows/test.yml:8:20:8:50 | steps.step5.outputs.MSG5 | semmle.label | steps.step5.outputs.MSG5 |
248254
| .github/workflows/test.yml:12:9:18:6 | Uses Step: step0 [value] | semmle.label | Uses Step: step0 [value] |

0 commit comments

Comments
 (0)