Skip to content

Commit 1ff8da5

Browse files
authored
prevent command substitution via uses (#27)
ideally you would never build a `uses` using untrusted input, but better safe than sorry 😅
1 parent b0b52ac commit 1ff8da5

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

.github/workflows/test.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,26 @@ jobs:
4848
- uses: ./.github/actions/assert-equal
4949
with:
5050
expected: 🙊
51-
actual: ${{ fromJSON(steps.no-inputs.outputs.outputs).echo }}
51+
actual: ${{ fromJSON(steps.no-inputs.outputs.outputs).echo }}
52+
test-invalid-inputs:
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@v6
57+
- name: attempt command substitution via uses
58+
id: command-substitution
59+
uses: ./.
60+
with:
61+
uses: ./.github/actions/echo$(echo secret>ohno.txt)
62+
continue-on-error: true
63+
- uses: ./.github/actions/assert-equal
64+
with:
65+
expected: failure
66+
actual: ${{ steps.command-substitution.outcome }}
67+
- id: verify-command-didnt-run
68+
shell: bash
69+
run: |
70+
if [ -f ohno.txt ]; then
71+
echo "::error::Expected command substitution not to happen"
72+
exit 1
73+
fi

action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ runs:
1919
- name: Setup
2020
shell: bash
2121
env:
22+
uses: ${{ inputs.uses }}
2223
with: ${{ inputs.with }}
2324
run: |
2425
mkdir -p ./.tmp-dynamic-uses &&
@@ -33,7 +34,7 @@ runs:
3334
shell: bash
3435
- name: Run
3536
id: run
36-
uses: ${{ toJSON(inputs.uses) }}
37+
uses: '$(echo "$uses" | sed "s/'/''/g")'
3738
with:
3839
$(echo "$with" | sed 's/^/ /')
3940
DYNAMIC_USES_EOF

0 commit comments

Comments
 (0)