Writing threat type patterns

SPARTA elicits threats by evaluating patterns on a DFD model. The patterns are part of a threat type catalog: every leaf threat type can contain one or more ThreatPatterns, written in the VIATRA query language (VQL). Each match of a pattern becomes a threat.

This page is the reference for writing such patterns: how SPARTA turns a catalog into queries, which parameters a pattern needs, how names and descriptions are filled in, and how to find errors. It also documents the older key-based threat types, which SPARTA 2026.2 still supports.

SPARTA 2026.2 builds on VIATRA 2.9.1.

Two elicitation mechanisms

Every analysis, both in the ThreatAnalysis view and in the command-line tools, runs two mechanisms side by side:

Catalog patterns

VQL text in the ThreatPatterns of a ThreatTypeCatalog. This is the mechanism used by the published STRIDE and LINDDUN catalogs, and the one described in most of this page.

Legacy key-based threat types

Keys such as ProcessToProcess in the patterns map of a threat type, evaluated by queries built into SPARTA. See Legacy key-based threat types.

A threat type that has both keys and ThreatPatterns yields threats from both mechanisms.

How a catalog becomes VIATRA queries

Catalogs in scope

SPARTA processes every ThreatTypeCatalog in the analysis scope:

  • In the ThreatAnalysis view, the scope is the analyzed model’s resource plus every resource that contains an element the model references.

  • In the command-line tools, the scope is the model plus every resource it references, directly or indirectly.

In the ThreatAnalysis view and the command-line tools, a catalog is found when the model contains it or references it, typically through the Resource list of the DFD model (DFDModel.resource). Patterns are parsed again every time you click Load and Analyze Model in the ThreatAnalysis view, so save the catalog and reload after every change.

Which threat types are elicited

A threat type is evaluated when all of the following hold:

  • it is a leaf ThreatType, not a group (only ThreatType can contain ThreatPatterns);

  • it is in the catalog’s threat list, or nested at any depth under a group in threat or threattypegroup;

  • at least one of its ThreatPatterns has a non-empty value in Patterns.

Warning

In SPARTA 2026.2, the Enabled flag of threat types and groups, and ThreatSpecifications, are ignored for catalog patterns. A threat type with enabled = false is still elicited. To stop a catalog threat type from being elicited, remove it, or remove or empty its ThreatPatterns. The And/Or kinds of composite threat types have no special meaning either.

Catalog settings

Three properties of the catalog apply to all of its patterns:

Package

A VQL package name, for example stride or linddun. Required.

SPARTA parses the patterns of all catalogs in an analysis together, so pattern names must be unique within a package, also across catalogs. If two catalogs with the same package define a pattern with the same name, the ThreatPattern that is parsed last fails and produces no threats. The PatternSupport view then shows an error such as The type TamperingDataFlow is already defined. For example, the published STRIDE-per-element and STRIDE-per-interaction catalogs both use the package stride and both define tamperingDataFlow: to use both in one model, change the package of one of them.

Imports

One complete VQL import line per value. All published catalogs use exactly these two values:

import "http://distrinet.cs.kuleuven.be/spartamodel"
import "http://www.eclipse.org/emf/2002/Ecore"

The first makes all classes and features of the SPARTA meta-model available, the second the Ecore data types such as EString.

Helper Patterns

VQL patterns that the threat patterns of this catalog can call with find. Helper patterns never produce threats.

Pattern Dependencies

Optional: other threat type catalogs whose patterns SPARTA processes before the patterns of this catalog. SPARTA follows the dependencies transitively, processes every catalog once, and parses the patterns of each catalog with that catalog’s own Package and Imports. The patterns of a dependency produce threats as usual. Cyclic dependencies are rejected with the error Cyclic dependencies in threat type catalog dependencies; this is not supported., and no analysis takes place. Also add the catalogs that your catalog depends on to the Resource property of the DFD model.

The prepended header

SPARTA never parses your pattern text on its own. It prepends a header built from the catalog settings:

package <Package>
<Imports, one per line>
<your pattern text>

Consequences:

  • Do not write a package line or import lines in pattern text; VQL only allows them at the start.

  • Line numbers in error messages refer to the text including the header. With the two standard imports, subtract 3 from a reported line number to get the line in your pattern text.

