Skip to content

feat(skills): add OWASP Threat Dragon export to security planning - #3159

Open
Will Velida (willvelida) wants to merge 8 commits into
microsoft:mainfrom
willvelida:velidawill/owasp-threat-dragon
Open

Will Velida (willvelida) wants to merge 8 commits into
microsoft:mainfrom
willvelida:velidawill/owasp-threat-dragon

Conversation

@willvelida

@willvelida Will Velida (willvelida) commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request

Description

Adds OWASP Threat Dragon v2.6.2 export to the security-planning skill as a sibling of the existing TM7 (Microsoft Threat Modeling Tool) export. The same YAML threat-model spec that produces a .tm7 file can now produce a Threat Dragon JSON model that opens directly in Threat Dragon. The design mirrors how the Security Planner already handles MTMT/TM7.

Generator and validator

  • generate_threat_dragon.py reuses load_spec, resolve_profile, and build_tm7_payload from generate_tm7.py, the same way generate_markdown.py does. Spec validation, trust-zone hierarchy, threat target resolution, and the deterministic layout come from TM7, so each representation becomes one Threat Dragon diagram drawn like its TM7 surface.
  • The mapping writes canvas labels, red outlines for open threats, dashed outlines for out-of-scope elements, and two-way arrowheads directly into the file, because Threat Dragon only derives them when a cell is edited.
  • validate_threat_dragon.py checks any model against a vendored, hash-pinned copy of the upstream v2.6.2 schema and the graph rules, with no new runtime dependency. Output is validated in a sibling temp file before an atomic replace. Exit codes follow the TM7 scripts: 0, 1 (invalid model), 2.
  • Generation fails closed on input Threat Dragon cannot represent, such as a trust_boundary_line element. With threat_generation_enabled: true, abuse-case threats are left out (they have no STRIDE type), and duplicate generated threats are emitted once.

Spec, agents, and instruction

  • Optional, vendor-neutral spec fields (owner, out_of_scope, bidirectional, public_network, encrypted, severity, likelihood, impact, risk) plus a namespaced export_options.threat_dragon block. TM7 ignores them; a test proves TM7 output is byte-identical with them present.
  • New threat-dragon-generation-workflow.instructions.md, mirroring the TM7 authorship-confirmation contract: a generated model stays unconfirmed, is not recorded as a phase artifact, and is not handed off until the user explicitly confirms. The TM7 instruction is unchanged.
  • The Security Planner and Security Reviewer each gain a short ## Threat Dragon Generation Workflow section beside their TM7 section. There is no new prompt or standalone agent.

Docs, security model, and evals

  • New references/threat-dragon-generation.md. Updates to SKILL.md, the skill README.md, SECURITY.md (new parse surface, controls, and a Low residual-risk row), the repository security-model registry row, the threat-models README, and the generated reference page.
  • Behaviour-conformance stimuli parallel to the TM7 ones in instructions.eval.yaml and skill-behavior.eval.yaml.
  • .gitattributes keeps the hash-pinned vendored schema byte-exact and the Threat Dragon golden fixtures LF on Windows checkouts. Without it, the hash and golden tests fail under core.autocrlf=true.
  • .cspell/general-technical.txt gains antv, dasharray, interactor, and threatmodel.

Related Issue(s)

Type of Change

Select all that apply:

Code & Documentation:

  • Bug fix (non-breaking change fixing an issue)
  • New feature (non-breaking change adding functionality)
  • Breaking change (fix or feature causing existing functionality to change)
  • Documentation update

Infrastructure & Configuration:

  • GitHub Actions workflow
  • Linting configuration (markdown, PowerShell, etc.)
  • Security configuration
  • DevContainer configuration
  • Dependency update

