Skip to content

Commit fc94335

Browse files
committed
Added matrix include test
1 parent ce4ce68 commit fc94335

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

actions/ql/lib/codeql/actions/ast/internal/Ast.qll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,7 +1874,14 @@ class MatrixExpressionImpl extends SimpleReferenceExpressionImpl {
18741874
exists(StrategyImpl s, MatrixAccessPathImpl p, ScalarValueImpl v |
18751875
(s = this.getEnclosingJob().getStrategy() or s = this.getEnclosingWorkflow().getStrategy()) and
18761876
p.toString() = fieldAccess and
1877-
resolveMatrixAccessPath(s.getMatrix(), p).getNode(_) = v.getNode() and
1877+
(
1878+
resolveMatrixAccessPath(s.getMatrix(), p).getNode(_) = v.getNode()
1879+
or
1880+
resolveMatrixAccessPath(
1881+
s.getMatrix().lookup("include").(YamlSequence).getElementNode(_).(YamlMappingLikeNode),
1882+
p
1883+
).getNode(_) = v.getNode()
1884+
) and
18781885
// Exclude values containing matrix expressions to avoid recursion
18791886
not exists(MatrixExpressionImpl e | e.getParentNode() = v) and
18801887
result = v.getValue()
@@ -1903,7 +1910,7 @@ class MatrixAccessPathImpl extends TMatrixAccessPathNode {
19031910
}
19041911

19051912
private YamlMappingLikeNode resolveMatrixAccessPath(
1906-
// TODO: support `include` and `exclude` keys
1913+
// TODO: support `exclude` keys
19071914
// https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#expanding-or-adding-matrix-configurations
19081915
YamlMappingLikeNode root, MatrixAccessPathImpl accessPath
19091916
) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
on: issue_comment
2+
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
strategy:
7+
matrix:
8+
ref: ["main"]
9+
include:
10+
- ref: "${{ github.event.comment.body }}"
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
repository: example/example
15+
ref: ${{ matrix.ref }}
16+
# VULNERABLE: an included job checks out a ref controlled by the event payload.
17+
- run: npm install

actions/ql/test/query-tests/Security/CWE-349/CachePoisoningViaDirectCache.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ edges
1717
| .github/workflows/direct_cache5.yml:17:9:21:6 | Uses Step | .github/workflows/direct_cache5.yml:21:9:22:21 | Run Step |
1818
| .github/workflows/direct_cache6.yml:13:9:16:6 | Uses Step | .github/workflows/direct_cache6.yml:16:9:20:6 | Uses Step |
1919
| .github/workflows/direct_cache6.yml:16:9:20:6 | Uses Step | .github/workflows/direct_cache6.yml:20:9:26:46 | Uses Step: cache-pip |
20+
| .github/workflows/dynamic_matrix_include_ref.yml:12:9:17:6 | Uses Step | .github/workflows/dynamic_matrix_include_ref.yml:17:9:17:24 | Run Step |
2021
| .github/workflows/dynamic_matrix_ref.yml:10:9:15:6 | Uses Step | .github/workflows/dynamic_matrix_ref.yml:15:9:15:24 | Run Step |
2122
| .github/workflows/neg_direct_cache1.yml:14:9:17:6 | Uses Step | .github/workflows/neg_direct_cache1.yml:17:9:21:6 | Uses Step |
2223
| .github/workflows/neg_direct_cache1.yml:17:9:21:6 | Uses Step | .github/workflows/neg_direct_cache1.yml:21:9:22:21 | Run Step |

actions/ql/test/query-tests/Security/CWE-349/CachePoisoningViaPoisonableStep.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ edges
2424
| .github/workflows/direct_cache6.yml:13:9:16:6 | Uses Step | .github/workflows/direct_cache6.yml:16:9:20:6 | Uses Step |
2525
| .github/workflows/direct_cache6.yml:15:17:15:57 | github.event.pull_request.head.sha | .github/workflows/direct_cache6.yml:13:9:16:6 | Uses Step |
2626
| .github/workflows/direct_cache6.yml:16:9:20:6 | Uses Step | .github/workflows/direct_cache6.yml:20:9:26:46 | Uses Step: cache-pip |
27+
| .github/workflows/dynamic_matrix_include_ref.yml:12:9:17:6 | Uses Step | .github/workflows/dynamic_matrix_include_ref.yml:17:9:17:24 | Run Step |
28+
| .github/workflows/dynamic_matrix_include_ref.yml:15:17:15:33 | matrix.ref | .github/workflows/dynamic_matrix_include_ref.yml:12:9:17:6 | Uses Step |
2729
| .github/workflows/dynamic_matrix_ref.yml:10:9:15:6 | Uses Step | .github/workflows/dynamic_matrix_ref.yml:15:9:15:24 | Run Step |
2830
| .github/workflows/dynamic_matrix_ref.yml:13:17:13:33 | matrix.ref | .github/workflows/dynamic_matrix_ref.yml:10:9:15:6 | Uses Step |
2931
| .github/workflows/neg_direct_cache1.yml:14:9:17:6 | Uses Step | .github/workflows/neg_direct_cache1.yml:17:9:21:6 | Uses Step |
@@ -69,6 +71,7 @@ edges
6971
| .github/workflows/poisonable_step5.yml:20:17:20:57 | github.event.pull_request.head.ref | .github/workflows/poisonable_step5.yml:17:9:22:6 | Uses Step |
7072
| .github/workflows/poisonable_step5.yml:22:9:24:6 | Uses Step | .github/workflows/poisonable_step5.yml:24:9:28:31 | Uses Step |
7173
#select
74+
| .github/workflows/dynamic_matrix_include_ref.yml:17:9:17:24 | Run Step | .github/workflows/dynamic_matrix_include_ref.yml:15:17:15:33 | matrix.ref | .github/workflows/dynamic_matrix_include_ref.yml:17:9:17:24 | Run Step | Potential cache poisoning in the context of the default branch due to privilege checkout of untrusted code from $@. ($@). | .github/workflows/dynamic_matrix_include_ref.yml:15:17:15:33 | matrix.ref | matrix.ref | .github/workflows/dynamic_matrix_include_ref.yml:1:5:1:17 | issue_comment | issue_comment |
7275
| .github/workflows/dynamic_matrix_ref.yml:15:9:15:24 | Run Step | .github/workflows/dynamic_matrix_ref.yml:13:17:13:33 | matrix.ref | .github/workflows/dynamic_matrix_ref.yml:15:9:15:24 | Run Step | Potential cache poisoning in the context of the default branch due to privilege checkout of untrusted code from $@. ($@). | .github/workflows/dynamic_matrix_ref.yml:13:17:13:33 | matrix.ref | matrix.ref | .github/workflows/dynamic_matrix_ref.yml:1:5:1:17 | issue_comment | issue_comment |
7376
| .github/workflows/poisonable_step1.yml:15:9:17:2 | Run Step | .github/workflows/poisonable_step1.yml:14:17:14:60 | steps.comment-branch.outputs.head_sha | .github/workflows/poisonable_step1.yml:15:9:17:2 | Run Step | Potential cache poisoning in the context of the default branch due to privilege checkout of untrusted code from $@. ($@). | .github/workflows/poisonable_step1.yml:14:17:14:60 | steps.comment-branch.outputs.head_sha | steps.comment-branch.outputs.head_sha | .github/workflows/poisonable_step1.yml:2:3:2:15 | issue_comment | issue_comment |
7477
| .github/workflows/poisonable_step1.yml:26:9:28:2 | Uses Step | .github/workflows/poisonable_step1.yml:25:17:25:60 | steps.comment-branch.outputs.head_sha | .github/workflows/poisonable_step1.yml:26:9:28:2 | Uses Step | Potential cache poisoning in the context of the default branch due to privilege checkout of untrusted code from $@. ($@). | .github/workflows/poisonable_step1.yml:25:17:25:60 | steps.comment-branch.outputs.head_sha | steps.comment-branch.outputs.head_sha | .github/workflows/poisonable_step1.yml:2:3:2:15 | issue_comment | issue_comment |

0 commit comments

Comments
 (0)