Back to glossary

Build System

A build system turns source code into artifacts by running a graph of compile, generate, and package steps, including code shipped by dependencies.

Also known as build tool, build automation

A build system, also called a build tool, turns source code into deployable artifacts by running a graph of steps (generate, compile, link, package) in dependency order and rerunning only what changed. Make, Bazel, Gradle, and Cargo are build systems. Most also execute code shipped inside dependencies, which makes the build system a prime supply chain target.

The dependency part is what most teams miss. A build system is a code execution engine, and much of the code it executes was written by strangers. Cargo runs every dependency's build script on cargo build and even on cargo check. pip runs a package's build backend just to read the metadata of a source distribution. We think build-time execution of dependency code should be opt-in, as it has been in Go from the start and in npm since v12. Securing a build system mostly means controlling that execution: what runs, what it can reach, and whether anyone can check the output independently.

What is a build system in software development?

#

A build system in software development is a program that maps declared inputs to outputs through rules, then runs those rules in the order a dependency graph dictates. Each rule names its inputs (source files, headers, outputs of other rules), its outputs, and the command that turns one into the other. Here is the smallest useful example:

Makefile
app: main.o util.o
	cc -o app main.o util.o

main.o: main.c util.h
	cc -c main.c

util.o: util.c util.h
	cc -c util.c

Make reads this as a graph. app depends on two object files, and each object file depends on its sources. When util.h changes, Make rebuilds both object files and relinks app. When only main.c changes, util.o is left alone. Make decides staleness by comparing file modification times. Bazel keys its cache on content digests of every declared input, so identical inputs on different machines can share one cached result.

Incremental builds are only correct if the declared inputs are complete. Suppose a compiler reads an environment variable, a file in $HOME, or a URL that the rule never declared. The build system cannot see that input change, so the cache serves a stale result, and two machines build different artifacts from the same commit. A build with no undeclared inputs is called hermetic. Hermeticity started as a correctness property. It turns out to be the security property too, because undeclared inputs are exactly what a malicious build step reaches for.

What the build graph tracks vs. what the build touches

Declared graph: hashed, cached, reviewed

  • app
  • ↳main.o ← main.c, util.h
  • ↳util.o ← util.c, util.h
  • ↳libdep.a ← dep 1.4.2 (lockfile pin)
  • ↳dep's build hook runs here

Undeclared inputs: invisible to cache and review

  • Environment: GITHUB_TOKEN, AWS_*, NPM_TOKEN
  • Files in $HOME: ~/.ssh, ~/.cargo/credentials.toml
  • The network: any URL a hook fetches
  • Host tools and headers in /usr
  • Leftovers from earlier jobs on a reused runner

A hermetic build has nothing in the dashed panel. By default, Cargo, Gradle, Maven, and pip (for source distributions) leave every item in it reachable from every dependency's build hook.

The figure contrasts two sets of inputs. The declared graph is what the build system hashes, caches, and what a reviewer sees in a diff: app built from main.o and util.o, each from its .c file and util.h, plus a static library from a dependency pinned at version 1.4.2 in the lockfile, whose build hook runs during the build. The undeclared inputs are invisible to both the cache and the reviewer: environment variables such as GITHUB_TOKEN, AWS_*, and NPM_TOKEN; files in the home directory such as ~/.ssh and ~/.cargo/credentials.toml; any URL a hook fetches over the network; host tools and headers in /usr; and files left behind by earlier jobs on a reused runner. A hermetic build has none of these. By default, Cargo, Gradle, Maven, and pip (for source distributions) leave all of them reachable from every dependency's build hook.

Build automation is the practice of running these steps without a human. The build system is the engine, and continuous integration is the service that runs it on every commit. Language toolchains bundle a build system with a package manager: Cargo for Rust, Gradle and Maven for the JVM, and PEP 517 build backends such as setuptools for Python. That bundling is where the security problem starts, because the package manager decides which third-party code enters the graph and the build system then runs it.

What code runs during a build?

#

A build runs three kinds of code: your own, the toolchain's, and hooks shipped inside dependencies. The third kind turns adding a dependency into code execution on a developer laptop or CI runner, before any application code imports it. The Cargo book states the Rust rule directly: a file named build.rs in a package root makes Cargo "compile that script and execute it just before building the package." The only stated limit is a convention that scripts should not write outside OUT_DIR. Nothing enforces it.

We reproduced this with a two-crate workspace. The dependency's build script records who ran it and what it could see:

Rust
use std::{env, fs};