Parsing units

  • The Helper Patterns of a catalog are joined with line breaks and parsed once, before the threat patterns of that catalog. They share the catalog’s package, so threat patterns call them by their simple name, for example find Communication(sender, df, recipient);.

  • Each ThreatPattern is parsed separately: all values of its Patterns are joined with line breaks and parsed as one unit.

Public and private patterns

Every public pattern in a ThreatPattern’s text produces threats, using that ThreatPattern’s description and mapping. A ThreatPattern can therefore contain several patterns that all fire, and a ThreatType can contain several ThreatPatterns (the STRIDE-per-interaction catalog has eight for spoofing alone).

  • Put shared helpers in the catalog’s Helper Patterns, not in a ThreatPattern.

  • A helper that is only needed inside one ThreatPattern can be declared private pattern; private patterns do not produce threats.

  • To express alternatives for one threat, prefer or bodies in a single pattern.

One threat per match

Each distinct match of a public pattern yields one threat. A match is the combination of the values of all pattern parameters, so every additional parameter that can take several values multiplies the number of threats. Overlapping ThreatPatterns of one threat type also yield duplicate threats.

Pattern parameters

SPARTA reads two parameters of each match by name; all other parameters are free.

Threatened element (the threat’s location)

SPARTA looks for these parameters, in this order:

  1. the parameter named by the mapping key location

  2. location

  3. threatened (older name, still accepted)

Required. The parameter must be bound to a DFDElement (Process, DataStore, ExternalEntity, DataFlow, TrustBoundaryContainer, …).

Data flow

SPARTA looks for these parameters, in this order:

  1. the parameter named by the mapping key flow

  2. flow

  3. df

Optional. If the pattern has this parameter, it must be bound to a DataFlow. Without it, the threat has no data flow (see The role of the data flow).

A value of the wrong type counts as missing. Without a threatened element, the ThreatAnalysis view does not show the threat, and it can leave out other threats of the analysis as well. SPARTA shows no message; the Error Log (Window ‣ Show View ‣ Error Log) contains a NullPointerException. The command-line tools report such a threat without location and risk.

Mapping

If your parameters have other names, add entries to the ThreatPattern’s mapping (New Child ‣ EString To EString Map), with Key location or flow and as Value the parameter name. Note that the key for the data flow is flow, not df. For example, with the mapping location -> target and flow -> channel, the pattern pattern p(target : DFDElement, channel : DataFlow) { ... } places its threats on target and uses channel as their data flow. Placeholders then use the actual parameter names (<$target$>, <$channel$>).

Other parameters

Parameters such as sender and recipient are not interpreted by SPARTA, but you need them as parameters when a name or description refers to them through a placeholder. Remember that they are part of the match.

The role of the data flow

The data flow of a threat is used for:

  • the Flow column of the ThreatAnalysis view;

  • the flow columns of the CSV export and the “DFD Elements” line of the report (see Analysis results and exports); these show the flow’s own sender and recipient, not refined ones;

  • the scope of countermeasures: a countermeasure with a non-empty scope only applies to a threat whose data flow is bound to one of the scope roles (see Advanced concepts in SPARTA).

A pattern whose threatened element is the data flow itself must bind both parameters, as in location == df;. Unlike the legacy mechanism, SPARTA does not use the location as data flow automatically.

Patterns without a data flow parameter, such as those of the STRIDE-per-element catalog, elicit one threat per threatened element, without a data flow. For such threats, the Flow column of the ThreatAnalysis view and the flow columns of the CSV export are empty.

Warning

Some limitations remain in SPARTA 2026.2 for threats without a data flow:

  • Report Export fails at the first such threat and leaves an incomplete threatcatalog.tex (see Analysis results and exports);

  • if a countermeasure with a non-empty scope is a candidate for such a threat (bound to the threatened element and mitigating its threat type), the risk calculation fails: the ThreatAnalysis view shows a risk of 0 and writes the error to the error log, and the command-line tools stop with a NullPointerException;

  • the --outtxt and --codequalityreport exports of sparta-cli fail with a NullPointerException (see Command-line tools).

Give the pattern a df : DataFlow (or flow) parameter if you need any of these. Note that this changes an element-based pattern into an interaction-based one: it then yields one threat per element and data flow, and no threat for elements without data flows (see One threat per match).

