Back to glossary

Threat Modeling

Threat modeling is analyzing a model of a system, such as a data flow diagram, to find what can go wrong and decide which controls to build.

Also known as Threat Analysis, STRIDE Threat Modeling

Threat modeling, also called threat analysis, is the practice of analyzing a model of a system, typically a data flow diagram with trust boundaries, to find what can go wrong before an attacker does. Teams enumerate threats with a framework like STRIDE, then choose controls. Done honestly, it exposes the boundary most models skip: dependency installation.

The artifact the exercise produces is a threat model. The Threat Modeling Manifesto gives the shortest accurate definition: "Threat modeling is analyzing representations of a system to highlight concerns about security and privacy characteristics." The representation is usually a diagram of processes, data stores, external entities, and the data flows between them. The analysis concentrates on the lines where data crosses from one level of trust to another.

The most important trust boundary in a modern application is one that rarely appears on the diagram: npm install, pip install, and their equivalents. On November 7, 2026, we installed four common npm packages into an empty project. We got 76 packages, publishable by 52 distinct npm accounts, and two of those packages tried to run code at install time. Every one of those accounts is an external entity in your system, whether or not you drew it. Our position is that a threat model without a trust boundary around dependency installation is incomplete. Almost every worm and credential stealer that hit npm since late 2025 ran at install time, before any application code loaded (npm v12 coverage).

What is threat modeling in cybersecurity?

#

Threat modeling in cybersecurity is a design-time review that answers four questions about a system, as framed by the Manifesto:

  1. What are we working on?
  2. What can go wrong?
  3. What are we going to do about it?
  4. Did we do a good enough job?

The first question produces the model. The usual representation is a data flow diagram (DFD) with five element types: external entities (people or systems you do not control), processes (code that runs), data stores, data flows, and trust boundaries. A trust boundary is any line where the principal controlling the data changes: browser to server, service to database, your network to a vendor's API.

Trust boundaries carry the analysis because assumptions change there. Inside a boundary, a process can assume its inputs came from code it trusts. Across a boundary, that assumption is exactly what an attacker attacks. The second question is answered by walking every element and every boundary-crossing flow and asking what an attacker could do to it. The third question turns each credible threat into a decision: eliminate it, reduce it, transfer it, or accept it. The fourth checks the work, and on a living system it never stops.

Threat modeling is distinct from adjacent practices. A penetration test probes a built system; a threat model reasons about a design, ideally before it is built. A vulnerability scan finds known flaws in code that exists; a threat model finds the classes of flaw your design invites. NIST SP 800-218, the Secure Software Development Framework, names it in practice PW.1.1: "Use forms of risk modeling – such as threat modeling, attack modeling, or attack surface mapping" to assess software risk. The output is a map of your attack surface annotated with decisions.

What is STRIDE in threat modeling?

#

STRIDE is a mnemonic for six threat categories, each the violation of one security property. Loren Kohnfelder and Praerit Garg created it at Microsoft in an internal paper, "The Threats to Our Products," dated April 1, 1999 (Adam Shostack, Dark Reading). Microsoft's training material pairs each category with the control it defeats:

ThreatProperty violatedClassic exampleSupply chain example
SpoofingAuthenticationStolen session cookieA typosquatted package name resolves instead of the real one
TamperingIntegrityModified database rowA hijacked maintainer account publishes a malicious version
RepudiationNon-repudiationAdmin action with no audit logA published version cannot be tied to any source commit or build
Information disclosureConfidentialityReadable backup bucketAn install script reads ~/.npmrc and CI secrets
Denial of serviceAvailabilityRequest floodA depended-on package disappears from the registry
Elevation of privilegeAuthorizationUser reaches admin APIA library executes shell commands with the developer's privileges

STRIDE is used by walking the DFD. For each process, data store, external entity, and flow that crosses a trust boundary, you ask which of the six categories applies and write down each credible threat. Kohnfelder and Garg's paper put it plainly: "Identifying the threats is the first step in a proactive security analysis process." STRIDE finds threats; it does not rank them. Prioritization comes from likelihood, impact, and evidence of what attackers actually do.

