SKY-D303 · CI/CD pipelines
contains() used as an allow-list check
In a GitHub Actions expression, contains('alice bob', github.actor) with a text first argument is a substring test, not a list lookup. It is true for any value that appears anywhere inside the text. SKY-D303 reports contains() used this way in a job or step if: on a value the person running the workflow can choose.
- Languages
- GitHub Actions workflows
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- review
- Catalog name
- GitHub Actions unsound contains condition
Why it matters
A condition meant to let only alice-dev and bob-ops deploy also lets through accounts named bob, b-op or ice-d. Whoever registers such a name gets past the check and runs the job with its secrets.
What Skylos flags
name: Deploy on commandon: issue_comment: types: [created]permissions: contents: readjobs: deploy: if: contains('alice-dev bob-ops carol', github.actor) runs-on: ubuntu-latest environment: production steps: - run: ./scripts/deploy.sh env: DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}What Skylos leaves alone
name: Deploy on labelon: pull_request_target: types: [labeled]permissions: contents: readjobs: deploy: if: contains(github.event.pull_request.labels.*.name, 'deploy') runs-on: ubuntu-latest environment: production steps: - run: ./scripts/deploy.sh env: DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}Why Skylos leaves it alone
Here the first argument is an array (the label names), so contains() looks for an exact element. Only accounts with triage or write access can add a label.
How Skylos decides
- Reads the
if:of every job and step in workflow files (not composite actions). - Looks for
contains('…', X): the first argument a quoted text, the second a plain context name. - Reports it when X is, or starts with, one of
env,inputs,github.actor,github.triggering_actor,github.ref,github.ref_name,github.head_ref,github.base_reforgithub.sha. It does not check which events start the workflow or what the condition is used for. - One HIGH finding per condition and context, on the first line of the file that holds the condition's first line.
How to fix it
Turn the list into a real array with fromJSON, so contains() checks for an exact element. Comparing with == for each name works too.
name: Deploy on commandon: issue_comment: types: [created]permissions: contents: readjobs: deploy:Removed: if: contains('alice-dev bob-ops carol', github.actor)Added: if: contains(fromJSON('["alice-dev", "bob-ops", "carol"]'), github.actor) runs-on: ubuntu-latest environment: production steps: - run: ./scripts/deploy.sh env: DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}When it can be wrong
- A substring test that is meant as one, such as
contains('refs/heads/main refs/heads/develop', github.ref)in a push-only workflow, is reported even though only people with write access can push a branch. - A condition written over several lines (
if: >-) is found, but its line is looked up by the whole folded text, which is not in the file, so the finding is placed on line 1.
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-D303]on the reported line or on the line directly above it, one rule per marker.YAML # skylos: ignore[SKY-D303] push-only workflow, only writers pushif: contains('refs/heads/main refs/heads/develop', github.ref)[tool.skylos] ignore = ["SKY-D303"]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.