Threat Generator
Architecture of the threat generation pipeline: UnifiedStrategy, catalog domain structure, context matching, i18n hierarchy, closed-loop mitigation mapper, and element/interaction sync services.
Generation Pipeline
Input: DFDGraphReference
dfdGraph — the analysis view of the graph built by build-dfd-graph.ts from the draw.io XML and widened by toReferenceGraph() (see DFD Engine). Contains elementsById, connectionsById, effectiveElementTrustBoundary, and CB/PB membership maps.
Base STRIDE categories
STRIDE_PER_ELEMENT_TYPE defines the base set per element type. ExternalEntity → [S,R], Process → [S,T,R,I,D,E], DataFlow → [T,I,D], DataStore → [T,R,I,D], ChipBoundary → [T,I,E], Sensor / Actuator → [S,T,D]. These are the hard ceiling — no module can add categories outside this set.
Category resolution: two modules
Module 1 — Element Properties: stride-modifier functions narrow or extend categories based on element properties (technology, protocol, operationalState, etc.).
Module 2 — CIANAAA: derives STRIDE categories from active asset security goals via CIANAAA_TO_STRIDE. Result is intersected with baseCategories — CIANAAA cannot add outside the matrix.
shouldEliminateThreat()
Pre-filter: certain property values make a threat scenario physically or logically impossible. debugProtection=fused_off → [T,I,E] eliminated, operationalState=permanent_disabled → all eliminated. Only unambiguous, deterministic cases are eliminated here.
Template selection: findElementTemplate()
For each surviving (element, STRIDE) pair, findElementTemplate() selects the best-matching template via matchesContext(). Matches on: elementType, technology, protocol, systemClass, platform, location, safetyFunction, accessMode, and more. Most-specific match wins. A key that names a missing or weak control also matches while the property is unset (contextMatch() counts these assumptions) — a template matched by facts is chosen before one matched by an assumption.
Localized texts: domain-prefixed lookup
Threat description, cause, and attack text are resolved via getLocalizedElementThreat(template.id, template.domain ?? "general"). Key format: {domain}.{templateId}.threat. Falls back to general with a console.error if domain-specific text is missing.
Closed-loop: getImplementedMitigationHints()
Inspects element properties and returns MitigationDraft[] with alreadyImplemented: true for controls already present on the element. Merged with template mitigations — existing entries get flagged, new hints are appended. Threat is always generated; nothing is suppressed.
Catalog Structure
Templates are split by domain and STRIDE category. Each JSON file contains only elementTemplates or interactionTemplates arrays. Every template carries a domain field used as the i18n lookup prefix.
Template schema — every field is required except context keys, which are optional matchers:
IDs are unique within a domain/STRIDE file (S-001, T-001, …). IDs in shared/ are globally unique across all shared files. The domain field drives i18n key construction — embedded.T-004.threat.
i18n Architecture
Each domain index spreads inner keys to produce a flat domain-keyed object:
i18n.ts imports ELEMENT_THREAT_TEXTS as the element-threats-attacks namespace. Lookup key: {domain}.{templateId}.threat.
UnifiedStrategy
UnifiedStrategy replaces the old Classic/Hybrid/Relation split. It is a two-module additive pipeline with a hard invariant: baseCategories are law.
baseCategories are the hard ceiling from STRIDE_PER_ELEMENT_TYPE. Neither the CIANAAA module nor the properties module may introduce a STRIDE category that is not in the base set for the element type. This was the root cause of spurious DataFlow Repudiation threats — fixed in v0.2.0-alpha.
Sync Services
ElementThreatSync
Detects orphaned threats (element deleted), missing elements (new element without threats), changed displayIds, and TB renames. Delegates new threat generation to elementThreatGenerator.generateThreatsForSingleElement() — does not call localization directly. Manual threats are preserved.
InteractionThreatSync
Same pattern for interaction threats. Detects orphaned DataFlow threats and missing connections. Delegates to interactionThreatGenerator.generateThreatsForProject() and filters to only add threats for missing items. Source/target name changes are patched in-place without regeneration.
features/threats and features/dfd must never import from each other. Shared types live in src/shared. The sync services receive a DFDAnalysisContext (from the DFD feature) as a parameter — they do not import DFD modules.
Closed-Loop Mapper
implemented-controls-mapper.ts translates element property values into MitigationDraft[] entries with alreadyImplemented: true. The generator merges these with template mitigations — existing IDs get flagged, new hints are appended.
Adding a Template
Checklist for adding a new threat template:
- Add the JSON entry to the correct
catalog/threats/per-element/{domain}/threats-{stride}.json - Set
"domain"field to match the directory name - Add EN text to
locales/en/threats/per-element/{domain}/threats-{stride}.jsonunder the"{domain}"key - Add DE text to
locales/de/threats/per-element/{domain}/threats-{stride}.json - Verify mitigation IDs exist in the mitigation catalog — broken references silently render as empty strings
- Add
affectsPropertiesentries to the referenced mitigations if they map to element properties - Run the project in dev and check the Console for
[ThreatCatalog] Missingerrors
IDs must be unique within their domain/STRIDE file. Shared files (gap, interface, physical) must have globally unique IDs across all three. The catalog index merges all arrays into a flat list — duplicate IDs will cause the last one to silently win.