Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 1 of 6 · Concept · 20 min · revision 3

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

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 crossenv for cross-env, reqeusts for requests). 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 preinstall scripts, 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.

YAML · .github/workflows/vulnerable-ci.yaml insecure pipeline anti-patterns
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=false

03. 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:

  1. Pinning Dependencies and Base Images by Cryptographic Digest: Never rely solely on mutable tags (such as python:3.12-alpine or v4). 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.

  2. Securing CI Runner Workflows: Never combine pull_request_target triggers with checkouts of untrusted pull request code. When pull_request_target executes, 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.

  3. 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 to main. 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 with github/codeql-action/upload-sarif, without which the results never appear under Security → Code scanning. The job-level permissions block replaces the workflow-level read-all for this job, so it must list the read permissions as well; on private repositories the job fails without them.

  4. 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.

YAML · .github/workflows/scorecard.yaml OpenSSF automated security assessment
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.sarif

04. Check your understanding

Practice check · 3 questions

Dependency confusion, install scripts and job permissions

Three questions on attacks and settings from the lesson.

Q1. How does an attacker execute a dependency confusion attack against an enterprise application, and what is the primary architectural mitigation?
Q2. Why run `npm ci --ignore-scripts` in CI?
Q3. The workflow sets `permissions: read-all`, yet the Scorecard job also lists `contents: read` and other reads. Why?
Practice only: not graded, not saved, not evidence.

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 .npmrc to 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 only contents: read (or permissions: {} if no job reads the repository), and grant each extra scope, such as id-token: write or security-events: write, only on the job that uses it. read-all is 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.

Sign in to mark reading complete

Prove this skill

6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check