Placeholders in names and descriptions

Names and descriptions can refer to the elements of a match:

<$param$>

Replaced by the name of the element bound to parameter param.

<$param.type$>

Replaced by the element’s meta-model class name, for example Process, DataStore, ExternalEntity, DataFlow or TrustBoundaryContainer (without spaces). Any other attribute after the dot yields the text UNSUPPORTED ATTRIBUTE.

Placeholders are substituted in:

  • the Name of the leaf ThreatType, shown in the Name column of the ThreatAnalysis view and of the CSV and XLSX exports;

  • the Name of the top-most group above the threat type, shown in the Type column (if the threat type is not in a group, the column shows its own name);

  • the Description of the ThreatPattern, shown in the Description column (Description missing. if it is empty);

  • the Long Description of the ThreatPattern, shown as “Info” in the dialog that opens when you double-click a threat.

The Description of a ThreatType and the Name of a ThreatPattern are not shown in the results.

Placeholders only read pattern parameters, not local variables. In 2026.2:

  • a placeholder for a parameter that the pattern does not declare causes a NullPointerException when SPARTA creates the threats: the ThreatAnalysis view shows none of the threats of that pattern, without a message, and the Error Log contains the exception, reported by the plug-in org.eclipse.core.databinding;

  • a placeholder for a parameter that is not bound to a model element (for example an EString) causes a ClassCastException;

  • if the name of an element used in a placeholder contains $ or \, the substitution fails with an IllegalArgumentException.

Changed in version 2026.2: In 2026.1, the ThreatAnalysis view showed the threats of a pattern with a placeholder for an undeclared parameter, but without the entire name or description.

Examples

A first pattern

The following pattern elicits an External Entity Spoofed threat for every external entity that is the sender or the recipient of a data flow:

pattern externalEntitySpoofed(location : DFDElement, df : DataFlow) {
  ExternalEntity(location);
  DataFlow.sender(df, location);
} or {
  ExternalEntity(location);
  DataFlow.recipient(df, location);
}
  • It only parses with the catalog’s Package and Imports set as described above.

  • It yields one threat per external entity and data flow, and therefore works in all parts of SPARTA 2026.2.

  • A threat type name such as <$location$> spoofed and a description such as <$location$> is spoofed on <$df$>. make the results readable.

  • DataFlow.sender and DataFlow.recipient are the flow’s own endpoints. If the external entity is decomposed and the flow is refined with a SenderSpecification or RecipientSpecification, the pattern still matches the outer element. To follow such refinements, use a helper such as Communication below.

Patterns from the published catalogs

The STRIDE and LINDDUN catalogs at https://github.com/SPARTA-Threat-Modeling/catalogs show the conventions used in practice.

Element-based (STRIDE-per-element). The threat is placed on every process and external entity; the pattern has no data flow parameter, so its threats have no data flow (see The role of the data flow):

pattern spoofingEntity(location : DFDElement) {
  Process(location);
} or {
  ExternalEntity(location);
}

Interaction-based (STRIDE-per-interaction). The threatened element sends to a data store through df. The extra parameter recipient is used in the description <$location$> is spoofed, and a malicious process writes to <$recipient$>.:

pattern spoofingSenderPtoDS(location : DFDElement, recipient : DFDElement, df : DataFlow) {
  find processToDataStoreComm(location, recipient, df);
}

Located on the data flow, and only when the flow crosses a trust boundary (STRIDE-per-interaction):

pattern tamperingDataFlow(location : DFDElement, df : DataFlow, sender: DFDElement, recipient: DFDElement) {
  location == df;
  DataFlow.sender(df,sender);
  DataFlow.recipient(df,recipient);
  find containerDiff(sender,recipient);
}

The LINDDUN convention: every pattern has the parameters location, sender, recipient and df, and places the threat on one of the three:

pattern linkingSender(location : DFDElement, sender : DFDElement, recipient : DFDElement, df: DataFlow) {
  find Communication(sender,df,recipient);
  location == sender;
}

Restricting the element type with or bodies (LINDDUN):

pattern nonComplianceSender(location : DFDElement, sender : DFDElement, recipient : DFDElement, df: DataFlow) {
  Process(location);
  find Communication(sender,df,recipient);
  location == sender;
} or {
  DataStore(location);
  find Communication(sender,df,recipient);
  location == sender;
}

