Skip to content

Commit 283729d

Browse files
use env
fix reference use instefof instead of invalid contains use
1 parent 2cc1eb3 commit 283729d

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

danger/action.yml

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

3335
# Read the Danger version from the properties file
@@ -40,8 +42,10 @@ runs:
4042
- name: Validate package names
4143
if: ${{ inputs.extra-install-packages }}
4244
shell: bash
45+
env:
46+
EXTRA_INSTALL_PACKAGES: ${{ inputs.extra-install-packages }}
4347
run: |
44-
packages="${{ inputs.extra-install-packages }}"
48+
packages="$EXTRA_INSTALL_PACKAGES"
4549
# Only allow alphanumeric characters, hyphens, periods, plus signs, underscores, and spaces
4650
if ! echo "$packages" | grep -E '^[a-zA-Z0-9._+-]+( [a-zA-Z0-9._+-]+)*$' > /dev/null; then
4751
echo "::error::Invalid package names in extra-install-packages. Only alphanumeric characters, hyphens, periods, plus signs, underscores, and spaces are allowed."
@@ -51,6 +55,9 @@ runs:
5155
# Using a pre-built docker image in GitHub container registry instead of NPM to reduce possible attack vectors.
5256
- name: Setup container
5357
shell: bash
58+
env:
59+
API_TOKEN: ${{ inputs.api-token }}
60+
EXTRA_DANGERFILE: ${{ inputs.extra-dangerfile }}
5461
run: |
5562
# Start a detached container with all necessary volumes and environment variables
5663
docker run -td --name danger \
@@ -61,19 +68,21 @@ runs:
6168
--workdir /github/workspace \
6269
--user $(id -u) \
6370
-e "INPUT_ARGS" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e GITHUB_ACTIONS=true -e CI=true \
64-
-e GITHUB_TOKEN="${{ inputs.api-token }}" \
71+
-e GITHUB_TOKEN="$API_TOKEN" \
6572
-e DANGER_DISABLE_TRANSPILATION="true" \
66-
-e EXTRA_DANGERFILE_INPUT="${{ inputs.extra-dangerfile }}" \
73+
-e EXTRA_DANGERFILE_INPUT="$EXTRA_DANGERFILE" \
6774
ghcr.io/danger/danger-js:${{ steps.config.outputs.version }} \
6875
-c "sleep infinity"
6976
7077
- name: Setup additional packages
7178
if: ${{ inputs.extra-install-packages }}
7279
shell: bash
80+
env:
81+
EXTRA_INSTALL_PACKAGES: ${{ inputs.extra-install-packages }}
7382
run: |
7483
docker exec --user root danger apt-get update
75-
echo "Installing packages: ${{ inputs.extra-install-packages }}"
76-
docker exec --user root danger sh -c "set -e && apt-get install -y --no-install-recommends ${{ inputs.extra-install-packages }}"
84+
echo "Installing packages: $EXTRA_INSTALL_PACKAGES"
85+
docker exec --user root danger sh -c "set -e && apt-get install -y --no-install-recommends $EXTRA_INSTALL_PACKAGES"
7786
echo "All additional packages installed successfully."
7887
7988
- name: Run DangerJS

danger/dangerfile.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,13 @@ async function CheckFromExternalChecks() {
193193
console.log(`::debug:: Checking from external checks: ${extraDangerFilePath}`);
194194
if (extraDangerFilePath) {
195195
try {
196-
if (extraDangerFilePath.contains(workspaceDir)) {
196+
const workspaceDir = '/github/workspace';
197+
const customPath = `${workspaceDir}/${extraDangerFilePath}`;
198+
199+
if (extraDangerFilePath.indexOf('..') !== -1) {
197200
fail(`Invalid dangerfile path: ${customPath}. Path traversal is not allowed.`);
198201
return;
199-
}
200-
201-
const workspaceDir = '/github/workspace';
202-
const customPath = `${workspaceDir}${extraDangerFilePath}`;
202+
}
203203

204204
const extraModule = require(customPath);
205205
if (typeof extraModule !== 'function') {

0 commit comments

Comments
 (0)