Skip to content

Commit 240ed21

Browse files
committed
chore: minor refactoring
1 parent 5be5614 commit 240ed21

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

danger/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ module.exports = async function ({ fail, warn, message, markdown, danger }) {
7676
warn('...');
7777
}
7878
79-
```
79+
```

danger/action.yml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ runs:
2626
steps:
2727
- name: Checkout repository
2828
uses: actions/checkout@v4
29-
env:
30-
API_TOKEN: ${{ inputs.api-token }}
3129
with:
32-
token: ${{ env.API_TOKEN }}
30+
token: ${{ inputs.api-token }}
3331
fetch-depth: 0
3432

3533
# Read the Danger version from the properties file
@@ -41,16 +39,19 @@ runs:
4139
# Validate extra-install-packages to prevent code injection
4240
- name: Validate package names
4341
if: ${{ inputs.extra-install-packages }}
44-
shell: bash
42+
shell: pwsh
4543
env:
4644
EXTRA_INSTALL_PACKAGES: ${{ inputs.extra-install-packages }}
4745
run: |
48-
packages="$EXTRA_INSTALL_PACKAGES"
49-
# Only allow alphanumeric characters, hyphens, periods, plus signs, underscores, and spaces
50-
if ! echo "$packages" | grep -E '^[a-zA-Z0-9._+-]+( [a-zA-Z0-9._+-]+)*$' > /dev/null; then
51-
echo "::error::Invalid package names in extra-install-packages. Only alphanumeric characters, hyphens, periods, plus signs, underscores, and spaces are allowed."
52-
exit 1
53-
fi
46+
# Validate against Debian package naming rules: must start with alphanumeric,
47+
# contain only lowercase letters, digits, hyphens, plus signs, periods
48+
# Package names cannot start with hyphen or period, and must be reasonable length
49+
foreach ($pkg in $env:EXTRA_INSTALL_PACKAGES -split '\s+') {
50+
if ($pkg -notmatch '^[a-z0-9][a-z0-9.+-]{0,100}$') {
51+
Write-Host "::error::Invalid package name '$pkg'. Debian packages must start with lowercase letter or digit and contain only lowercase letters, digits, hyphens, periods, and plus signs."
52+
exit 1
53+
}
54+
}
5455
5556
# Using a pre-built docker image in GitHub container registry instead of NPM to reduce possible attack vectors.
5657
- name: Setup container
@@ -88,4 +89,9 @@ runs:
8889
id: danger
8990
shell: bash
9091
run: |
91-
docker exec --user $(id -u) danger danger ci --fail-on-errors --dangerfile ${{ github.action_path }}/dangerfile.js
92+
docker exec --user $(id -u) danger danger ci --fail-on-errors --dangerfile ${{ github.action_path }}/dangerfile.js
93+
94+
- name: Cleanup container
95+
if: always()
96+
shell: bash
97+
run: docker rm -f danger || true

danger/dangerfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ async function checkFromExternalChecks() {
202202
const resolvedPath = fs.realpathSync(customPath);
203203
if (!resolvedPath.startsWith(workspaceDir)) {
204204
fail(`Invalid dangerfile path: ${extraDangerFilePath}. Must be within workspace.`);
205-
return;
205+
throw new Error('Security violation: dangerfile path outside workspace');
206206
}
207207

208208
const extraModule = require(customPath);

0 commit comments

Comments
 (0)