SKY-D300 · CI/CD pipelines
Unsafe write to GITHUB_ENV or GITHUB_PATH
A step can set environment variables for every later step in its job by appending NAME=value lines to the file named by $GITHUB_ENV, and add folders to PATH through $GITHUB_PATH. SKY-D300 reports a run: script that writes anything other than a fixed NAME=value text to one of those files.
- Languages
- GitHub Actions workflows, composite actions
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- review
- Catalog name
- GitHub Actions unsafe environment file write
Why it matters
If the written value comes from a file, a command or event text that someone else controls, a line break in it adds a variable of their choice, such as NODE_OPTIONS or LD_PRELOAD. Every later step in the job then runs their code with the job's token and secrets.
What Skylos flags
name: Coverage commenton: workflow_run: workflows: [Tests] types: [completed]permissions: actions: read pull-requests: writejobs: comment: runs-on: ubuntu-latest steps: - uses: actions/download-artifact@v4 with: name: coverage run-id: ${{ github.event.workflow_run.id }} github-token: ${{ github.token }} - name: Read the pull request number run: echo "PR_NUMBER=$(cat pr-number.txt)" >> "$GITHUB_ENV" - name: Post the coverage report run: gh pr comment "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --body-file cov.md env: GH_TOKEN: ${{ github.token }}What Skylos leaves alone
name: Testson: [push, pull_request]permissions: contents: readjobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: persist-credentials: false - name: Quieter pip run: echo "PIP_DISABLE_PIP_VERSION_CHECK=1" >> "$GITHUB_ENV" - run: pip install -e . && pytestWhy Skylos leaves it alone
The script writes a fixed NAME=value text in quotes, with no $ or backtick inside, so nothing outside the workflow file can shape what lands in $GITHUB_ENV.
How Skylos decides
- Reads the steps of workflows and of composite actions (
action.yml). Only a step's ownrun:text is read. - Looks at each line of the script that names the file:
$GITHUB_ENV,${GITHUB_ENV},%GITHUB_ENV%,$env:GITHUB_ENV, or the same forms ofGITHUB_PATH. The line must also contain>,>>,|ortee, so reading the file is not a write. - Accepts the line only when the part before the redirect is exactly
echo "NAME=value"(or single quotes) with no$or backtick in the value. Everything else is reported: command output, variables,${{ }}expressions,printf, heredocs, and unquotedecho NAME=value. - Reports one MEDIUM finding per file. It is placed on the first line of the file that starts with
run:(after spaces), which is not always the step that writes the file; when every step is written- run: …, the finding is on line 1.
How to fix it
Do not write outside data to $GITHUB_ENV. Check the value, pass it on as a step output, and give it to the next step through env:. A check before a $GITHUB_ENV write is not enough for Skylos: the line still holds a variable, so it is still reported.
name: Coverage commenton: workflow_run: workflows: [Tests] types: [completed]permissions: actions: read pull-requests: writejobs: comment: runs-on: ubuntu-latest steps: - uses: actions/download-artifact@v4 with: name: coverage run-id: ${{ github.event.workflow_run.id }} github-token: ${{ github.token }} - name: Read the pull request numberRemoved: run: echo "PR_NUMBER=$(cat pr-number.txt)" >> "$GITHUB_ENV"Added: id: prAdded: run: |Added: number="$(cat pr-number.txt)"Added: [[ "$number" =~ ^[0-9]+$ ]] || { echo "::error::bad number"; exit 1; }Added: echo "number=$number" >> "$GITHUB_OUTPUT" - name: Post the coverage report run: gh pr comment "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --body-file cov.md env: GH_TOKEN: ${{ github.token }}Added: PR_NUMBER: ${{ steps.pr.outputs.number }}When it can be wrong
- Common safe writes are reported:
echo "$HOME/.local/bin" >> "$GITHUB_PATH"(everyGITHUB_PATHline is a folder, neverNAME=value),echo "SHA=${GITHUB_SHA::7}" >> "$GITHUB_ENV", and a value checked against a strict pattern first. - Several unsafe steps in one file give a single finding, on the first
run:line of the file, even when that step writes nothing.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Put
# skylos: ignore[SKY-D300]on the reported line or on the line directly above it. Because the file gets one finding on its firstrun:line, that marker silences the rule for the whole file.YAML # skylos: ignore[SKY-D300] SHA comes from the runnerrun: echo "SHORT_SHA=${GITHUB_SHA::7}" >> "$GITHUB_ENV"[tool.skylos] ignore = ["SKY-D300"]turns the rule off for the whole project.A baseline works, but it records the absolute file path and the line, so it stops matching when the checkout moves or lines above shift.