Skip to main content

SKY-D305 · CI/CD pipelines

Multi-line if with ${{ }} that is always true

Medium

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

An if: written as a YAML block (if: |) keeps a line break after the last line. When the block holds ${{ … }}, GitHub no longer sees one expression but text with an expression inside, and any non-empty text is true. SKY-D305 reports a block if: that contains ${{.

Languages
GitHub Actions workflows
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Catalog name
GitHub Actions unsound multiline condition
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

The condition never stops the job. In the example, a release meant to run only for version tags and main also runs when someone starts the workflow by hand on any branch, and publishes that branch.

What Skylos flags

.github/workflows/release.yml · YAMLReported on line 10
name: Releaseon:  push:    tags: ["v*"]  workflow_dispatch:permissions:  contents: readjobs:  publish:    if: |      ${{ startsWith(github.ref, 'refs/tags/v') ||          github.ref == 'refs/heads/main' }}    runs-on: ubuntu-latest    environment: release    steps:      - uses: actions/checkout@v4        with:          persist-credentials: false      - run: ./scripts/publish.sh        env:          REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}

What Skylos leaves alone

.github/workflows/release.yml · YAML
name: Releaseon:  push:    tags: ["v*"]  workflow_dispatch:permissions:  contents: readjobs:  publish:    if: |      startsWith(github.ref, 'refs/tags/v') ||      github.ref == 'refs/heads/main'    runs-on: ubuntu-latest    environment: release    steps:      - uses: actions/checkout@v4        with:          persist-credentials: false      - run: ./scripts/publish.sh        env:          REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}

Why Skylos leaves it alone

The block has no ${{ }}. GitHub reads the whole if: text as the expression, and the trailing line break does not change its value.

How Skylos decides

  1. Reads workflow files under .github/workflows, not composite actions.
  2. Goes through the file line by line for if: followed by a block marker, | or > with any modifier (|-, >-, |+), on its own or after a list dash.
  3. Takes the lines below it that are indented further, and reports when any of them contains ${{.
  4. One HIGH finding on the if: line.

How to fix it

Write the condition without ${{ }}, either on one line or as a block. GitHub treats a bare if: as an expression.

.github/workflows/release.yml · YAML · the fix, against the flagged file
name: Releaseon:  push:    tags: ["v*"]  workflow_dispatch:permissions:  contents: readjobs:  publish:Removed:     if: |Removed:       ${{ startsWith(github.ref, 'refs/tags/v') ||Removed:           github.ref == 'refs/heads/main' }}Added:     if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main'    runs-on: ubuntu-latest    environment: release    steps:      - uses: actions/checkout@v4        with:          persist-credentials: false      - run: ./scripts/publish.sh        env:          REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}

When it can be wrong

  • if: |- and if: >- drop the final line break, so a ${{ }} block written with them works as intended. Skylos still reports them, even though its own message suggests a stripped block.

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-D305] on the reported if: line or on the line directly above it, one rule per marker.

    YAML
    # skylos: ignore[SKY-D305] |- strips the trailing line breakif: |-  ${{ github.event_name == 'push' }}
  • [tool.skylos] ignore = ["SKY-D305"] 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.