Skip to content

Commit 2beeec8

Browse files
Potential fix for code scanning alert no. 350: Artifact poisoning
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Dargon789 <64915515+Dargon789@users.noreply.github.com>
1 parent 157d3cb commit 2beeec8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

.github/workflows/npm.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,21 +292,30 @@ jobs:
292292
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
293293
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
294294
NPM_REGISTRY_URL: ${{ env.NPM_REGISTRY_URL }}
295+
# Use the validated release version derived earlier, not any arbitrary environment value.
296+
RELEASE_VERSION: ${{ steps.release-version.outputs.RELEASE_VERSION }}
295297
run: |
296298
set -euo pipefail
297-
bun run build
298299
299-
# Validate RELEASE_VERSION before exporting it. Only allow semantic-version-like strings,
300-
# e.g. 1.2.3 or 1.2.3-beta.1. Reject anything else to avoid artifact poisoning.
300+
# Validate RELEASE_VERSION before using or exporting it. Only allow semantic-version-like strings,
301+
# and reject any value containing whitespace or newlines to prevent artifact poisoning.
301302
if [[ -z "${RELEASE_VERSION:-}" ]]; then
302303
echo "RELEASE_VERSION is empty or unset; refusing to export." >&2
303304
exit 1
304305
fi
306+
# Disallow whitespace (including newlines, tabs) in RELEASE_VERSION
307+
if [[ "$RELEASE_VERSION" =~ [[:space:]] ]]; then
308+
echo "RELEASE_VERSION contains whitespace; refusing to export." >&2
309+
exit 1
310+
fi
311+
# Only allow versions like 1.2.3 or 1.2.3-beta.1
305312
if ! [[ "$RELEASE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
306313
echo "RELEASE_VERSION '$RELEASE_VERSION' has an invalid format; refusing to export." >&2
307314
exit 1
308315
fi
309316
317+
bun run build
318+
310319
printf 'RELEASE_VERSION=%s\n' "$RELEASE_VERSION" >>"$GITHUB_OUTPUT"
311320
312321
- name: Stage Binary Into Package

0 commit comments

Comments
 (0)