Skip to content

Commit 90b3c96

Browse files
authored
Merge pull request #74 from github/docs/help_files
docs/help files
2 parents 23754b6 + d602726 commit 90b3c96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1783
-31
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Environment Path Injection
2+
3+
## Description
4+
5+
GitHub Actions allow to define the system PATH variable by writing to a file pointed to by the `GITHUB_PATH` environment variable. Writing to this file appends a directory to the system PATH variable and automatically makes it available to all subsequent actions in the current job.
6+
7+
E.g.:
8+
9+
```bash
10+
echo "$HOME/.local/bin" >> $GITHUB_PATH
11+
```
12+
13+
If an attacker can control the contents of the system PATH, they are able to influence what commands are run in subsequent steps of the same job.
14+
15+
## Recommendations
16+
17+
Do not allow untrusted data to influence the system PATH: Avoid using untrusted data sources (e.g., artifact content) to define the system PATH.
18+
19+
## Examples
20+
21+
### Incorrect Usage
22+
23+
Consider the following basic setup where an environment variable `PATH` is set:
24+
25+
```yaml
26+
steps:
27+
- name: Set the path
28+
env:
29+
BODY: ${{ github.event.comment.body }}
30+
run: |
31+
PATH=$(echo "$BODY" | grep -oP 'system path: \K\S+')
32+
echo "$PATH" >> "$GITHUB_PATH"
33+
```
34+
35+
If an attacker can manipulate the value being set, such as through artifact downloads or user inputs, they can potentially change the system PATH and get arbitrary command execution in subsequent steps.
36+
37+
## References
38+
39+
- [Workflow commands for GitHub Actions](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Environment Path Injection
2+
3+
## Description
4+
5+
GitHub Actions allow to define the system PATH variable by writing to a file pointed to by the `GITHUB_PATH` environment variable. Writing to this file appends a directory to the system PATH variable and automatically makes it available to all subsequent actions in the current job.
6+
7+
E.g.:
8+
9+
```bash
10+
echo "$HOME/.local/bin" >> $GITHUB_PATH
11+
```
12+
13+
If an attacker can control the contents of the system PATH, they are able to influence what commands are run in subsequent steps of the same job.
14+
15+
## Recommendations
16+
17+
Do not allow untrusted data to influence the system PATH: Avoid using untrusted data sources (e.g., artifact content) to define the system PATH.
18+
19+
## Examples
20+
21+
### Incorrect Usage
22+
23+
Consider the following basic setup where an environment variable `PATH` is set:
24+
25+
```yaml
26+
steps:
27+
- name: Set the path
28+
env:
29+
BODY: ${{ github.event.comment.body }}
30+
run: |
31+
PATH=$(echo "$BODY" | grep -oP 'system path: \K\S+')
32+
echo "$PATH" >> "$GITHUB_PATH"
33+
```
34+
35+
If an attacker can manipulate the value being set, such as through artifact downloads or user inputs, they can potentially change the system PATH and get arbitrary command execution in subsequent steps.
36+
37+
## References
38+
39+
- [Workflow commands for GitHub Actions](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions)
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Environment Variable Injection
2+
3+
## Description
4+
5+
GitHub Actions allow to define environment variables by writing to a file pointed to by the `GITHUB_ENV` environment variable:
6+
7+
This file contains lines in the `KEY=VALUE` format:
8+
9+
```bash
10+
steps:
11+
- name: Set the value
12+
id: step_one
13+
run: |
14+
echo "action_state=yellow" >> "$GITHUB_ENV"
15+
```
16+
17+
It is also possible to define multiline variables by using the [following construct](https://en.wikipedia.org/wiki/Here_document):
18+
19+
```
20+
KEY<<{delimiter}
21+
VALUE
22+
VALUE
23+
{delimiter}
24+
```
25+
26+
```bash
27+
steps:
28+
- name: Set the value in bash
29+
id: step_one
30+
run: |
31+
{
32+
echo 'JSON_RESPONSE<<EOF'
33+
curl https://example.com
34+
echo EOF
35+
} >> "$GITHUB_ENV"
36+
```
37+
38+
If an attacker can control the values assigned to environment variables and there is no sanitization in place, the attacker will be able to inject additional variables by injecting new lines or `{delimiters}`.
39+
40+
## Recommendations
41+
42+
1. **Do not allow untrusted data to influence environment variables**:
43+
44+
- Avoid using untrusted data sources (e.g., artifact content) to define environment variables.
45+
- Validate and sanitize all inputs before using them in environment settings.
46+
47+
2. **Do not allow new lines when defining single line environment variables**:
48+
49+
- `echo "BODY=$(echo "$BODY" | tr -d '\n')" >> "$GITHUB_ENV"`
50+
51+
3. **Use unique identifiers when defining multi line environment variables**:
52+
53+
```bash
54+
steps:
55+
- name: Set the value in bash
56+
id: step_one
57+
run: |
58+
# Generate a UUID
59+
UUID=$(uuidgen)
60+
{
61+
echo "JSON_RESPONSE<<EOF$UUID"
62+
curl https://example.com
63+
echo "EOF$UUID"
64+
} >> "$GITHUB_ENV"
65+
```
66+
67+
## Examples
68+
69+
### Example of Vulnerability
70+
71+
Consider the following basic setup where an environment variable `MYVAR` is set and used in subsequent steps:
72+
73+
```yaml
74+
steps:
75+
- name: Set the value
76+
id: step_one
77+
env:
78+
BODY: ${{ github.event.comment.body }}
79+
run: |
80+
REPLACED=$(echo "$BODY" | sed 's/FOO/BAR/g')
81+
echo "MYVAR=$REPLACED" >> "$GITHUB_ENV"
82+
```
83+
84+
If an attacker can manipulate the value being set, such as through artifact downloads or user inputs, the attacker can potentially inject new environment variables. For example, they could write an issue comment like:
85+
86+
```text
87+
FOO
88+
NEW_ENV_VAR=MALICIOUS_VALUE
89+
```
90+
91+
Likewise, if the attacker controls a file in the GitHub Actions Runner's workspace (eg: the workflow checkouts untrusted code or downloads an untrusted artifact) and the contents of that file are assigned to an environment variable such as:
92+
93+
```bash
94+
- run: |
95+
PR_NUMBER=$(cat pr-number.txt)
96+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
97+
```
98+
99+
An attacker could craft a malicious artifact that writes dangerous environment variables:
100+
101+
```bash
102+
- run: |
103+
echo -e "666\nNEW_ENV_VAR=MALICIOUS_VALUE" > pr-number.txt
104+
- uses: actions/upload-artifact@v4
105+
with:
106+
name: pr-number
107+
path: ./pr-number.txt
108+
```
109+
110+
### Exploitation
111+
112+
An attacker is be able to run arbitrary code by injecting environment variables such as `LD_PRELOAD`, `BASH_ENV`, etc.
113+
114+
## References
115+
116+
- [Workflow commands for GitHub Actions](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions)
117+
- [GitHub Actions Exploitation: Repo Jacking and Environment Manipulation](https://www.synacktiv.com/publications/github-actions-exploitation-repo-jacking-and-environment-manipulation)
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Environment Variable Injection
2+
3+
## Description
4+
5+
GitHub Actions allow to define environment variables by writing to a file pointed to by the `GITHUB_ENV` environment variable:
6+
7+
This file contains lines in the `KEY=VALUE` format:
8+
9+
```bash
10+
steps:
11+
- name: Set the value
12+
id: step_one
13+
run: |
14+
echo "action_state=yellow" >> "$GITHUB_ENV"
15+
```
16+
17+
It is also possible to define multiline variables by using the [following construct](https://en.wikipedia.org/wiki/Here_document):
18+
19+
```
20+
KEY<<{delimiter}
21+
VALUE
22+
VALUE
23+
{delimiter}
24+
```
25+
26+
```bash
27+
steps:
28+
- name: Set the value in bash
29+
id: step_one
30+
run: |
31+
{
32+
echo 'JSON_RESPONSE<<EOF'
33+
curl https://example.com
34+
echo EOF
35+
} >> "$GITHUB_ENV"
36+
```
37+
38+
If an attacker can control the values assigned to environment variables and there is no sanitization in place, the attacker will be able to inject additional variables by injecting new lines or `{delimiters}`.
39+
40+
## Recommendations
41+
42+
1. **Do not allow untrusted data to influence environment variables**:
43+
44+
- Avoid using untrusted data sources (e.g., artifact content) to define environment variables.
45+
- Validate and sanitize all inputs before using them in environment settings.
46+
47+
2. **Do not allow new lines when defining single line environment variables**:
48+
49+
- `echo "BODY=$(echo "$BODY" | tr -d '\n')" >> "$GITHUB_ENV"`
50+
51+
3. **Use unique identifiers when defining multi line environment variables**:
52+
53+
```bash
54+
steps:
55+
- name: Set the value in bash
56+
id: step_one
57+
run: |
58+
# Generate a UUID
59+
UUID=$(uuidgen)
60+
{
61+
echo "JSON_RESPONSE<<EOF$UUID"
62+
curl https://example.com
63+
echo "EOF$UUID"
64+
} >> "$GITHUB_ENV"
65+
```
66+
67+
## Examples
68+
69+
### Example of Vulnerability
70+
71+
Consider the following basic setup where an environment variable `MYVAR` is set and used in subsequent steps:
72+
73+
```yaml
74+
steps:
75+
- name: Set the value
76+
id: step_one
77+
env:
78+
BODY: ${{ github.event.comment.body }}
79+
run: |
80+
REPLACED=$(echo "$BODY" | sed 's/FOO/BAR/g')
81+
echo "MYVAR=$REPLACED" >> "$GITHUB_ENV"
82+
```
83+
84+
If an attacker can manipulate the value being set, such as through artifact downloads or user inputs, the attacker can potentially inject new environment variables. For example, they could write an issue comment like:
85+
86+
```text
87+
FOO
88+
NEW_ENV_VAR=MALICIOUS_VALUE
89+
```
90+
91+
Likewise, if the attacker controls a file in the GitHub Actions Runner's workspace (eg: the workflow checkouts untrusted code or downloads an untrusted artifact) and the contents of that file are assigned to an environment variable such as:
92+
93+
```bash
94+
- run: |
95+
PR_NUMBER=$(cat pr-number.txt)
96+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
97+
```
98+
99+
An attacker could craft a malicious artifact that writes dangerous environment variables:
100+
101+
```bash
102+
- run: |
103+
echo -e "666\nNEW_ENV_VAR=MALICIOUS_VALUE" > pr-number.txt
104+
- uses: actions/upload-artifact@v4
105+
with:
106+
name: pr-number
107+
path: ./pr-number.txt
108+
```
109+
110+
### Exploitation
111+
112+
An attacker is be able to run arbitrary code by injecting environment variables such as `LD_PRELOAD`, `BASH_ENV`, etc.
113+
114+
## References
115+
116+
- [Workflow commands for GitHub Actions](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions)
117+
- [GitHub Actions Exploitation: Repo Jacking and Environment Manipulation](https://www.synacktiv.com/publications/github-actions-exploitation-repo-jacking-and-environment-manipulation)

ql/src/Security/CWE-078/CommandInjectionCritical.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* @id actions/command-injection/critical
1010
* @tags actions
1111
* security
12+
* experimental
1213
* external/cwe/cwe-078
1314
*/
1415

ql/src/Security/CWE-078/CommandInjectionMedium.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* @id actions/command-injection/medium
1010
* @tags actions
1111
* security
12+
* experimental
1213
* external/cwe/cwe-078
1314
*/
1415

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Argument Injection in GitHub Actions
2+
3+
## Description
4+
5+
Passing user-controlled arguments to certain commands in the context of `Run` steps may lead to arbitrary code execution.
6+
7+
Argument injection in GitHub Actions may allow an attacker to exfiltrate any secrets used in the workflow and the temporary GitHub repository authorization token. The token may have write access to the repository, allowing the attacker to make changes to the repository.
8+
9+
## Recommendations
10+
11+
When possible avoid passing user-controlled data to commands which may spawn new processes using some of their arguments.
12+
13+
It is also recommended to limit the permissions of any tokens used by a workflow such as the GITHUB_TOKEN.
14+
15+
## Examples
16+
17+
### Incorrect Usage
18+
19+
The following example lets a user inject an arbitrary shell command through argument injection:
20+
21+
```yaml
22+
on: issue_comment
23+
24+
jobs:
25+
echo-body:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- env:
29+
BODY: ${{ github.event.comment.body }}
30+
run: |
31+
cat file.txt | sed "s/BODY_PLACEHOLDER/$BODY/g" > replaced.txt
32+
```
33+
34+
An attacker may set the body of an Issue comment to `BAR|g;1e whoami;#` and the command `whoami` will get executed during the `sed` operation.
35+
36+
## References
37+
38+
- [Common Weakness Enumeration: CWE-88](https://cwe.mitre.org/data/definitions/88.html).
39+
- [Argument Injection Explained](https://sonarsource.github.io/argument-injection-vectors/explained/)
40+
- [Argument Injection Vectors](https://sonarsource.github.io/argument-injection-vectors/)
41+
- [GTFOBins](https://gtfobins.github.io/)

ql/src/Security/CWE-094/ArgumentInjectionCritical.ql renamed to ql/src/Security/CWE-088/ArgumentInjectionCritical.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
* @id actions/argument-injection/critical
99
* @tags actions
1010
* security
11-
* external/cwe/cwe-094
12-
* external/cwe/cwe-095
13-
* external/cwe/cwe-116
11+
* external/cwe/cwe-088
1412
*/
1513

1614
import actions

0 commit comments

Comments
 (0)