AI Artifacts:

  • Reviewed contribution with hve-builder and addressed all actionable findings
  • Copilot instructions (.github/instructions/*.instructions.md)
  • Copilot prompt (.github/prompts/*.prompt.md)
  • Copilot agent (.github/agents/*.agent.md)
  • Copilot skill (.github/skills/*/SKILL.md)
  • Copilot hook (.github/hooks/*/*.json)
  • Eval spec added/updated for changed AI artifacts (evals/)

Note for AI Artifact Contributors:

  • Agents: Research, indexing/referencing other project (using standard VS Code GitHub Copilot/MCP tools), planning, and general implementation agents likely already exist. Review .github/agents/ before creating new ones.
  • Skills: Must include both bash and PowerShell scripts. See Skills.
  • Model Versions: Contributions MUST target models listed in the model catalog (scripts/linting/model-catalog.json) whose provider appears in providerAllowlist and whose status is ga or preview. Run npm run lint:models to validate references.
  • See Agents Not Accepted and Model Version Requirements.

Other:

  • Script/automation (.ps1, .sh, .py)
  • Other (please describe):

Sample Prompts (for AI Artifact Contributions)

User Request:

"Generate an OWASP Threat Dragon model for this security plan."

Execution Flow:

  1. The Security Planner (or Security Reviewer) reads references/threat-dragon-generation.md and halts if it is missing.
  2. It reuses the plan's YAML threat-model spec, or drafts one from the plan, and proposes optional fields such as owner or bidirectional rather than inventing values.
  3. It runs generate_threat_dragon.py, which validates the model before writing it.
  4. It presents the spec and the output, asks the user to confirm explicitly, and keeps the model unconfirmed until they do.

Output Artifacts:

A Threat Dragon v2.6.2 JSON model, written to a caller-chosen path (default out.threat-dragon.json) and not committed. Abbreviated example:

{
  "version": "2.6.2",
  "summary": { "title": "Threat Dragon fixture commerce", "owner": "Platform security", "id": "f84c7e8c-…" },
  "detail": {
    "diagrams": [
      { "id": 0, "title": "Commerce context", "diagramType": "STRIDE", "version": "2.6.2", "cells": ["…"] }
    ],
    "diagramTop": 2,
    "threatTop": 3
  }
}

Success Indicators:

  • validate_threat_dragon.py <model.json> exits 0.
  • In Threat Dragon v2.6.2 (Open an existing threat model), elements and flows show their real names, open-threat elements have red outlines, out-of-scope elements are dashed, the Owner field is filled, and each threat shows its status, severity, and an HVE-Core context block.
  • The agent reports the model as awaiting confirmation until the user explicitly confirms.

For detailed contribution requirements, see:

Testing

Commands run locally on Windows, with results:

  • pytest (full security-planning suite, via the skill's uv environment): 616 passed, 2 skipped (the opt-in loader test and a Windows TMT probe).
  • Opt-in native loader (THREAT_DRAGON_LOADER=1 pytest tests/test_threat_dragon_loader.py): passed. It runs the golden model through real Threat Dragon v2.6.2 code at commit 8c0edb2: v2 detection, upstream schema check, the THREATMODEL_SELECTED mutation, and labels, strokes, and markers read back through Threat Dragon's X6 shapes.
  • ruff check . and ruff format --check on the skill: passed.
  • npm run validate:skills, lint:frontmatter, lint:ai-artifacts, lint:md, lint:json, lint:yaml, lint:artifact-portability, lint:asset-docs, lint:eval-grader-lineage, lint:links, validate:copyright: passed.
  • npm run plugin:sync (no change; plugin.json already current) and npm run plugin:validate: passed. npm run docs:generate produced the new reference page and index updates.
  • Markdown table check (Format-MarkdownTables.ps1 -Check): passed.
  • cspell on changed files: no new findings. Remaining hits are on pre-existing lines.
  • git diff --check: clean apart from the vendored upstream schema and licence, which are kept byte-identical (schema git blob c8fab1c8… matches upstream).
  • A clean checkout with core.autocrlf=true keeps the vendored schema SHA-256 and the golden fixture's LF endings intact.
  • Manual: generated models from docs/planning/threat-models/hve-core-comprehensive.yaml and opened them in Threat Dragon v2.6.2 desktop. Labels, red open-threat outlines, dashed out-of-scope services, and the owner field render as expected.
  • Development review: an hve-builder reviewer pass on the instruction and agent sections returned no findings, and an RPI review finding (abuse-case threats with threat generation enabled) was fixed and covered by a test.

Validation history and latest update for published head 7c633523 (2026-11-09):

  • uv run --no-sync pytest -q -rs from the security-planning skill root: 616 passed, 2 skipped before the CI repairs. The skips were the opt-in native loader and an unavailable Windows directory-link operation.
  • uv run --no-sync pytest tests/test_generate_threat_dragon.py tests/test_validate_threat_dragon.py tests/test_threat_dragon_loader.py -q -rs: 41 passed, 1 opt-in native-loader test skipped after the CI repairs. The native loader and manual desktop checks reported above were not rerun during these repairs.
  • uv run --no-sync ruff check . and uv run --no-sync ruff format --check . from the skill root: passed after the repairs.
  • pwsh -File scripts/evals/Test-EvalSpec.ps1 -Root evals/behavior-conformance -OutputPath logs/pr-3159-eval-spec-validation.json: both complete eval specs passed; no failures.
  • npm run lint:md-links -- -ChangedFilesOnly -BaseBranch upstream/main: passed. Internal links were checked repository-wide; external URLs were checked only in changed Markdown files.
  • npm run validate:local: attempted, not passed. ShellCheck 0.11.0 is now installed, and validation progressed through workflow, JSON, and link-language checks. The full external-link check reported website access challenges on unchanged files; the strict aggregate remains incomplete. No internal-link failures were reported.
  • npm run validate:docs: passed after documentation dependencies were restored. ESLint, label-registry consistency, TypeScript, all 15 Jest suites / 132 tests, 13 Mermaid tests, and accessibility metadata checks for 65 Mermaid diagrams passed. An initial child-process timeout did not recur after an isolated test and full-suite retry.
  • npm run spell-check -- --no-progress: passed, 868 files checked and zero issues. Two ignored, untracked legacy extension README outputs were moved to a verified local backup; no tracked files, dictionaries, or ignore rules were changed.
  • npm run lint:models, npm run lint:asset-docs, npm run lint:extension-artifact-naming, npm run lint:cold-start, and npm run lint:eval-grader-lineage: passed. Asset documentation validation reported 34 existing placeholder warnings and no errors.
  • A direct hve-builder review covered the changed agents, instruction, skill, bundled reference, and CI repairs. Two subsequent findings were resolved in 7c633523: mixed-licence attribution and explicit confirmation-contract loading for direct skill invocation. The scoped closure review passed, with frontmatter, skill structure, packaging, generated docs, eval schemas, grader lineage, and static grader checks passing. The HVE Builder and AI-artifact verification checkboxes below remain for human confirmation.
  • Local skill smoke test: the unchanged commerce specification was exported with generate_threat_dragon.py and checked with validate_threat_dragon.py; both commands exited 0, and the JSON matched the golden fixture byte-for-byte. The user explicitly confirmed the specification and output for the local test.
  • Manual desktop test, user-confirmed on 2026-11-09: opened the commerce model in Threat Dragon v2.6.2, inspected both diagrams and all four threats, then saved, closed, and reopened it with the diagrams and threat details preserved. Screenshots show Session impersonation as Open / Critical, Request tampering as Open / High, Order metadata observation as Mitigated / Low, and Order processing exhaustion as N/A / TBD. Original threat IDs, source states, and supplied mitigation text are preserved. This is user-provided manual evidence, not agent-executed GUI automation or security approval.

Hosted checks for 7c633523: 145 passed and 9 skipped, with no failing or pending checks at the time of this update. GitHub now reports conflicts against the current base branch; the PR remains a draft and requires review. Model-backed eval lanes were not run locally. Repository-wide npm run test:py and npm run lint:py were not completed; the skill-scoped results above are not full-repository passes.

Checklist

Required Checks

  • Documentation is updated (if applicable)
  • Files follow existing naming conventions
  • Changes are backwards compatible (if applicable)
  • Tests added for new functionality (if applicable)

AI Artifact Contributions

  • Used hve-builder review mode to review contribution
  • Addressed all actionable findings from the hve-builder review
  • Verified contribution follows common standards and type-specific requirements

Required Local Checks

The following local-safe validation commands must pass before merging:

  • Local validation aggregate: npm run validate:local
  • Documentation validation (if docs changed): npm run validate:docs
  • Spell checking: npm run spell-check
  • Link validation: npm run lint:md-links

Security Considerations

  • This PR does not contain any sensitive or NDA information
  • Any new dependencies have been reviewed for security issues
  • Security-related scripts follow the principle of least privilege

No runtime dependency is added: the validator implements the schema keywords it needs in-module. The vendored schema is Apache-2.0 and ships with its licence, a third-party notice, and a provenance record (upstream commit, git blob SHA, SHA-256, and size). The generator and validator make no network calls. Reads are size-bounded, and writes go through a validated temp file and an atomic replace. The opt-in loader test is the only code that reaches the network; it clones the pinned Threat Dragon commit and runs npm ci in a temporary directory, and only when explicitly enabled.

Additional Notes

  • Design direction: this follows maintainer guidance to mirror the Security Planner's MTMT/TM7 capability rather than ship a standalone Threat Dragon agent. Export is one-way (spec to Threat Dragon) and targets Threat Dragon v2.6.2 only. Generated models are build output and are not committed, the same as .tm7 files.
  • Scripts are Python only: the skill-template note asks for Bash and PowerShell scripts. The Threat Dragon scripts are Python, matching the existing security-planning generators (generate_tm7.py, generate_markdown.py) they import from.
  • Layout: Threat Dragon diagrams reuse TM7's layout at 1:1 scale, so future TM7 layout changes will also change the Threat Dragon golden fixture (regenerate it with the generator).
  • Follow-up, out of scope: trust_boundary_line elements fail closed today. Mapping them to Threat Dragon's trust-boundary-curve needs line geometry TM7 does not produce.

- add Threat Dragon v2.6.2 generator and validator with vendored schema
- wire Security Planner and Reviewer via a confirm-before-final instruction
- add optional spec fields, reference, tests, and evals
- keep vendored schema and golden fixtures safe from CRLF conversion

🐉 - Generated by Copilot

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🔀 - Generated by Copilot

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…onflicts

🔀 - Generated by Copilot

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov-commenter

Codecov Comments Bot (codecov-commenter) commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.45387% with 68 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.47%. Comparing base (299c0b6) to head (baa7ef6).

Files with missing lines Patch % Lines
...ecurity-planning/scripts/validate_threat_dragon.py 79.81% 44 Missing ⚠️
...ecurity-planning/scripts/generate_threat_dragon.py 92.59% 24 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3159      +/-   ##
==========================================
+ Coverage   85.01%   85.47%   +0.45%     
==========================================
  Files         189      111      -78     
  Lines       37947    20884   -17063     
  Branches      264       63     -201     
==========================================
- Hits        32260    17850   -14410     
+ Misses       5605     3023    -2582     
+ Partials       82       11      -71     
Flag Coverage Δ
docusaurus 90.58% <ø> (ø)
pester 87.05% <ø> (-0.01%) ⬇️
pytest 82.83% <87.45%> (-1.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ecurity-planning/scripts/generate_threat_dragon.py 92.59% <92.59%> (ø)
...ecurity-planning/scripts/validate_threat_dragon.py 79.81% <79.81%> (ø)

... and 82 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- keep external Jest fixtures out of local Node discovery
- shorten eval grader names and preserve lineage
- remove unreachable error handler and add regressions

🛠️ - Generated by Copilot

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- declare mixed licences and inventory the vendored schema
- load the confirmation contract for direct skill use
- cover the direct-use gate with a conformance stimulus

📋 - Generated by Copilot

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- regenerate reference counts from the merged catalog
- preserve upstream registry changes and Threat Dragon coverage

🔀 - Generated by Copilot

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@willvelida
Will Velida (willvelida) marked this pull request as ready for review November 10, 2026 22:44
@willvelida
Will Velida (willvelida) requested a review from a team as a code owner November 10, 2026 22:44

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants