How build pipelines get attacked
Examine real-world software supply chain compromises, categorize attack vectors across source, dependency, build, and distribution tiers, and establish defense-in-depth pipeline hardening using OpenSSF Scorecard.
Contentsand lesson path
On this page
- The Expanded Attack Surface: Beyond Application Code
- Taxonomy of Pipeline Attacks: Source, Dependency, Build, and Artifact Tiers
- Pipeline Hardening: OpenSSF Scorecard and Automated Guardrails
- Check your understanding
- Apply it
- Review prompt
Lessons of Supply Chain Security
- How build pipelines get attacked Concept · 20 min
- SLSA in practice: hardened builds and provenance Concept · 20 min
- Lab: SBOMs and a vulnerability triage policy Lab · 25 min
- Lab: keyless signing and provenance in CI Lab · 25 min
- Enforcing trust at the cluster door Worked example · 20 min
- Check: supply-chain audit of a sample pipeline Knowledge check · 6 questions
What you will learn
- Map supply-chain threats across source, dependencies, build and distribution, assess a pipeline against SLSA build levels, and pin dependencies and base images with automated update pull requests.
01. The Expanded Attack Surface: Beyond Application Code
For decades, enterprise application security focused almost exclusively on vulnerabilities within first-party source code: addressing SQL injection, cross-site scripting, and authentication bypasses. However, modern cloud-native applications are constructed predominantly from open-source dependencies, third-party libraries, base container images, and automated continuous integration (CI) workflows. In many services, most of the code in the deployed artifact comes from dependencies, base images and build tooling rather than from the team's own source.
Attackers have noticed that breaking into a well-guarded production environment directly is often harder than compromising an upstream dependency or the build pipeline. When an attacker breaches a CI runner or an upstream package, the victim's own trusted automation builds, signs and deploys the malicious code, sometimes into many downstream organisations at once.
High-profile incidents illustrate this paradigm shift. The SolarWinds Orion breach demonstrated an adversary inserting a backdoor into an automated build system, allowing clean source code to produce trojanized commercial software. The Codecov Bash Uploader incident showed how attackers modified an unversioned bash script hosted on an external server, extracting environment variables and credentials from customers' CI runners. More recently, the XZ Utils (CVE-2024-3094) backdoor came from a multi-year social engineering effort: an obfuscated remote code execution backdoor, hidden in test files and in a modified M4 build macro that only the release tarballs contained, reached development versions of several Linux distributions before it was caught.
02. Taxonomy of Pipeline Attacks: Source, Dependency, Build, and Artifact Tiers
A comprehensive supply chain defense requires categorizing attack vectors across the four distinct phases of the software delivery lifecycle:
-
1. Source Integrity Attacks: Adversaries compromise developer workstations, steal personal access tokens (PATs) or SSH commit signing keys, or hijack contributor GitHub accounts to introduce malicious commits directly into version control. Unprotected Git branches, lack of branch protection rules, and single-approver pull request requirements allow unvetted code into mainline branches.
-
2. Dependency Poisoning (Upstream Ingestion): Attackers target the point where packages enter your build. Typosquatting registers misspelled package names on public registries (for example
crossenvforcross-env,reqeustsforrequests). Dependency confusion exploits package managers (npm, pip, Maven) that look in public registries as well as your private one when resolving an unscoped name, so a public package with your internal name wins. Account takeover hijacks an abandoned or poorly protected maintainer account on npm or PyPI, through credential stuffing or phishing, and publishes a malicious patch release. -
3. Build Runner Compromise: Malicious code executes during the CI build process. Many package managers execute arbitrary code upon installation (npm
preinstallscripts, setup.py execution). If an untrusted dependency runs in CI, it can inspect environment variables, read/proc/1/environ, steal cloud credentials, or modify compiled binaries on the runner filesystem before the artifact is hashed. -
4. Artifact Registry Tampering: Attackers gain write access to container registries, artifactory servers, or cloud storage buckets, replacing legitimate binary digests with poisoned versions without altering Git history.
name: Vulnerable Build Workflow
on: [pull_request_target] # Critical risk: runs with repo secrets
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # Anti-pattern: mutable tag
with:
ref: ${{ github.event.pull_request.head.sha }} # Untrusted code
- name: Insecure Script Ingestion
# Anti-pattern: piping unpinned external URL to bash
run: curl -sSfL https://install.corp-tool.io/cli.sh | bash
- name: Insecure Dependency Installation
# Anti-pattern: npm install runs lifecycle preinstall scripts
run: npm install --ignore-scripts=false03. Pipeline Hardening: OpenSSF Scorecard and Automated Guardrails
Defending build pipelines needs several layers of controls, so that one failure does not let an attack through:
-
Pinning Dependencies and Base Images by Cryptographic Digest: Never rely solely on mutable tags (such as
python:3.12-alpineorv4). Registries allow tags to be reassigned to malicious image digests without warning. Pinned digests (golang@sha256:4a8b...) fix the inputs, so any upstream change needs an explicit pull request that you review; bots such as Renovate or Dependabot open those pull requests for you. -
Securing CI Runner Workflows: Never combine
pull_request_targettriggers with checkouts of untrusted pull request code. Whenpull_request_targetexecutes, it runs in the context of the base repository with access to repository secrets; checking out pull request branches in that context allows fork submitters to execute arbitrary code that exfiltrates secrets. -
Automated Supply Chain Scoring with OpenSSF Scorecard: The Open Source Security Foundation (OpenSSF) maintains the Scorecard tool, an automated security health scanner for software repositories. Scorecard runs a set of automated checks (about twenty at the time of writing), including branch protection rules, cryptographically pinned dependencies, active maintenance, binary artifact verification, and presence of security policies (
SECURITY.md). The workflow below runs it weekly and on every push tomain. It pins every action to a commit SHA, so Scorecard's own Pinned-Dependencies check passes on this file, and it uploads the SARIF results withgithub/codeql-action/upload-sarif, without which the results never appear under Security → Code scanning. The job-levelpermissionsblock replaces the workflow-levelread-allfor this job, so it must list the read permissions as well; on private repositories the job fails without them. -
Disabling Lifecycle Install Scripts: Configure package managers to suppress automatic script execution during CI resolution (
npm ci --ignore-scripts). If legitimate native compilation is required, compile native extensions in dedicated, network-isolated sandboxes.
name: OpenSSF Scorecard Supply Chain Audit
on:
schedule:
- cron: "0 4 * * 1" # weekly, Monday 04:00 UTC
push:
branches: [main]
permissions: read-all # no write permissions at workflow level
jobs:
analysis:
runs-on: ubuntu-latest
permissions:
security-events: write # upload the SARIF results to code scanning
id-token: write # publish_results: prove the results came from here
contents: read # the four reads are needed on private repositories
issues: read
pull-requests: read
checks: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: ossf/scorecard-action@23f22cd43608bae7a1f1fa2603d7314dee9538a5 # v2.6.0
with:
results_file: results.sarif
results_format: sarif
publish_results: true
- name: Upload the results to the Security tab
# Split only to fit this page. In double quotes, a trailing `\` drops the
# line break and the next line's leading spaces; without it YAML puts a
# space after "@" and the ref breaks. In a real workflow keep the value
# and its tag comment on one line, so Dependabot and Renovate update both.
uses: "github/codeql-action/upload-sarif@\
915412ff23e8b7659517e607487dbeae018f2934" # v4.39.5
with:
sarif_file: results.sarif04. Check your understanding
05. Apply it
Implement these supply chain security practices across your organizational repositories:
- Adopt Scoped Packages: Prefix all internal company libraries with an organization scope (e.g.
@corp/payment-utils) and configure.npmrcto route scoped packages exclusively to internal artifact registries. - Pin Actions to Commit SHAs: Pin every third-party GitHub Action to an immutable 40-character commit SHA accompanied by a comment indicating the version (e.g.
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1). - Run OpenSSF Scorecard in CI: Embed the Scorecard GitHub Action to audit repository security hygiene weekly, tracking progress on branch protection and dependency pinning.
- Enforce
npm ci --ignore-scripts: Suppress automatic lifecycle script execution during continuous integration package installation, allow-listing only the packages whose build scripts you have reviewed. - Automate Dependency Updates with Renovate: Configure automated bots to submit tested pull requests for digest and package updates, ensuring upstream patches are reviewed systematically.
- Audit CI Workflow Permissions: Give the token only what the workflow needs. Start every workflow with a top-level
permissions:block that holds onlycontents: read(orpermissions: {}if no job reads the repository), and grant each extra scope, such asid-token: writeorsecurity-events: write, only on the job that uses it.read-allis broader: it grants read access to every scope. In the Scorecard workflow above it does no harm only because the single job replaces it with an explicit list.
06. Review prompt
Explain how software supply chain attacks differ from traditional application security vulnerabilities, detailing how adversaries leverage dependency confusion, typosquatting, and compromised build runners. Describe the critical security danger of combining GitHub Actions pull_request_target triggers with checkouts of untrusted pull request code, and explain why pinning third-party CI actions to full commit SHAs provides superior tamper resistance compared to mutable release tags.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.