Matching on annotations. The MTMT catalog in the tutorial project (Tutorial.zip, not part of the published catalogs) uses the following helper pattern in its Helper Patterns, so that a threat pattern can require that an element carries a ModelElementAnnotation with a given value, for example find hasAnnotation(location, "mstmt.unmanaged-code");:

pattern hasAnnotation(element: DFDElement, value : EString) {
  DFDElement.annotations(element,a);
  ModelElementAnnotation.value(a,value);
}

The published catalogs use these VQL constructs: type constraints (Process(x);), path expressions (DataFlow.sender(df, x);, which also resolve inherited features), find and neg find, transitive closure (find containment+(a,b)), equality (location == df), or bodies and anonymous variables (_); the MTMT catalog also uses string literals.

Helper patterns of the published catalogs

The STRIDE-per-interaction and LINDDUN catalogs share the same 31 helper patterns. You can copy them into your own catalog. The most useful ones:

Communication(sender, flow, recipient)

The actual endpoints of flow: follows SenderSpecification and RecipientSpecification chains to the most refined sender and recipient (through actualSender and actualRecipient).

processToProcessComm(location, p2, df) and the other xToYComm helpers

For processes, data stores and external entities: the first argument sends df to the second; the element types are fixed by the name.

xThroughYComm variants and flowThroughComm

The same, but only when the flow crosses a trust boundary.

flowComm(location, p, p2)

Any communication over the flow location.

containerDiff(sender, recipient)

The two elements communicate (through Communication) and some TrustBoundaryContainer (directly or indirectly) contains one of them but not the other.

contains(outer, inner) and containment

Containment through containedElements, transitive and reflexive (an element contains itself).

Debugging patterns

The PatternSupport view

The PatternSupport view lists the errors found while parsing the threat patterns of the loaded catalogs. Open it with Window ‣ Show View ‣ Other…, and select PatternSupport in the Other category (or type PatternSupport in the filter field).

  • Open the view before you click Load and Analyze Model: it is filled when the patterns are parsed.

  • Columns: ThreatType (the raw threat type name), Pattern (the VQL pattern name) and Issue (the parser message). Rows with an issue have a red background.

  • Double-click a row to see the full message in a dialog.

  • Patterns with errors are skipped; the other patterns are still evaluated.

  • Errors in Helper Patterns do not appear in this view. Depending on the error, a threat pattern that calls a faulty helper still works, shows an error such as <helper> cannot be resolved in this view and produces no threats, or makes the analysis fail. While you develop a helper pattern, you can put a copy of it in a threat pattern, so that this view shows its errors.

  • Line numbers include the prepended header (subtract 3 with the two standard imports).

Checklist

If a threat type yields no threats, check that:

  • its ThreatPattern has a non-empty Patterns value and parses without errors;

  • the catalog has a Package and both Imports;

  • the model contains or references the catalog, and you clicked Load and Analyze Model after saving it, with the DFD model’s editor active (not the editor of the catalog);

  • the pattern has a location (or mapped) parameter bound to a DFDElement;

  • the helper patterns it calls exist in the catalog and parse.

If the Description column shows Description missing., the ThreatPattern has no description. If all threats of a pattern are missing and the Error Log contains a NullPointerException from ThreatPatternConversion, check that every placeholder names a parameter of the pattern. If Report Export fails, or a command-line analysis stops with a NullPointerException because of a countermeasure with a scope, add a data flow parameter (see The role of the data flow). If threats in the command-line output have no location and no risk, or the ThreatAnalysis view fails while loading them, add a threatened element (location) parameter. If you get more threats than expected, look for extra parameters and for overlapping ThreatPatterns.

Known limitations in 2026.2

  • For threats of patterns without a data flow parameter, Report Export and the --outtxt and --codequalityreport exports of sparta-cli fail, and so does the risk calculation when a countermeasure with a scope is a candidate (see The role of the data flow).

  • Enabled and ThreatSpecifications are ignored for catalog patterns (see Which threat types are elicited).

  • A placeholder for a parameter that the pattern does not declare makes the ThreatAnalysis view show none of the threats of that pattern, a placeholder for a parameter that is not bound to a model element causes a ClassCastException, and $ or \ in element names break placeholder substitution (see Placeholders in names and descriptions).

  • Errors in helper patterns are not shown in the PatternSupport view (see The PatternSupport view).

  • Cyclic Pattern Dependencies are rejected (see Catalog settings).