STRIDE's weakness is that it only finds threats against elements you drew. If the diagram shows your service as one box labeled "API," STRIDE will never ask who can modify the 76 packages inside that box.

STRIDE vs PASTA vs attack trees vs LINDDUN

#

Several methods compete for the "what can go wrong" step. They differ in what they start from and how much ceremony they require.

MethodStarts fromOutputCostBest fit
STRIDEThe DFD, element by elementA list of threats per elementLow; one engineering session per featureDesign reviews run by the engineers who build the system
PASTABusiness objectives, through seven stagesRisk-ranked threats tied to business impactHigh; seven stages with security and business stakeholdersRegulated organizations that must justify spend per risk
Attack treesOne attacker goal as the root nodeDecomposed paths to that goalMedium; deep but narrowA single high-value goal, such as "publish a malicious release of our package"
LINDDUNThe DFD, with privacy categoriesPrivacy threats such as linking and identifying usersLow to mediumSystems that process personal data

Verdict: use STRIDE on a DFD as the default, because it is cheap enough to repeat on every significant design change. Add an attack tree for the one or two goals that would end your company, and your release pipeline should be one of them. Reach for PASTA when you must rank risks in business terms for an audit or a budget. Run LINDDUN alongside STRIDE whenever personal data flows through the system. MITRE ATT&CK is not a modeling method; it is a catalog of observed attacker techniques, useful as a checklist when answering "what can go wrong."

Where threat models stop: the package manager

#

Most threat models treat dependencies as part of the application box. To see why that is wrong, look at what an install actually does.

npm install reads version ranges from package.json, asks the registry for each package's metadata, picks versions, downloads tarballs, and unpacks them into node_modules. Historically it then ran each dependency's install scripts (preinstall, install, and postinstall), plus an implicit node-gyp rebuild for any package that ships a binding.gyp. Those scripts run with the full privileges of whoever typed the command: a developer's home directory, SSH keys, and cloud credentials, or a CI runner's tokens. The design made sense when it was made. Native addons need a compile step on the target machine, and running it automatically saved every user a manual build.

The trust assumption is that a dependency behaves like your own code. It is not your code. It was written and published by accounts outside your organization, and a fresh resolution can pick up a version none of your engineers has seen. Here is what four direct dependencies pulled in on November 7, 2026, with npm 12.2.2:

Shell Session
$ npm install express@5 bcrypt@6 esbuild sharp
added 76 packages, and audited 77 packages in 1s
npm warn install-scripts 2 packages had install scripts blocked because they are not covered by allowScripts:
npm warn install-scripts   bcrypt@6.0.0 (install: node-gyp-build)
npm warn install-scripts   esbuild@0.28.2 (postinstall: node install.js)

The lockfile records which packages want to execute at install time:

JSON
"node_modules/esbuild": {
  "version": "0.28.2",
  "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.2.tgz",
  "integrity": "sha512-HKVLS8dvII+xoKW9kmqxbRKrnWEXfJJr/FZhhJmiqIB0e053QNYFqOBouTMO/k5sID4MvCiUCvv8b9M4h32wIA==",
  "hasInstallScript": true,
  "license": "MIT"
}

And this script counts the external entities. It reads the lockfile, asks the registry who maintains each installed package, and prints the number of accounts that can publish the next version of something in your tree:

JavaScript
// Who can publish code that lands in this install?
import { readFileSync, existsSync } from 'node:fs';
const lock = JSON.parse(readFileSync('package-lock.json', 'utf8'));
const names = Object.keys(lock.packages)
  .filter((path) => path && existsSync(path)) // skip optional deps not installed here
  .map((path) => path.split('node_modules/').pop());
const accounts = new Set();
for (const name of new Set(names)) {
  const res = await fetch(`https://registry.npmjs.org/${name.replace('/', '%2f')}`);
  const { maintainers = [] } = await res.json();
  for (const m of maintainers) accounts.add(m.name);
}
console.log(`${names.length} installed packages, ${accounts.size} npm accounts can publish them`);
Shell Session
$ node publishers.mjs
76 installed packages, 52 npm accounts can publish them

