You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pentesting-ci-cd/github-security/abusing-github-actions/gh-actions-context-script-injections.md
+48Lines changed: 48 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,6 +53,46 @@ New issue uid=1001(runner) gid=118(docker) groups=118(docker),4(adm),100(users),
53
53
Why quoting doesn’t save you:
54
54
- Expressions are rendered first, then the resulting script runs. If the untrusted value contains $(...), `;`, `"`/`'`, or newlines, it can alter the program structure despite your quoting.
A dangerous variant appears when a workflow **searches comments and later treats the returned comment as trusted automation state**. For example, `peter-evans/find-comment` can search by `body-includes` and expose the matching `comment-body` as a step output. If the workflow does **not** also restrict `comment-author`, any user who can comment may spoof the marker text expected from a bot.
59
+
60
+
```yaml
61
+
- uses: peter-evans/find-comment@v4
62
+
id: fc
63
+
with:
64
+
issue-number: ${{ github.event.issue.number }}
65
+
body-includes: "Opened a new issue in org/repo:"
66
+
```
67
+
68
+
If that output is later embedded into shell syntax, the workflow becomes exploitable even though the original source was "just a comment":
69
+
70
+
```yaml
71
+
- run: |
72
+
if [ '${{ steps.fc.outputs.comment-body }}' = '' ]; then
73
+
echo "new issue needed"
74
+
fi
75
+
```
76
+
77
+
An attacker can post a comment that both:
78
+
- matches the searched marker string, and
79
+
- contains shell-breaking content such as `' ]; <cmd>; if [ 'x`
80
+
81
+
After GitHub renders `${{ ... }}`, Bash receives attacker-controlled syntax, not data. This creates a **two-stage exploit**:
82
+
1. **Provenance confusion**: the workflow mistakes attacker comments for bot state.
83
+
2. **Script injection**: the returned `comment-body` is pasted into `run:` and executed.
84
+
85
+
### TOCTOU race against bot comments
86
+
87
+
If the legitimate bot comment is created only after some earlier step, an attacker may race it by posting the spoofed comment first. If the search action returns the attacker's comment before the real bot comment exists (or before it is selected), a low-privilege public commenter can turn an `issue_comment`/issue workflow into privileged runner execution.
88
+
89
+
### Safer patterns for comment-driven automation
90
+
91
+
- When using `find-comment`, require **both content and provenance** (`comment-author`, repository/App identity, or another strong binding).
92
+
- Do not use comments as state if a label, artifact, issue field, or external datastore can hold the same state more safely.
93
+
- Never paste `comment-body`, issue titles, labels, or any workflow output derived from them directly into `run:`.
94
+
- If you must consume comment text, pass it through `env:` or a file and handle it as data only.
95
+
56
96
## Safe pattern (shell variables via env)
57
97
58
98
Correct mitigation: copy untrusted input into an environment variable, then use native shell expansion ($VAR) in the run script. Do not re-embed with ${{ ... }} inside the command.
@@ -87,6 +127,10 @@ Accounts with only read permission on public repositories can still trigger many
87
127
88
128
Which specific fields are attacker-controlled is event-specific. Consult GitHub Security Lab’s untrusted input guide: https://securitylab.github.com/resources/github-actions-untrusted-input/
89
129
130
+
## Local validation without touching the target repo
131
+
132
+
You can reproduce many GitHub Actions script injections safely with [`act`](https://github.com/nektos/act): generate a synthetic event JSON, run the vulnerable workflow locally, and replace the external action output with a controlled value (for example a mocked `comment-body`). This is useful to debug payload structure, verify whether the injected text still leaves valid Bash syntax, and confirm harmless canary exfiltration before any live test.
133
+
90
134
## Practical tips
91
135
92
136
- Minimize use of expressions inside run:. Prefer env: mapping + $VAR.
@@ -96,6 +140,10 @@ Which specific fields are attacker-controlled is event-specific. Consult GitHub
96
140
97
141
## References
98
142
143
+
- [Find Comment, Get Shell: Command Injection in dbt’s GitHub Actions](https://landh.tech/blog/20260701-find-comment-get-shell)
- [GHSL-2023-109: GitHub Actions command injection in a TDesign Vue Next workflow](https://securitylab.github.com/advisories/GHSL-2023-109_TDesign_Vue_Next/)
146
+
- [nektos/act](https://github.com/nektos/act)
99
147
- [GitHub Actions: A Cloudy Day for Security - Part 1](https://binarysecurity.no/posts/2025/08/securing-gh-actions-part1)
0 commit comments