Legacy key-based threat types

Before VIATRA patterns could be stored in catalogs, SPARTA elicited threats with a fixed set of built-in queries, selected by keys on the threat types. This mechanism still works in 2026.2 and runs next to the catalog patterns. New catalogs should use catalog patterns; the information below helps you to read and maintain existing catalogs. An example of a complete legacy catalog is contoso/ThreatCatalog.sparta in https://github.com/SPARTA-Threat-Modeling/example-cases, which sets 41 keys on each of its threat types.

Keys

A key is an entry of the patterns map of a threat type or group (New Child ‣ EString To EBoolean Map, with Key and Value). In the .sparta file it looks like this:

<threat xsi:type="spartamodel:ThreatType" name="Spoofing">
  <patterns key="ProcessToProcess" value="true"/>
</threat>

In the key names, X and Y stand for Process, DataStore or ExternalEntity. A key without * places the threat on the sender, a trailing * places it on the recipient, and a * right after To or Through places it on the data flow. “Crosses a trust boundary” means that some TrustBoundaryContainer (directly or indirectly) contains one endpoint of the flow but not the other.

The keys are:

DataFlow

Threat located at the data flow. No condition.

DataFlowThrough

Threat located at the data flow, if the flow crosses a trust boundary.

XToY (9 keys)

Threat located at the sender (of type X). No condition.

XToY* (9 keys)

Threat located at the recipient (of type Y). No condition.

XThroughY (9 keys)

Threat located at the sender (of type X), if the flow crosses a trust boundary.

XThroughY* (9 keys)

Threat located at the recipient (of type Y), if the flow crosses a trust boundary.

XTo*Y (5 keys)

Threat located at the data flow from an X to a Y. No condition.

XThrough*Y (5 keys)

Threat located at the data flow from an X to a Y, if the flow crosses a trust boundary.

The keys located at the sender or the recipient exist for all nine combinations of X and Y. The keys located at the data flow only exist for five combinations: ProcessTo*Process, ProcessTo*DataStore, DataStoreTo*Process, ProcessTo*ExternalEntity and ExternalEntityTo*Process, and the same combinations with Through*. That is 48 keys in total. Other spellings, such as Process*ToProcess or DataStoreTo*DataStore, never match. A threat type that sets both DataFlow and an XTo*Y key gets one threat per data flow, not two; the same holds for DataFlowThrough and an XThrough*Y key. The sender and recipient include every element along a chain of SenderSpecifications and RecipientSpecifications, so a refined flow yields threats for both the outer and the refined element.

Changed in version 2026.2: In 2026.1, ProcessTo*Process, ProcessTo*DataStore and ExternalEntityTo*Process only matched flows that cross a trust boundary, DataStoreTo*Process and ProcessTo*ExternalEntity never matched, and no XThrough*Y key matched. Legacy catalogs that use these keys can therefore yield more threats than in 2026.1.

Applicability rules

A key k applies to a leaf threat type t when:

  • t is enabled;

  • t or one of its enabled ancestors has k with the value true;

  • neither t nor any ancestor is disabled;

  • no enabled ancestor-or-self has k with the value false (a false overrides a true);

  • no ThreatSpecification for t or one of its ancestors disables it (see below).

Threat specifications

A ThreatSpecificationCatalog adjusts a catalog for one model without changing the catalog. It must be in the analysis scope, like any other resource. Each ThreatSpecification refers to one threat type or group (Threat) and can:

  • disable it entirely (Enabled false);

  • disable individual keys (a patterns entry with the value false);

  • disable threats located at a given element type (a types entry with the key Process, DataStore, ExternalEntity or DataFlow and the value false).

Threat specifications only affect legacy key-based threat types.

Results of legacy threats

Legacy threats do not support placeholders or ThreatPattern descriptions: the Description column shows a generated summary of the estimated risk instead. Their location and data flow come from the built-in queries; for the keys located at the data flow, the flow is both location and data flow.