3.2 Agile, DevSecOps and building a threat modelling programme
In this lesson you will:
- Fit threat modelling into agile cadences (epic, story and continuous) without becoming a bottleneck.
- Explain threat modelling as code, and what automation can and cannot do.
- Compare common threat modelling tools and choose one for a team.
- Design a programme with risk-based triage, security champions, templates and metrics.
- Assess a programme's maturity and decide on the next step.
Opening case: the security team as a queue
After the auditor's visit, Kestrel's leadership mandates "a threat model for every feature". There are twelve delivery squads and a security team of three. Within a month, the security team has a backlog of 34 threat model requests, squads are waiting up to three weeks for a session, and some have started labelling features as "minor" to avoid the queue.
By the end of this section you will be able to redesign this so that threat modelling scales with twelve squads, and the security team spends its time where risk is highest.
Threat modelling in agile delivery
Agile teams deliver in small increments, often releasing several times a week. A two-day threat modelling workshop per release does not fit. The answer is not to skip threat modelling but to match its depth to the size and risk of the change, at three cadences.
Per epic or release (60–120 minutes). When an epic introduces a new capability, run a full session: refresh the Level-1 DFD, apply STRIDE to the new boundary crossings, rate threats and create mitigation stories. This is where most serious design flaws are caught.
Per story (5–10 minutes). During backlog refinement, ask a short set of questions for each story that touches security-relevant areas. A useful set, sometimes called a security story check:
- Does this story add or change an entry point (API, UI, file, webhook, message)?
- Does it add or change a data store, or the sensitivity of data held?
- Does it change who can do what (roles, permissions, authentication)?
- Does it add a dependency or a third party?
- Does it add or change an AI capability (model, prompt, retrieval source, tool)?
If all the answers are no, move on. If any answer is yes, spend a few minutes on "what could go wrong?" and add security acceptance criteria to the story, or escalate to an epic-level session if the change is bigger than it looked.
Continuously. Keep the threat model in the repository or a tool next to the code, review its changes in pull requests, track open threats in the backlog, and report metrics. This is where automation helps most.
Practitioner tip. Put the story check into the team's definition of ready. A story is not ready for a sprint until the five questions have been answered. It takes seconds for most stories and catches the ones that need more.
Security acceptance criteria
The output of a story-level check is usually one or more acceptance criteria, written so they can be tested:
- "Given a user of merchant A, when they request merchant B's settlement report, then the API returns 404 and logs
authz_denied." - "Given a payout account change, when it is saved, then the merchant's registered email and phone are notified and the next settlement to the new account is held for 24 hours."
- "Given more than 100 payment-link requests per minute from one merchant, then further requests return 429 for 60 seconds."
Threat modelling as code
Threat modelling as code describes the system model in a text format (Python, YAML or a domain-specific language) stored in the repository with the application. Tools then generate diagrams and candidate threats from it [4].
A minimal example in the style of OWASP pytm:
from pytm import TM, Actor, Server, Datastore, Dataflow, Boundary
tm = TM("Kestrel refunds")
internet = Boundary("Internet")
vpc = Boundary("Kestrel VPC")
merchant = Actor("Merchant user", inBoundary=internet)
gateway = Server("API gateway", inBoundary=vpc)
refunds = Server("Refund service", inBoundary=vpc)
ledger = Datastore("Refund ledger", inBoundary=vpc)
ledger.isEncrypted = True
Dataflow(merchant, gateway, "POST /refunds (HTTPS)")
Dataflow(gateway, refunds, "refund request (mTLS)")
Dataflow(refunds, ledger, "write refund")
tm.process()
Running this generates a DFD image and a list of candidate threats based on the elements' properties (for example, a flow across a boundary without encryption, or a data store without encryption at rest). Other tools in this space include Threagile (YAML models with risk rules) and the threat modelling features of commercial platforms.
What automation does well:
- Keeps the model in version control, so changes are reviewed in pull requests like code.
- Shows the diff: a pull request that adds a new flow across a boundary is visible to reviewers.
- Generates consistent baseline threats for common patterns (unencrypted flows, missing authentication).
- Can gate a pipeline: for example, fail the build if a new high-rated threat has no linked ticket.
What automation cannot do:
- Understand business logic. No rule engine knows that refunds must not exceed the original payment, or that only owners may change payout accounts.
- Find design flaws that arise from how features combine.
- Replace the conversation in which people with different knowledge challenge each other's assumptions.
The Threat Modeling Manifesto's value of "people and collaboration over processes, methodologies and tools" applies here. Use automation to keep models current and catch the obvious; keep people for the design flaws.
Tools
| Tool | Type | Notes |
|---|---|---|
| Whiteboard, draw.io, Miro | General diagramming | Fast and collaborative; threat list kept separately (sheet or tickets) |
| Microsoft Threat Modeling Tool | Free desktop tool | Draw a DFD; generates STRIDE threats per element from templates; Windows only |
| OWASP Threat Dragon | Free, open source | Web or desktop; DFDs with STRIDE, LINDDUN and other rule sets; models stored as JSON |
| OWASP pytm | Open source, code | Python models in the repo; generates DFDs, sequence diagrams and threats |
| Threagile | Open source, code | YAML models; risk rules; reports and diagrams |
| Commercial platforms | SaaS | Component libraries, automated threat generation, integrations with issue trackers, enterprise reporting |
Choose by team: a team that lives in pull requests may prefer pytm or Threagile; a mixed team with product owners may prefer a visual tool. The tool matters far less than the habit of using it. A threat list in a spreadsheet that is kept current beats an elaborate platform that is not.
Building a programme
A threat modelling programme is how an organisation makes threat modelling happen consistently across many teams. Its main design problem is the one in the opening case: there are always more changes than security experts.
Risk-based triage
Not every application needs the same depth. Classify applications (OWASP SAMM calls this an application risk profile) by factors such as data sensitivity, internet exposure, money movement, regulatory relevance and AI capability. Then set expectations by tier:
| Tier | Examples at Kestrel | Expectation |
|---|---|---|
| 1 — Critical | Payments, settlements, admin console, AI agents that act | Baseline model reviewed by the security team; epic-level sessions with a security engineer present; annual deep review |
| 2 — High | Merchant portal, partner API, AI support assistant | Team-run epic sessions with champion facilitation; security team reviews High findings |
| 3 — Standard | Internal reporting, marketing site | Story checks; team-run sessions for new interfaces; spot checks |
Security champions
Security champions are developers, testers or architects in each squad who receive extra training and act as the first line of security expertise: facilitating routine sessions, running story checks, keeping the model current and escalating to the security team when needed. Champions turn a central queue into distributed capability. They need time allocated (often 10–20% of their week), recognition, a community with other champions, and direct access to the security team.
Standard templates
Give teams a template so every model has the same parts: scope, DFD, assets, assumptions, threat register (ID, statement, STRIDE, location, existing controls, likelihood, impact, decision, owner, ticket), accepted risks and review date. Consistent structure makes models comparable and reviewable (Module 5 covers the report).
Training
Train in layers: a short awareness module for everyone in delivery (the four questions, STRIDE basics), hands-on training for champions (facilitating sessions with real systems, using games such as Elevation of Privilege), and deep training for security engineers (methods, AI threat modelling, reviewing others' models).
Metrics
Measure to improve, not to punish. Useful metrics include:
- Coverage: percentage of Tier 1 and Tier 2 applications with a model reviewed in the last 12 months.
- Freshness: median age of models since last update, compared with the last significant change.
- Flow: time from session request to session; time from High threat to fix.
- Effectiveness: proportion of pen-test and incident findings that were anticipated in the model (and analysis of those that were not).
- Health of the register: open High threats past SLA; accepted risks past expiry.
Avoid vanity metrics such as "number of threats found", which rewards long lists of trivial threats.
Maturity
Figure 3.5 summarises a typical maturity path. Most organisations start at Level 1 (ad hoc: experts threat model when asked) and the next step is almost always the same: an inventory of applications and a standard template. Moving from Level 2 to 3 usually requires champions and a link between threats and the backlog. Levels 4 and 5 are about measurement and feedback: using metrics, triggers, automation, incidents and red-team results to keep models current and improve the method itself.
The opening case, resolved
Kestrel replaced "a threat model for every feature by the security team" with:
- A three-tier application risk profile. Only Tier 1 epics need a security engineer in the room.
- Twelve trained security champions, one per squad, with 15% of their time allocated.
- The five-question story check in every squad's definition of ready.
- A standard template in the repository, and pytm models for the two Tier 1 platforms.
- Monthly metrics on coverage, freshness and High threats past SLA.
The queue disappeared within six weeks. The security team now spends its time on Tier 1 sessions, reviewing High findings and coaching champions, and the number of design flaws found before release roughly doubled, because many more changes were being looked at.
Check your understanding
1. A story says: "Add a CSV export of transactions to the merchant dashboard." Which story-check questions does it trigger, and what acceptance criterion would you add?
Answer: It adds an entry point (a new export endpoint) and changes data exposure (bulk data leaving the system). Criterion: "Given a user of merchant A, when they request an export, then only merchant A's transactions are included, values starting with =, +, - or @ are escaped to prevent formula injection, and the export is logged with user and row count."
2. A pipeline tool generates 60 threats automatically for a new service. Does the team still need a session?
Answer: Yes, for anything above routine risk. Automated tools generate baseline threats from element properties but cannot see business logic flaws or emergent design problems. The session should review the generated list (dismissing noise) and look for logic and design threats.
3. Which metric is MOST useful for judging whether threat modelling is effective, rather than just busy?
Answer: The proportion of pen-test and incident findings that the threat models had anticipated (and what the misses had in common).
Key takeaways
- Match depth to change: full sessions per epic, a five-question story check per story, continuous upkeep in the repository.
- Express mitigations as testable security acceptance criteria.
- Threat modelling as code (pytm, Threagile) keeps models versioned and visible in pull requests; it cannot replace human analysis of business logic.
- Scale with risk-based tiers, security champions with allocated time, templates, layered training and outcome-focused metrics.
- Maturity grows from ad hoc to defined (inventory, template, champions, backlog linkage) to measured and optimised (metrics, triggers, feedback from incidents).