Fifty-two npm accounts can change code that runs inside this project. Only 13 of the 76 installed versions carry a provenance attestation linking the tarball to a source repository and build. None of this appears on a diagram that draws the service as one box. Transitive dependencies make the count grow faster than anyone reviews it: the project's package.json names four packages.

How do you threat model your dependencies?

#

You threat model your dependencies by drawing the install path as its own data flow and running STRIDE across it. The path has three regions: the publisher accounts and the registry, which you do not control; the trust boundary, which is the moment of resolution and install; and your machines, where install-time and import-time code runs next to your secrets.

THIRD PARTIES · OUTSIDE YOUR CONTROLMaintainer accounts52 can publish into our 76-package demopublishTRRegistryregistry.npmjs.orgSDmetadata + tarballTRUST BOUNDARY: npm installYOUR MACHINES · LAPTOP OR CI RUNNERPackage managerresolves, unpacks into node_modulesscripts run as youESecrets in reach~/.npmrc · GITHUB_TOKENcloud creds · SSH keysIbuildBuild artifactships to productionS spoofing · T tampering · R repudiationI information disclosure · D denial of serviceE elevation of privilege

The diagram above has two zones separated by a trust boundary labeled "npm install". Outside the boundary: maintainer accounts (52 in our demo) publish to the registry, registry.npmjs.org. Tampering and repudiation threats sit on the publish flow; spoofing and denial-of-service threats sit on the registry and the name resolution it performs. Inside the boundary: the package manager on a laptop or CI runner downloads tarballs and runs install scripts, which is the elevation-of-privilege point. Those scripts can read secrets such as ~/.npmrc, GITHUB_TOKEN, cloud credentials, and SSH keys, which is the information-disclosure point. The build then ships the result to production. Each threat maps to an incident:

Spoofing. The package you get is not the package you meant. Typosquatting registers names one keystroke away from popular ones. Dependency confusion publishes a public package with the same name as a private one and relies on the resolver preferring the public registry. AI coding tools add a new variant: in a study of five frontier LLMs, 53 package names the models repeatedly invented were still unregistered as of April 2026. The question for your model: what proves that a name resolves to the publisher you intended?

Tampering. The package is the real one, and its contents are hostile. Maintainer account takeover is the dominant form. In the axios compromise of March 2026, an attacker socially engineered the lead maintainer, took over his npm access, and published axios@1.14.1 and axios@0.30.4. The malicious releases added a dependency, plain-crypto-js@4.2.1, whose postinstall hook fetched a platform-specific remote access trojan. The malicious versions were live for about three hours (GitHub Actions hardening guide).

Repudiation. A version exists on the registry, and nothing ties it to a commit, a build, or an accountable publisher. The malicious axios release had no matching tag in the project's GitHub repository. Package provenance and trusted publishing record which repository, commit, and workflow produced a tarball, which turns "who built this?" into a verifiable claim. Provenance does not prove the publisher was honest. Lead maintainer Jason Saayman said the attacker's access would likely have been "complete irrespective of what was setup" (Socket).

Information disclosure. Install-time code reads whatever the installing user can read. The Shai-Hulud worm, first seen on September 14, 2025, ran TruffleHog from a lifecycle script to find npm, GitHub, and cloud credentials, then used stolen npm tokens to republish infected versions of its victims' packages. Socket's indicator list for that wave counted 526 packages.

Denial of service. A dependency stops being available, or turns on its host. When left-pad was unpublished in 2016, 11 lines of code disappeared from builds across the ecosystem because Babel depended on them transitively. npm tightened its unpublish rules afterward. A malicious package can do worse: in the Nx s1ngularity compromise, the payload appended sudo shutdown -h 0 to ~/.bashrc and ~/.zshrc, so every new shell powered off the machine.

Elevation of privilege. Code you imported as a library gets the authority of a shell. The same Nx compromise, in August 2025, shipped a telemetry.js payload inside a popular build tool. It invoked locally installed AI coding CLIs (claude, gemini, and q) to inventory files worth stealing, then exfiltrated tokens, SSH keys, and .env files to public repositories prefixed s1ngularity-repository in each victim's own GitHub account. Attackers also route around script fields: the Miasma "Phantom Gyp" waves used a binding.gyp file so node-gyp would run node index.js with no preinstall or postinstall entry at all.

