-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgithub-script-injection.yaml
More file actions
77 lines (76 loc) · 3.44 KB
/
Copy pathgithub-script-injection.yaml
File metadata and controls
77 lines (76 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
rules:
- id: github-script-injection
languages:
- yaml
severity: ERROR
metadata:
tags: [security]
shortDescription: Risk of code injection when using `github` context data in `actions/github-script`.
confidence: HIGH
help: |
## Remediation
Instead of using variable interpolation with `github` context data directly in the script,
use an intermediate environment variable:
1. Store the data using `env:`
2. Reference the environment variable in the script using double-quotes: "$ENVVAR"
category: security
cwe:
- "CWE-94: Improper Control of Generation of Code ('Code Injection')"
owasp:
- A03:2021 - Injection
references:
- https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#understanding-the-risk-of-script-injections
- https://securitylab.github.com/research/github-actions-untrusted-input/
- https://github.com/actions/github-script
technology:
- github-actions
cwe2022-top25: true
subcategory:
- vuln
likelihood: HIGH
impact: HIGH
message: >-
Using variable interpolation `${{...}}` with `github` context data in a `actions/github-script`'s
`script:` step could allow an attacker to inject their own code into the runner. This would allow them to steal secrets and code. `github` context
data can have arbitrary user input and should be treated as untrusted. Instead, use an intermediate environment
variable with `env:` to store the data and use the environment variable in the `run:` script. Be sure to use double-quotes
the environment variable, like this: "$ENVVAR".
patterns:
- pattern-inside: 'steps: [...]'
- pattern-inside: |
uses: $ACTION
...
- pattern-inside: |
with:
...
script: ...
...
- pattern: 'script: $SHELL'
- metavariable-regex:
metavariable: $ACTION
regex: actions/github-script@.*
- metavariable-pattern:
language: generic
metavariable: $SHELL
patterns:
- pattern-either:
- pattern: ${{ github.event.issue.title }}
- pattern: ${{ github.event.issue.body }}
- pattern: ${{ github.event.pull_request.title }}
- pattern: ${{ github.event.pull_request.body }}
- pattern: ${{ github.event.comment.body }}
- pattern: ${{ github.event.review.body }}
- pattern: ${{ github.event.review_comment.body }}
- pattern: ${{ github.event.pages. ... .page_name}}
- pattern: ${{ github.event.head_commit.message }}
- pattern: ${{ github.event.head_commit.author.email }}
- pattern: ${{ github.event.head_commit.author.name }}
- pattern: ${{ github.event.commits ... .author.email }}
- pattern: ${{ github.event.commits ... .author.name }}
- pattern: ${{ github.event.pull_request.head.ref }}
- pattern: ${{ github.event.pull_request.head.label }}
- pattern: ${{ github.event.pull_request.head.repo.default_branch }}
- pattern: ${{ github.head_ref }}
- pattern: ${{ github.event.inputs ... }}
- pattern: ${{ github.event.discussion.title }}
- pattern: ${{ github.event.discussion.body }}