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:
- a publish command:
npm publish,pnpm publish,yarn publish,yarn npm publish(alsoyarn workspaces foreach … npm publish), and - an install that runs dependency lifecycle scripts:
npm ci,npm install/npm i/npm add,npm install-test/npm citand their aliases, bareyarn,yarn install,yarn add, also behindsudoorenv. A global install (npm install -g npm@11,yarn global add …) adds a named tool, not the project's dependencies, and is not counted.
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:
--ignore-scriptson the install line, or Yarn 2+'s--mode=skip-build;NPM_CONFIG_IGNORE_SCRIPTSornpm_config_ignore_scriptsset totrue, orYARN_ENABLE_SCRIPTSset tofalse, as the value the job gets, or as an assignment in front of the install command;- earlier in the job,
npm config set ignore-scripts true, anignore-scripts=trueline written to.npmrc,export NPM_CONFIG_IGNORE_SCRIPTS=true, oryarn config set enableScripts false.
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 publish command:
twine upload,poetry publish,uv publish,flit publish,hatch publishorpdm publish, also aspython -m twine,uvx twine, oruv run/poetry run/pipx run … twine. A--dry-runuploads nothing and is not counted; and - an install of the project's dependency tree:
pip install -r …,pip install .,pip install -e .andpip install .[extra](alsopython -m pipanduv pip install),uv pip sync,uv sync,poetry install,pipenv install/syncandpdm install/sync.
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:
--only-binary :all:on a pip oruv pipinstall, or--no-buildon a uv install;PIP_ONLY_BINARYset to:all:,UV_NO_BUILDset to1/true, or Poetry 2'sPOETRY_INSTALLER_ONLY_BINARYset to:all:/true, as the value the job gets, or as an assignment in front of the install command;- earlier in the job, an
exportof one of these,pip config set global.only-binary :all:, orpoetry config installer.only-binary :all:.
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