agentleFS
herohuaherohua/skills/threat-model/SKILL.md

threat-model

Skill1 starsChanged 3 months agoMITView on GitHub

Update Microsoft Threat Modeling Tool (.tm7) files to reflect design changes. Use when the user wants to update a threat model, add new elements/flows/threats to a .tm7 file, modify DFD diagrams, or apply STRIDE analysis. Triggers include: any mention of 'threat model', '.tm7', 'STRIDE', 'DFD', 'data flow diagram', 'threat modeling tool', or requests to add threats, trust boundaries, data flows, or external interactors to a threat model. Also use when user provides a design flowchart and wants to update the corresponding threat model.

39 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use supply-chain-review, vuln-scan and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • MesteriisSkill

    supply-chain-review

    Reviews lockfiles, installers, provenance, CI permissions, dependency confusion, artifacts, registries, and publishing.

    Also in 3 projects that use this

  • AnthropicSkill

    vuln-scan

    Static source-code vulnerability scan. Reads a target directory (and THREAT_MODEL.md if present), spawns parallel review subagents per focus area, and writes VULN-FINDINGS.json + .md for /triage to consume. Read-only — no building, running, or network. For execution-verified crashes, use vuln-pipeline instead. Use when asked to "scan for vulns", "review this code for security issues", "find bugs in <dir>", or as the step between /threat-model and /triage.

    Also in 3 projects that use this

  • AnthropicSkill

    patch

    Generate candidate fixes for verified security findings. Consumes

    Also in 3 projects that use this

  • fefogarciaSkill

    dependency-audit

    Comprehensive dependency health auditing for JavaScript/TypeScript projects. Run npm audit, detect outdated packages, check for security advisories, and verify license compliance. Prioritises vulnerabilities by severity and provides actionable fix recommendations.

    Also in 4 projects that use this

  • CloudflareSkill

    security-audit

    Security guidance and vulnerability review for codebases, APIs, services, CLI tools, libraries, and daemons. Use for security questions, focused reviews, vulnerability research, security audits, or pen tests. Run the complete workflow only for explicit codebase audit or pen-test requests, full/comprehensive/end-to-end reviews, or requested report artifacts.

    Also in 7 projects that use this

  • SentrySkill

    write-tests

    Write tests following project conventions. Use when adding new tests or modifying existing ones.

    Also in 3 projects that use this

  • +2 more from anthropics

The file

Show its rules and text

We split this skill into the rules it gives an agent

17 rules. 0 are common, 11 are distinctive, and 6 are very specific to this project.

  • 0

    Common

    Most of the 35 edited versions we read keep these.

  • 11

    Distinctive

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Update Microsoft Threat Modeling Tool (TMT) .tm7 files programmatically — adding DFD elements, data flows, trust boundaries, and STRIDE …

    line 11
  2. Distinctive:

    Should arrow labels follow a specific naming convention?

    line 35
  3. Distinctive:

    Read the .tm7 file and extract the current state.

    line 39
  4. Very specific:

    Write a Python script that uses the builder functions from references/tm7_builders.py.

    line 73
  5. Distinctive:

    All text arguments accept plain text — escaping is handled internally.

    line 150
  6. Very specific:

    Check for double-escaped XML entities (&amp;amp;)

    line 177
  7. Distinctive:

    Verify new GUIDs are present

    line 178
  8. Distinctive:

    Verify Out Of Scope flags are set correctly

    line 179
  9. Distinctive:

    Verify trust boundary dimensions encompass intended elements

    line 180
  10. Very specific:

    Avoid double-escaping: never pre-escape & as &amp.

    line 194
  11. Very specific:

    When moving an element, update all connected data flow connectors — use move_element() + move_connector_endpoint() for each connector

    line 199
  12. Distinctive:

    When inserting a new numbered flow between existing ones, rename in reverse order (highest number first) to avoid name collisions

    line 204
  13. Very specific:

    Arrow labels: Use format N. Operation (Auth) — e.g., 5.

    line 210
  14. Distinctive:

    Element names: Use clear, descriptive names matching the design diagram

    line 212
  15. Distinctive:

    Write specific, actionable threat descriptions — not generic boilerplate

    line 220
  16. Distinctive:

    Update InteractionString in threats when renaming data flows

    line 223
  17. Distinctive:

    Update it whenever new flows are added

    line 227

“Common” is measured: kept by at least 6 in 10 of the 35 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Threat Model Update Skill

Update Microsoft Threat Modeling Tool (TMT) .tm7 files programmatically — adding DFD elements, data flows, trust boundaries, and STRIDE threats to reflect new or changed system designs.