fn main() {
    let who = env::var("USER").unwrap_or_default();
    let home = env::var("HOME").unwrap_or_default();
    let ci_token = env::var("GITHUB_TOKEN").is_ok();
    fs::write("/tmp/build-rs-was-here",
        format!("user={who} home={home} github_token_visible={ci_token}\n")).unwrap();
    println!("cargo:warning=build.rs ran as {who}, HOME={home}");
}

The application lists the crate as a dependency and never calls it. Its main.rs is the default println!("Hello, world!"). Then we ran the cheapest Cargo command there is, which only type-checks:

Bash
$ cargo check
     Locking 1 package to latest Rust 1.97.0 compatible version
   Compiling innocent-dep v0.1.0 (/home/dev/innocent-dep)
warning: innocent-dep@0.1.0: build.rs ran as dev, HOME=/home/dev
    Checking app v0.1.0 (/home/dev/app)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.26s
$ cat /tmp/build-rs-was-here
user=dev home=/home/dev github_token_visible=true

The build script ran as the developer, with the developer's home directory and environment, including the token. Editors do the same thing without a command. rust-analyzer's documented default is to "run build scripts (build.rs) for more precise code analysis," and procedural macros are on by default too. Opening a Rust project in an editor runs build scripts from every crate in its graph.

Python has the same property, in a less obvious place. We built a source distribution whose setup.py writes a marker file, then asked pip only to download it:

Bash
$ pip download --find-links dist --no-deps -d dl innocent_dep
Processing ./dist/innocent_dep-1.0.0.tar.gz
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
  Preparing metadata (pyproject.toml): started
  Preparing metadata (pyproject.toml): finished with status 'done'
Saved ./dl/innocent_dep-1.0.0.tar.gz
Successfully downloaded innocent_dep
$ cat /tmp/setup-py-was-here
user=dev cwd=/tmp/pip-download-pbidqp4e/innocent-dep_4ebb040f4ec148df9f1973f38febbc34

pip download installs nothing, yet it executed setup.py. pip needs a package's metadata to resolve dependencies, and for an sdist the only way to get it is to ask the PEP 517 build backend, which runs the project's code. With --only-binary :all:, pip refused the sdist and nothing ran. We ran both demos with Cargo 1.97.0 and pip 26.2.1 in November 2026.

npm moved the other way. npm v12, generally available since July 2026, no longer runs dependency install scripts unless they are allowed. The block includes the implicit node-gyp rebuild npm triggers for any package that ships a binding.gyp. pnpm made the same change earlier, when pnpm 10.0.0 blocked lifecycle scripts by default.

Go never had the hook. Filippo Valsorda's post on Go's supply chain design calls it an explicit goal "that neither fetching nor building code will let that code execute, even if it is untrusted and malicious." We confirmed it: a dependency with a //go:generate directive and a panicking init() built cleanly, and the generate command never ran. The guarantee has had bugs. CVE-2023-29404 let crafted #cgo LDFLAGS execute code at build time until Go 1.19.10 and 1.20.5.

EcosystemDependency code that runs at build or install timeDefault as of November 2026Off switch
npmpreinstall, install, and postinstall scripts; implicit node-gyp rebuild for packages with binding.gypBlocked since npm v12 (July 2026) and pnpm 10.0.0allowScripts allowlist for packages that need it
Python (pip)The PEP 517 build backend, including setup.py, for any sdist, on pip install and pip downloadRuns whenever no compatible wheel exists--only-binary :all:, which also rejects sdist-only packages
Rust (Cargo)build.rs and procedural macros of every crate in the graph, on cargo build and cargo checkRunsNone in Cargo
JVM (Gradle, Maven)Build plugins and buildscript dependencies, as code inside the build JVMRunsNone; pin and verify plugin versions
GoNone; go build compiles module code but does not execute itNever runs, by designNot needed

Our verdict: Go and npm v12 have the right default. Cargo and pip are the gaps. Cargo has no switch at all, and pip's switch also breaks every package that publishes only a source distribution.

Where do build systems get compromised?

#

Build system compromises enter at two points: the inputs a build consumes and the platform it runs on. Four well-documented incidents cover both, and in each one the malicious artifact shipped under the project's own identity.

Two entry points, four incidents, one trusted identity

  1. Source in version control

    What reviewers read. None of the four incidents below put readable malicious code here.

  2. Build inputs

    Resolved dependencies, release tarballs, downloaded tools.

    2026arrayref 0.3.10 adds proc-macro1, whose build.rs fetches and runs a backdoor during cargo build. 2024xz 5.6.0 tarball ships a modified build-to-host.m4 that exists nowhere in git.
  3. Build platform

    Build server, CI runner, caches.

    2020SUNSPOT swaps InventoryManager.cs while MsBuild.exe runs, then restores it. 2024Ultralytics release job restores a CI cache entry poisoned from a fork.
  4. Sign and attest

    Every artifact above shipped under the project's own identity
  5. Registry and users

    Downstream builds pull it in through routine updates.

