Skip to main content

SKY-D320 · CI/CD pipelines

GitLab CI release job restores a cache

High

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

A GitLab cache: keeps files such as downloaded packages between jobs and pipelines. SKY-D320 reports a job that releases or deploys and still restores a cache, its own or one it inherits from default: or the top of the file.

Languages
GitLab CI
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Catalog name
GitLab CI release cache poisoning risk
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Other jobs and pipelines write the same cache, and GitLab keeps a separate one only for protected branches and tags. A job on a less trusted ref that uses the same key can leave a tampered package in .npm/, and the release job then installs it and ships it to your users.

What Skylos flags

.gitlab-ci.yml · YAMLReported on line 16
stages: [test, release] default:  image: node:22-bookworm  cache:    key:      files: [package-lock.json]    paths: [.npm/] test:  stage: test  script:    - npm ci --cache .npm --prefer-offline    - npm test publish:  stage: release  timeout: 15 minutes  rules:    - if: $CI_COMMIT_TAG  script:    - npm ci --cache .npm --prefer-offline    - npm publish

What Skylos leaves alone

.gitlab-ci.yml · YAML
stages: [test, release] default:  image: node:22-bookworm test:  stage: test  cache:    key:      files: [package-lock.json]    paths: [.npm/]  script:    - npm ci --cache .npm --prefer-offline    - npm test publish:  stage: release  timeout: 15 minutes  rules:    - if: $CI_COMMIT_TAG  script:    - npm ci    - npm publish

Why Skylos leaves it alone

Only the test job uses the cache. The publish job sets no cache and inherits none, so it installs every package fresh from the registry.

How Skylos decides

  1. Runs with --danger (and -a). Reads every file named exactly .gitlab-ci.yml in the scanned folder, skipping .git, node_modules, .venv, venv, build, dist and cache folders. Files pulled in with include: are not read, and a file PyYAML's safe loader cannot read (for example one that uses !reference) is skipped.
  2. Picks release-like jobs, hidden .template jobs excluded: the job name contains deploy, release or publish; its stage is deploy, deployment, release, publish or production; its environment is prod or production; it has release, id_tokens or identity; or a command starts with a publish or deploy tool such as docker push, npm publish, twine upload, cargo publish, helm upgrade, kubectl apply or terraform apply.
  3. Takes the job's cache (its own, else from default:, else top-level). Any value except false, [], {} or none counts as on.
  4. One MEDIUM finding per job, on the first line that contains the job name followed by :.

How to fix it

Turn the cache off in release and deploy jobs with cache: [], or give them a key no other job writes. Pass build output to them as artifacts from a job in the same pipeline.

.gitlab-ci.yml · YAML · the fix, against the flagged file
stages: [test, release] default:  image: node:22-bookworm  cache:    key:      files: [package-lock.json]    paths: [.npm/] test:  stage: test  script:    - npm ci --cache .npm --prefer-offline    - npm test publish:  stage: release  timeout: 15 minutesAdded:   cache: []  rules:    - if: $CI_COMMIT_TAG  script:Removed:     - npm ci --cache .npm --prefer-offlineAdded:     - npm ci    - npm publish

When it can be wrong

  • A cache with its own key that only release jobs write is reported the same as a shared one.
  • A job is release-like by name alone, so release-notes-preview with a cache is reported.
  • The flagged example also gets SKY-D340 for npm publish; that rule is separate.

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-D320] and a reason on the reported line, or on the line directly above it. Skylos looks for that exact text, so write one rule per marker, with the ID in upper case.

    YAML
    # skylos: ignore[SKY-D320] cache key is written only by release jobspublish:
  • [tool.skylos] ignore = ["SKY-D320"] turns the rule off for the whole project.

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