Blog / A03:2021 Injection
A03:2021 · Injection

An unquoted variable in your test script is a code path

A test script dropped an environment variable into a command without quotes. Word splitting turns its value into extra arguments, and the right value loads attacker-chosen code during CI.

env var set by acaller or…expanded unquotedin a scriptshell splits itinto argumentsextra runneroptions injectedattacker codeloaded during…ATTACKER INPUTIMPACTcode path executes
Attack path · env var set by a caller or CI config → expanded unquoted in a script → shell splits it into arguments → extra runner options injected → attacker code loaded during the run

A test script dropped an environment variable into a command without quotes. Word splitting turns its value into extra arguments, and the right value loads attacker-chosen code during CI.

What goes wrong

A package script built a test command by expanding an environment variable inline, without quotes. The intent was to let someone pick the reporter. The shell does not know that is the intent.

An unquoted expansion is subject to word splitting and glob expansion. Whatever the variable holds gets chopped on whitespace into separate arguments. Set it to a reporter name followed by an option that requires a file, and you have injected an extra flag that tells the test runner to load a script of your choosing. Now arbitrary code runs inside the test process, with that process's access to your source checkout and any secrets the build holds.

CI is a high-value target precisely because it holds credentials and runs semi-trusted input on a schedule. Quote your expansions. Better yet, do not build shell commands out of environment variables at all. Pass arguments as an array to the runner so the shell never gets a vote.

The pattern

Vulnerable
# a package script, run through a shell
test-cmd: runner --reporter $RUN_OPTS ./tests

# RUN_OPTS = "spec --require ./evil.js"
# the shell splits it on the space into two arguments,
# so the runner loads evil.js before any test runs
Hardened
# option 1: quote the expansion
test-cmd: runner --reporter "$RUN_OPTS" ./tests

# option 2 (better): skip the shell entirely
spawn("runner",
      ["--reporter", env.RUN_OPTS, "./tests"],
      { shell: false })
How the pipeline adjudicated itPROVEN
ABCDEFGH

Every gate held. The exploit path was reproduced against a negative control, the impact was calibrated, and the finding was signed report-ready.

Ed25519 · per-tenant signing key · gate ledger A–H · verify offline against the published payload hash

Why it matters to you

If an attacker can influence that variable through a pull request, a fork's CI config, or a compromised dependency's setup, they run code in your build. Build compromise is how supply-chain attacks start, and it usually rides in on something as dull as an unquoted variable in a script nobody has read in years.

Check your own code