Entry pointIncidentWhat changedReadable in version control?
Build inputsarrayref compromise, August 2026arrayref 0.3.10 added a proc-macro1 dependency whose build.rs downloaded and ran a backdoor during cargo buildNo
Build inputsxz utils backdoor, March 2024Release tarballs for 5.6.0 and 5.6.1 carried a modified build-to-host.m4 absent from gitNo; the payload sat in binary test files
Build platformSolarWinds Orion, 2020SUNSPOT replaced InventoryManager.cs while MsBuild.exe ran, then restored itNo
Build platformUltralytics, December 2024The release workflow restored a GitHub Actions cache entry poisoned from a forkNo

All four artifacts went out through the project's legitimate channel: the maintainer's crates.io account, the maintainer's release tarballs, SolarWinds' signed update, and Ultralytics' trusted publisher with valid attestations. The pipeline's identity checks passed every time.

Malicious inputs: the arrayref compromise

#

On August 20, 2026, someone holding a maintainer's credentials republished three crates.io packages: arrayref 0.3.10, internment 0.8.7, and append-only-vec 0.1.9. The arrayref compromise added one line to each manifest:

TOML, also INI
proc-macro1 = "1.0.107"

proc-macro1 was a typosquat of the widely used proc-macro2 crate, with copied source and documentation as camouflage. The library code was inert. Its build.rs detected the OS and architecture, disabled TLS certificate verification, downloaded a platform-specific backdoor, and launched it detached from Cargo. The application never had to import anything. The attacker also yanked older legitimate arrayref releases, which steered new resolutions toward 0.3.10.

The Rust Security Response Team reports that the three malicious versions were online for 86, 90, and 107 minutes. Fast removal does not help a machine that resolved one in that window, because the payload ran at compile time. RustSec counted roughly 152 million downloads for the previous clean arrayref release, which shows how many build graphs sat one cargo update away from the new version.

Compromised platform: SolarWinds and Ultralytics

#

The SolarWinds Orion compromise never touched the repository. CrowdStrike's analysis of SUNSPOT, the implant on SolarWinds' build server, shows it checked running processes every second for MsBuild.exe. When an Orion build started, SUNSPOT verified MD5 hashes of the target, swapped InventoryManager.cs for a backdoored copy, and restored the original after MSBuild exited. The source tree stayed clean and the output carried SolarWinds' code signature. CrowdStrike dates the implant's build to February 20, 2020.

The Ultralytics compromise in December 2024 reached the platform through the CI cache instead. A pull_request_target workflow let a fork write a poisoned GitHub Actions cache entry, and the release workflow later restored it and built from it. Version 8.3.41 shipped a crypto miner to PyPI and stayed up for about 12 hours, with valid attestations.

Inputs outside version control: the xz utils backdoor

#

The xz utils backdoor (CVE-2024-3094) used the build system itself as the loader. Andres Freund's original disclosure found that the 5.6.0 and 5.6.1 release tarballs carried a modified m4/build-to-host.m4, and that the injected line "is not in the upstream source of build-to-host, nor is build-to-host used by xz in git." During configure, that line extracted a payload hidden in binary test files and patched liblzma. It fired only on x86-64 Linux, with gcc and the GNU linker, inside a Debian or RPM package build. Reviewers reading git saw binary fixtures. Distribution build farms ran the loader.

How do you secure a build system?

#

You secure a build system by limiting what code it runs, what that code can reach, and how much an attacker gains if something runs anyway. No single control covers both entry points, so the order matters. These are the controls we recommend, cheapest first, with what each one costs.

Take secrets and persistence out of the build

#

Run every build on an ephemeral runner that is destroyed afterward. Give the build job no publishing credential, and publish from a separate job that takes the build output as an artifact and runs no project code. On GitHub Actions, set cache-mode: none on release jobs. These steps line up with SLSA Build L3, which requires that runs cannot influence one another and that build steps cannot reach the signing key. Ephemeral runners deny an implant like SUNSPOT a persistent home, and cache-mode: none on the release job closes the path Ultralytics was attacked through. They do not stop a malicious build step from writing itself into the artifact.

Turn off dependency build hooks where the tool allows it

#

