glsec

Rules / GL090

GL090 Publish job runs dependency install code

Severity: warn
OWASP: CICD-SEC-3 – Dependency Chain Abuse
CWE: CWE-829 – Inclusion of Functionality from Untrusted Control Sphere

Risk

npm ci, npm install and yarn install run the preinstall, install and postinstall scripts of every dependency. In a job that also publishes the package, those scripts run with the publish token in the environment. A single compromised dependency can read the token and the job's other secrets and publish new versions of the maintainer's own packages. This is how the 2025 npm worms (Shai-Hulud and its successors) spread. The token never has to appear in the pipeline file; it only has to be reachable from the install step.

Python and Ruby work the same way when a dependency has to be built. pip, uv, Poetry, Pipenv and PDM install a wheel without running any package code, but build a source distribution by running its setup.py or build backend in the job. Whoever controls a dependency also controls whether a release ships a wheel, so publishing only an sdist is enough to get code run. bundle install runs the extconf.rb of every gem with a native extension.

What glsec checks

A job (with before_script and script taken from default: and the jobs it extends: in the same file) that publishes a package and, in the same ecosystem, installs dependencies in a way that runs their code. One finding is reported per ecosystem, on the install line.

npm

The job runs both:

The install is not counted when lifecycle scripts are off for it. A variable counts with the value GitLab gives the job: the job's own over a template's over the top-level one, and a value from rules: must protect on every path:

pnpm install and bun install are not counted: pnpm 10 and bun don't run the lifecycle scripts of dependencies unless they are allowed by name.

Python

The job runs both:

A named tool install such as pip install build twine or pip install --upgrade pip gets wheels and is not counted, nor is a local wheel (pip install ./dist/*.whl) or the project without its dependencies (pip install --no-deps .). python -m build builds the job's own code in an isolated environment and is not counted either.

The install is not counted when builds from source are off for it:

Any of these switches counts for every Python install in the job, even when it is for a different tool (PIP_ONLY_BINARY in front of uv sync).

Publishing with PyPI trusted publishing (id_tokens:) does not change the finding: the ID token is in the job's environment, and a build script can exchange it for an upload token just as twine does.

RubyGems

The job runs gem push or rake release (also bundle exec rake release) and bundle install or a bare bundle. A named gem install bundler is not counted. Nothing switches native extension builds off, so the only fix is to split the jobs.

Hidden jobs are not reported themselves.

Known attacks

The Shai-Hulud npm worm spread through install scripts that stole npm tokens and published infected versions.

Trigger example

publish:
  image: node:22.11.0
  variables:
    NPM_TOKEN: $NPM_PUBLISH_TOKEN
  script:
    - npm ci
    - npm publish

Safe alternatives

Build in one job and publish the built package from a job that installs nothing. The publish token is then only in the job that runs no dependency code:

build:
  image: node:22.11.0
  script:
    - npm ci
    - npm run build
    - npm pack
  artifacts:
    paths:
      - "*.tgz"

publish:
  image: node:22.11.0
  needs: [build]
  variables:
    NPM_TOKEN: $NPM_PUBLISH_TOKEN
  script:
    - npm publish ./*.tgz

If the package needs no install scripts, switch them off in the publish job:

publish:
  image: node:22.11.0
  script:
    - npm ci --ignore-scripts
    - npm publish

Publishing with trusted publishing (an OIDC token instead of a long-lived NPM_TOKEN) also limits what a stolen credential is worth.

For Python, upload the dist/ artifact from a job that installs only twine:

build:
  image: python:3.13.1
  script:
    - pip install -r requirements.txt
    - python -m build
  artifacts:
    paths:
      - dist/

publish:
  image: python:3.13.1
  needs: [build]
  variables:
    TWINE_USERNAME: __token__
    TWINE_PASSWORD: $PYPI_TOKEN
  script:
    - pip install twine
    - twine upload dist/*

Or install only wheels in the publish job:

publish:
  image: python:3.13.1
  variables:
    PIP_ONLY_BINARY: ":all:"
  script:
    - pip install -r requirements.txt
    - python -m build
    - twine upload dist/*

Commands wrapped in sudo or doas, including user and other value-taking options, are checked as the command they run.

Not detectable

ignore-scripts=true in a committed .npmrc, enableScripts: false in .yarnrc.yml, or only-binary = :all: in a committed pip.conf or uv.toml (no-build = true), is outside the pipeline file. In that case the finding can be suppressed with a reason:

    - npm ci  # glsec:ignore GL090 -- .npmrc sets ignore-scripts=true

A publish that happens inside a tool (semantic-release, changesets, lerna publish, an npm run release script, a make release target) is not visible either.

Documentation for glsec 1.29.0. Source of this page · Rule implementation