When to Use

  • User provides a design change (flowchart, architecture diagram, description) and wants the threat model updated
  • User wants to add new processes, external interactors, data stores, data flows, or trust boundaries
  • User wants new STRIDE threats generated for new or modified data flows
  • User wants to restructure trust boundaries or rename elements
  • User wants to move elements in or out of trust boundaries

High-Level Workflow

Phase 1: Gather Inputs

Collect from the user:

  1. Design input: New/changed system design — flowchart, Mermaid diagram, architecture doc, or verbal description
  2. Target .tm7 file: Path to the existing threat model file to update
  3. Scope: Which parts of the design are new vs already modeled

Ask clarifying questions:

  • Which elements are in-scope vs out-of-scope for threat analysis?
  • Which trust boundaries should elements belong to?
  • What authentication methods are used on each data flow? (e.g., MSI, OAuth, access token, GitHub App, user login)
  • Should arrow labels follow a specific naming convention?

Phase 2: Analyze Existing .tm7

Read the .tm7 file and extract the current state. See references/tm7-format.md for the full format reference.

Extract and present to the user:

  1. All border elements (stencils): processes, external interactors, data stores — names, GUIDs, positions, out-of-scope flags
  2. All trust boundaries: names, GUIDs, positions, dimensions — which elements they contain
  3. All data flow connectors: names, source/target elements, authentication annotations
  4. All existing threats: count by STRIDE category, current ID range
  5. Annotations/notes: free-text boxes on the diagram
  6. z:Id sequence: the last used z:Id value (needed for adding new elements)

Key values to record for later use:

  • Drawing Surface GUID: needed for all new threat instances
  • Existing element GUIDs: needed as source/target references for new data flows
  • Last threat ID: new threats continue from this number
  • Last z:Id: new elements continue from this number

Phase 3: Plan Changes

Based on the design input and existing model state, produce a change plan:

Change TypeDetails
New border elementsName, type (Process/EI/DataStore), position, in/out of scope
New data flowsName, source, target, auth method
Modified elementsWhat changes (position, scope, name)
Trust boundary changesNew boundaries, expanded boundaries, elements to include
New threatsWhich flows get threats, STRIDE categories to cover
Annotation updatesUpdated step descriptions

Present the plan to the user for approval before proceeding.

Phase 4: Generate Update Script

Write a Python script that uses the builder functions from references/tm7_builders.py. Copy the needed functions into the script — they handle all XML generation and escaping.

Script pattern:

import argparse

# Copy builder functions from references/tm7_builders.py:
#   xml_escape, make_external_interactor, make_process,
#   make_connector, make_threat,
#   set_out_of_scope, resize_boundary, rename_data_flow

DRAWING_SURFACE_GUID = "..."  # from Phase 2
# ... other existing GUIDs ...
# ... new deterministic GUIDs ...

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--input", required=True)
    parser.add_argument("--output", default=None)
    args = parser.parse_args()

    with open(args.input, "r", encoding="utf-8") as f:
        content = f.read()

    # Note: .tm7 files produced by Microsoft Threat Modeling Tool contain a
    # single DrawingSurfaceModel, so these closing tags appear exactly once.

    # 1. Add new border elements before </Borders>
    new_borders = []
    new_borders.append(make_external_interactor(GUID, z_id, "Name", left, top))
    new_borders.append(make_process(GUID, z_id, "Name", left, top))
    content = content.replace("</Borders>", "".join(new_borders) + "</Borders>")

    # 2. Add new data flows before </Lines>
    new_lines = []
    new_lines.append(make_connector(GUID, z_id, "N. Operation (Auth)",
        source_guid, target_guid,
        source_x, source_y, target_x, target_y, handle_x, handle_y))
    content = content.replace("</Lines>", "".join(new_lines) + "</Lines>")

    # 3. Add new threats before </ThreatInstances>
    new_threats = []
    new_threats.append(make_threat(threat_id, "TH7", DRAWING_SURFACE_GUID,
        source_guid, flow_guid, target_guid,
        "Threat title", "Spoofing", "Short desc",
        "Full description", "Flow name", "Mitigations"))
    content = content.replace("</ThreatInstances>",
        "".join(new_threats) + "</ThreatInstances>")

    # 4. Modify existing elements
    content = set_out_of_scope(content, element_guid, "true")
    content = resize_boundary(content, boundary_guid, left, top, width, height)
    content = rename_data_flow(content, "old name", "new name")

    with open(args.output or args.input, "w", encoding="utf-8") as f:
        f.write(content)

if __name__ == "__main__":
    main()

Available builder functions (see references/tm7_builders.py):