Keep npm v12's allowScripts default and allowlist only packages that compile native code. Use pip install --only-binary :all: in CI. The cost is an allowlist to maintain and, for pip, packages that cannot be installed at all. Cargo offers no equivalent, which is why the next control matters more for Rust.

Slow down intake

#

A committed Cargo.lock kept existing builds on arrayref 0.3.9 until someone ran cargo update. A dependency cooldown covers that update. Rust 1.100 adds a minimum publish age to Cargo, scheduled to ship November 12, 2026 and off by default. A one-day cooldown would have skipped all three arrayref releases. Two gaps remain. By default, cargo install ignores the packaged Cargo.lock, and the cooldown does not apply to it. And malware that evades detection for longer than the cooldown passes straight through.

Make builds hermetic, then isolate them

#

Declaring every input and fetching dependencies before the build, then running the build with no network, empties the dashed panel in the first figure. Bazel's sandbox enforces declared inputs, but its documentation is clear that "sandboxing doesn't hide the host environment in any way." Treat it as a correctness tool. The security boundary is a container or VM with no credentials and no outbound network. The cost is real engineering time and slower, less cached builds.

Analyze packages before they enter the graph

#

A malicious build.rs is visible in the package before it runs. Socket's Rust analysis flags "malicious or risky build scripts that execute during compilation," and our AI Scanner flagged proc-macro1 at 07:29:50 UTC on the day of the arrayref attack. This works on package contents, not metadata, so it catches what a lockfile faithfully pins. It does not catch a payload with no detectable signal, which is why it sits alongside isolation rather than replacing it.

Verify outputs independently

#

A build is reproducible if any party can recreate bit-for-bit identical artifacts from the same source, environment, and instructions. An independent rebuild exposes platform tampering such as SUNSPOT or a poisoned cache. It does not expose xz, because rebuilders start from the same poisoned tarball. Adoption is thin. When vlt tested 5,000 high-impact npm packages, it found 5.78% were reproducible, against 3.72% that had published provenance.

Build security controls compared

#
ControlStopsMissesCost
Ephemeral runner, no secrets in build job, separate publish jobPersistence like SUNSPOT, token theft, cache poisoning into releasesA build step that writes itself into the artifactLow
Dependency build hooks offInstall-time and build-time payloadsCargo (no switch), code that runs when the app runsAllowlist upkeep; sdist-only packages fail under pip
Lockfile plus cooldownMalicious versions in their first hours, like arrayref (86 to 107 minutes)cargo install, git dependencies, slow-detected malwareFixes arrive later
Hermetic, network-off buildExfiltration and fetches from undeclared hostsMalicious code that uses declared inputsHigh
Pre-install package analysisKnown-malicious and suspicious build scriptsPayloads with no detectable signalTriage time
Provenance (SLSA Build L2 or L3)Artifacts that did not come from the claimed pipelineMalicious inputs, compromised maintainersLow on hosted CI
Reproducible buildsBuild platform tamperingMalicious source or tarballsHigh; few packages qualify

Our verdict: start with the first three rows. They are cheap, and together they would have stopped the cache-poisoned Ultralytics releases and kept a cooled-down resolver off the malicious arrayref versions. Add package analysis where Cargo or pip leaves build hooks on. Treat provenance as an audit trail, not a trust signal.

Provenance proves where a build ran, not what it ran

#

Build provenance is a signed record of which platform built an artifact, from which source, with which top-level inputs. SLSA's Build track grades it in three levels: L1 means provenance exists, L2 means a hosted platform generates and signs it, and L3 adds isolation between runs and keeps the signing key away from user-defined build steps. The SLSA v1.2 specification is candid about the ceiling. Build L3 isolation "is limited to ensuring that a well-intentioned build runs securely."

SLSA's own wording is the whole problem with treating provenance as a safety signal. Ultralytics 8.3.41 carried valid attestations because the compromised workflow really did build it. A malicious build.rs runs inside the isolated build, so the provenance faithfully records a backdoored artifact. The arrayref versions came from the maintainer's real account, so any identity check would have passed. Provenance tells you which pipeline to investigate after an incident. It does not tell you whether to install.

Build-time execution should be opt-in

#

Go shows that a mainstream toolchain can make fetching and building inert. npm reversed its own default in July 2026. Cargo still runs a dependency's build script whenever it builds that crate, and has no switch to stop it. Build scripts have real uses: compiling bundled C libraries, generating bindings, probing the host. A per-crate allowlist, like npm's allowScripts, would keep those uses and make the rest fail closed. Until Cargo ships one, a Rust build is only as trustworthy as the least-reviewed crate in its graph, running with everything the build machine can reach.