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.3 still supports.

SPARTA 2026.3 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 run Load and Analyze Model, so save the catalog and analyze the model again after every change. While an analysis is loaded, SPARTA recalculates risk values after model edits, but it does not parse changed patterns again.

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.3, 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. To be able to select another catalog, first load its file into the editor of your catalog with SpartaModel Editor ‣ Load Resource… (see SPARTA Interface). 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. In the workbench, the error is reported as The analysis engine could not analyse <model URI>: followed by this message. 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. SPARTA does not calculate the risk of such a threat: in the command-line tools, the --outcsv, --outxlsx and --outtxt exports stop with the error risk not yet calculated for this threat (see Command-line tools).

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 and the trust boundary columns of the CSV and XLSX exports, 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 Which countermeasures apply).

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 and XLSX exports are empty, and the report draws only the threatened element in the diagram of the threat.

A countermeasure with a non-empty scope never applies to a threat without a data flow. If such a countermeasure should reduce the risk of these threats, give the pattern a df : DataFlow (or flow) parameter. 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. A placeholder that SPARTA cannot fill in is shown as <unknown: param>, for example <unknown: recipient>. This happens when the pattern does not declare a parameter with that name, when the parameter is not bound to a model element (for example an EString), and, for <$param$>, when the element has no name. Element names are inserted literally, also when they contain $ or \.

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, so countermeasures with a scope can apply to its threats (see The role of the data flow).

  • 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).

Editing patterns in SPARTA

To edit the Patterns of a ThreatPattern with VQL syntax highlighting, right-click the threat pattern in the tree editor and choose Edit VQL Pattern…. The dialog shows the prepended header as read-only context, but it does not check the VQL: errors only show up in the PatternSupport view when you analyze a model. Editing the VQL text describes the dialog.

Debugging patterns

The PatternSupport view

The PatternSupport view lists the errors found while parsing the threat patterns of the loaded catalogs. In the SPARTA perspective, it is the PatternSupport tab next to the ThreatAnalysis view. You can also open it with Window ‣ Show View ‣ Other…, and select PatternSupport in the Pattern Support category (or type PatternSupport in the filter field).

  • Show the view before you run Load and Analyze Model, for example by clicking its tab: 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).

Caution

If almost every pattern of a catalog that worked before shows ... cannot be resolved for a helper pattern, such as processToProcessComm or containerDiff, check the path of the SPARTA folder: in SPARTA 2026.3, a space in that path makes the parsing of catalog patterns fail (see Installing SPARTA).

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 ran 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 a name or description shows <unknown: ...>, check that every placeholder names a parameter of the pattern that is bound to a model element. If a countermeasure with a scope does not reduce the risk of threats without a data flow, add a data flow parameter (see The role of the data flow). If the ThreatAnalysis view fails while loading the threats, or a command-line export stops with risk not yet calculated for this threat, add a threatened element (location) parameter. If you get more threats than expected, look for extra parameters and for overlapping ThreatPatterns.

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.3 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.

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.

Known limitations in 2026.3

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

  • Countermeasures with a scope never apply to threats of patterns without a data flow parameter (see The role of the data flow).

  • Threats of a pattern without a threatened element are missing from the ThreatAnalysis view, and make the exports of the command-line tools fail (see Pattern parameters).

  • Errors in helper patterns are not shown in the PatternSupport view, and the view only shows the errors of an analysis that runs while it is shown (see The PatternSupport view).

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