Skip to main content

SKY-D300 · CI/CD pipelines

Unsafe write to GITHUB_ENV or GITHUB_PATH

High

The catalog lists HIGH, but the detector reports every finding as MEDIUM.

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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

.github/workflows/coverage-comment.yml · YAMLReported on line 19
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

.github/workflows/tests.yml · YAML
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 . && pytest

Why 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

  1. Reads the steps of workflows and of composite actions (action.yml). Only a step's own run: text is read.
  2. Looks at each line of the script that names the file: $GITHUB_ENV, ${GITHUB_ENV}, %GITHUB_ENV%, $env:GITHUB_ENV, or the same forms of GITHUB_PATH. The line must also contain >, >>, | or tee, so reading the file is not a write.
  3. 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 unquoted echo NAME=value.
  4. 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.

.github/workflows/coverage-comment.yml · YAML · the fix, against the flagged file
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" (every GITHUB_PATH line is a folder, never NAME=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 first run: 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.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.