TARAflow
Developers / 05

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.

01

Generation Pipeline

DFDGraph

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.

STRIDE Matrix

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.

UnifiedStrategy

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.

Eliminate

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.

Catalog

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.

i18n

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.

Mitigations

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.

02

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.

catalog/threats/ per-element/ general/ <- Process, DS, DF, EE threats-spoofing.json threats-tampering.json ... embedded/ <- CB, OT protocols cloud/ mobile/ per-interaction/ general/ embedded/ cloud/ shared/ threats-gap.json <- property gap threats threats-interface.json threats-physical.json <- PB + CB physical

Template schema — every field is required except context keys, which are optional matchers:

// ElementTemplate { "id": "T-004", "domain": "embedded", "strideCategory": "T", "elementTypes": ["Process"], "context": { "technology": [ "bootloader", "rtos_task" ] }, "mitigations": ["M-CB-T-001"], "verifications": ["V-CB-T-001"], "isCustom": false }
// Convention

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.

03

i18n Architecture

locales/en/threats/ index.ts <- ELEMENT_THREAT_TEXTS INTERACTION_THREAT_TEXTS per-element/ general/ index.ts <- GENERAL_ELEMENT_THREATS threats-spoofing.json ... embedded/ cloud/ mobile/ per-interaction/ general/ embedded/ cloud/ shared/ index.ts threats-gap.json threats-interface.json threats-physical.json

Each domain index spreads inner keys to produce a flat domain-keyed object:

// per-element/embedded/index.ts export const EMBEDDED_ELEMENT_THREATS = { embedded: { ...threatsSpoofing.embedded, ...threatsTampering.embedded, // ... }, }; // root index.ts merges all domains export const ELEMENT_THREAT_TEXTS = { ...SHARED_ELEMENT_THREATS, // gap/interface/physical ...PER_ELEMENT_THREATS, // general/embedded/cloud/mobile };

i18n.ts imports ELEMENT_THREAT_TEXTS as the element-threats-attacks namespace. Lookup key: {domain}.{templateId}.threat.

04

UnifiedStrategy

UnifiedStrategy replaces the old Classic/Hybrid/Relation split. It is a two-module additive pipeline with a hard invariant: baseCategories are law.

// Module 1: Element Properties const propsResult = applyElementProperties(element, baseCategories); // Module 2: CIANAAA Security Goals const cianaaaResult = applyCIANAAA(element.id, project); // Combine — CIANAAA cannot add outside baseCategories if (cianaaaResult.applied) { const combined = new Set([ ...cianaaaResult.categories, ...(propsResult.applied ? propsResult.categories : []), ]); finalCategories = Array.from(combined) .filter(c => baseCategories.includes(c)); // leftarrow hard filter }
// Invariant

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.

05

Sync Services

element-sync.ts

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.

interaction-sync.ts

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.

// Architecture rule

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.

06

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.

// Property → Mitigation mapping examples // Interface.implementedControls.linkAuthentication = "mutual_pairing" (S) M-S-001 alreadyImplemented: true M-S-002 alreadyImplemented: true // Interface.implementedControls.debugProtection ≠ "none" (T, E) M-CB-T-001 alreadyImplemented: true // Interface.operationalState = "hw_disabled" (S, T, E) M-IF-E-001 alreadyImplemented: true // DataFlow.physicalPathProtection = "conduit" M-T-001 alreadyImplemented: true M-D-001 alreadyImplemented: true // Merge: existing template mitigation gets flagged // New hints not in template are appended function mergeMitigationHints( templateMitigations: MitigationDraft[], hints: MitigationDraft[] ): MitigationDraft[]
07

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}.json under 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 affectsProperties entries to the referenced mitigations if they map to element properties
  • Run the project in dev and check the Console for [ThreatCatalog] Missing errors
// ID uniqueness

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.