Skip to content

Commit 193aa0e

Browse files
committed
Fix shell injection: use env vars for input interpolation
- Pass inputs.package and inputs.npm-tag through env vars instead of direct ${{ }} interpolation in bash to prevent command injection - Add npm-tag format validation (alphanumeric, hyphens, dots only) to prevent GITHUB_OUTPUT injection via newlines
1 parent 5f2d648 commit 193aa0e

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

.github/workflows/publish-package.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,27 @@ jobs:
5757
exit 1
5858
5959
- name: Validate package input
60+
env:
61+
PACKAGE: ${{ inputs.package }}
6062
run: |
61-
case "${{ inputs.package }}" in
63+
case "$PACKAGE" in
6264
express-boilerplate|integration-boilerplate-node|logger|mint-components|program-boilerplate|program-test-suite|publish-helper) ;;
63-
*) echo "::error::Invalid package '${{ inputs.package }}'."; exit 1 ;;
65+
*) echo "::error::Invalid package '${PACKAGE}'."; exit 1 ;;
6466
esac
6567
6668
- name: Generate Variables
6769
id: vars
70+
env:
71+
PACKAGE: ${{ inputs.package }}
72+
NPM_TAG: ${{ inputs.npm-tag || (inputs.increment-type == 'prerelease' && 'next') || 'latest' }}
6873
run: |
69-
echo "dir=packages/${{ inputs.package }}" >> ${GITHUB_OUTPUT}
70-
echo "npmtag=${{ inputs.npm-tag || (inputs.increment-type == 'prerelease' && 'next') || 'latest' }}" >> ${GITHUB_OUTPUT}
74+
# Validate npm-tag is a safe dist-tag value (alphanumeric, hyphens, dots)
75+
if [[ ! "$NPM_TAG" =~ ^[a-zA-Z0-9._-]+$ ]]; then
76+
echo "::error::Invalid npm-tag '${NPM_TAG}'. Must be alphanumeric with hyphens/dots only."
77+
exit 1
78+
fi
79+
echo "dir=packages/${PACKAGE}" >> ${GITHUB_OUTPUT}
80+
echo "npmtag=${NPM_TAG}" >> ${GITHUB_OUTPUT}
7181
7282
- name: Checkout
7383
id: checkout

0 commit comments

Comments
 (0)