The same walk, condensed into one row per STRIDE category:

STRIDEElement on the install pathIncidentControl that answers it
SRegistry name resolutionTyposquatting, dependency confusion, slopsquattingScoped private registries, name review on new dependencies
TPublish flow from maintainer accountaxios 1.14.1 and 0.30.4, March 2026Release-age cooldown, content analysis before install
RPublish flow, missing source linkaxios release with no matching git tagProvenance and trusted publishing, verified at install
IInstall scripts reading local secretsShai-Hulud, September 2025No secrets in install jobs; scripts off by default
DRegistry availability; host integrityleft-pad, 2016; Nx shutdown payloadRegistry mirror or proxy; scripts off by default
EInstall and import-time executionNx s1ngularity, August 2025; Phantom GypScript allowlists pinned to versions, sandboxed installs

Which controls answer which threats, and what they miss

#

Every control below covers some STRIDE categories and leaves others open. A threat model is useful precisely because it makes the gaps explicit.

Install scripts off by default. As of npm v12, released July 8, 2026, dependency lifecycle scripts and the implicit node-gyp rebuild do not run unless allowed. pnpm made the same change in version 10. Approval in npm 12.2.2 writes a version-pinned entry, so a new version of an approved package must be approved again:

JSON
{
  "allowScripts": {
    "esbuild@0.28.2": true
  }
}

This closes the install-time path for E and I. It costs friction: native modules fail at runtime, not install time, when their build was skipped, and the default is a warning unless you set strict-allow-scripts=true. It does not cover code that runs when the package is first imported, and an attacker who loses the install hook can move the payload there. And the approval prompt tells you that a script exists, not what it does.

Release-age cooldown. A dependency cooldown such as npm's min-release-age, added in npm 11.10.0, refuses versions younger than N days during resolution. Most malicious versions are removed within hours, so even a one-day cooldown would have kept the three-hour axios window out of your lockfile. It answers T for fast, noisy compromises. It does nothing against a payload that waits out the window, it does not apply under npm ci, and your update bot needs its own setting.

Lockfiles and npm ci. A lockfile makes existing installs deterministic. It does not make new installs safe, and code fetched through npx or a global install never appears in a project lockfile (axios blast radius analysis). Treat a clean lockfile as evidence about one project, not proof of exposure across your machines.

Provenance and trusted publishing. These answer R and raise the cost of stolen long-lived tokens. They are necessary and not sufficient: a compromised maintainer publishes through the legitimate pipeline and gets a valid attestation.

Least privilege at install. Run installs in a job that holds no publish token and no production credential, and publish from a separate job that runs no project code (GitHub Actions hardening guide). This shrinks what I and E can reach. It does not stop the malicious code from shipping in your build output.

Content analysis before install. Metadata says what a package claims; the tarball says what it does. Socket Firewall runs as a network proxy in front of npm, pip, uv, cargo, yarn, and pnpm, checks each requested package against Socket's analysis, and blocks confirmed malware before it reaches disk. It answers T, S, and E for known-bad packages. It blocks only confirmed malware, so a package flagged by AI analysis alone produces a warning, and packages already in the local cache are never checked.

CVE scanning. Vulnerability databases answer none of the six threats above in time. Malware does not get a CVE. Malware advisories do get published, but only after someone detects the package, reports it, and the entry propagates, and that pipeline can take longer than a three-hour compromise lasts.

The fourth question never closes

#

A dependency threat model has done a good enough job only if it is re-checked on every lockfile change. A threat model is a document reviewed when the design changes. A dependency tree changes on every resolution: a new transitive package, a new maintainer added to an existing one, a new install script in a patch release. The 52 accounts in our demo are a measurement for one day, not a property of the project.

The fix is to make the fourth question mechanical. Every lockfile change is a design change to the install path, and it can be checked like one: which packages are new, which gained an install script, which added a maintainer, which lost provenance they used to have. Each answer maps back to a STRIDE row above. The OWASP Top 10 for 2025 added Software Supply Chain Failures as a new category, and 50% of community survey respondents ranked it their top concern. The industry has accepted that dependencies belong in the threat model. Most threat models still draw them as part of the app.