FunctionPurpose
xml_escape(text)Escape &, <, > for XML values
make_external_interactor(guid, z_id, name, left, top, ...)Create External Interactor element
make_process(guid, z_id, name, left, top, ...)Create Process element
make_connector(guid, z_id, name, source_guid, target_guid, ...)Create data flow connector
make_threat(threat_id, type_id, drawing_surface_guid, ...)Create STRIDE threat instance
set_out_of_scope(content, element_guid, value)Set Out Of Scope flag on an element
resize_boundary(content, boundary_guid, left, top, width, height)Resize a trust boundary
rename_data_flow(content, old_name, new_name)Rename a flow + update threat references
move_element(content, element_guid, new_left, new_top)Move an element to a new position
move_connector_endpoint(content, connector_guid, element_guid, new_x, new_y, ...)Update connector Source/TargetX/Y after moving an element

All text arguments accept plain text — escaping is handled internally.

STRIDE Threat Generation

For each new data flow, generate threats covering relevant categories:

CategoryWhen to ApplyTypical TypeId
SpoofingFlow uses credentials/tokensTH7, TH86
TamperingFlow carries modifiable dataTH96, TH108
RepudiationAutomated actions without audit trailTH30
Information DisclosureFlow could leak sensitive dataTH94, TH101
Denial of ServiceFlow to shared resource (apply selectively)—
Elevation of PrivilegesAutomated entity has elevated permissionsTH110

Unauthenticated API flows deserve special threat attention:

  • Spoofing via DNS hijacking / MITM (no client auth to verify identity)
  • Tampering of response data in transit
  • Information Disclosure of query patterns revealing internal structure
  • API abuse / data poisoning if the service has any write surface
  • EoP when untrusted response data flows into an automated fix pipeline

Phase 5: Run and Verify

  1. Run the script against the .tm7 file
  2. Verify changes programmatically:
    • Count border elements, data flows, and threats before/after
    • Check for double-escaped XML entities (&amp;amp;)
    • Verify new GUIDs are present
    • Verify Out Of Scope flags are set correctly
    • Verify trust boundary dimensions encompass intended elements
  3. Report results to the user with a summary table

Tell the user to open the .tm7 in Microsoft Threat Modeling Tool to visually verify:

  • Element positions and layout
  • Arrow label readability (no overlaps)
  • Trust boundary coverage
  • Threat list completeness

Best Practices

XML Manipulation

  • Always use string-based manipulation (find/replace) — never DOM parsers for .tm7 files
  • Pass plain text to builder functions — they handle XML escaping internally
  • Avoid double-escaping: never pre-escape & as &amp; before passing to builders
  • Use deterministic GUIDs for reproducibility — hardcode them as constants
  • Use large search regions (5000+ chars from GUID marker): TMT built-in stencils (SE.P.TMCore.WebApp, etc.) have many more properties than generic elements, pushing positional fields (Left, Top, SourceX, TargetX) far from the <a:Key> marker. A 3000-char region will miss them.

Moving Elements

  • When moving an element, update all connected data flow connectors — use move_element() + move_connector_endpoint() for each connector
  • Find connected connectors by searching for the element's GUID in <SourceGuid> and <TargetGuid> tags
  • Adjust HandleX/HandleY proportionally to keep labels readable

Renumbering Flows

  • When inserting a new numbered flow between existing ones, rename in reverse order (highest number first) to avoid name collisions
    • Example: inserting new step 6 → rename 9→10, 8→9, 7→8, 6→7, then add step 6
  • rename_data_flow() updates both the connector name and all threat InteractionString references automatically
  • Each renamed flow may have multiple threats — all are updated in one call

Naming Conventions

  • Arrow labels: Use format N. Operation (Auth) — e.g., 5. Create Issue (GitHub App)
  • Auth methods: MSI, GitHub App, GitHub Login, OAuth, Access Token, API Key, No Auth, etc.
  • Element names: Use clear, descriptive names matching the design diagram

Positioning

  • Spread arrow handle positions to avoid label overlap — vary HandleX/HandleY coordinates
  • Expand trust boundaries with 50px padding around contained elements
  • Keep elements within their trust boundaries — verify positions against boundary coordinates

Threat Quality

  • Write specific, actionable threat descriptions — not generic boilerplate
  • Include concrete mitigations relevant to the specific technology and auth method
  • Set appropriate priority: High for credential theft, code injection, privilege escalation; Medium for audit/logging gaps
  • Update InteractionString in threats when renaming data flows

Annotation

  • Maintain a step-by-step annotation box describing the entire workflow
  • Update it whenever new flows are added
  • Expand the annotation box dimensions to fit additional text

Reference Files

FilePurpose
references/tm7_builders.pyReusable Python builder functions — copy into your script
references/tm7-format.md.tm7 XML format specification, namespace reference, threat TypeIds

Output Artifacts

When done, produce:

  1. Python update script — using builders from tm7_builders.py, with --input / --output args
  2. Changes summary (Markdown) — table of all elements, flows, and threats added
  3. Updated .tm7 file — ready to open in Microsoft Threat Modeling Tool

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.