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.0 still supports.
For a step-by-step walkthrough of creating a catalog in the SPARTA editor, see Creating threat type catalogs.
For the meta-model classes of catalogs and threat types, see Advanced concepts in SPARTA in the developer guide.
For using catalogs from your own Java code, see Pairing existing threat type catalogs in the developer guide.
SPARTA 2026.0 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
ProcessToProcessin thepatternsmap 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
threatlist, or nested at any depth under a group inthreatorthreattypegroup;at least one of its ThreatPatterns has a non-empty value in Patterns.
Warning
In SPARTA 2026.0, 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
strideorlinddun. 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 packagestrideand both definetamperingDataFlow: 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
Leave this empty. In 2026.0, any dependency makes the pattern processing recurse endlessly (or fail with a “Cyclic dependencies” error).
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
packageline 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
orbodies 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:
the parameter named by the mapping key
locationlocationthreatened(older name, still accepted)
The parameter must be bound to a DFDElement (Process, DataStore, ExternalEntity, DataFlow, TrustBoundaryContainer, …). Required.
- Data flow
SPARTA looks for these parameters, in this order:
the parameter named by the mapping key
flowflowdf
The parameter must be bound to a DataFlow. Effectively required in 2026.0, see the warning below.
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 () 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 (), with Key
locationorflowand as Value the parameter name. Note that the key for the data flow isflow, notdf. For example, with the mappinglocation -> targetandflow -> channel, the patternpattern p(target : DFDElement, channel : DataFlow) { ... }places its threats ontargetand useschannelas their data flow. Placeholders then use the actual parameter names (<$target$>,<$channel$>).- Other parameters
Parameters such as
senderandrecipientare 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
scopeonly 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.
Warning
In SPARTA 2026.0, patterns without a data flow parameter (such as those of the STRIDE-per-element catalog) only work in the ThreatAnalysis view, which leaves the Flow column empty. With such patterns:
the command-line tools (
sparta-cliandsparta-ci) fail with aNullPointerExceptionwhile creating the threats;CSV Export in the ThreatAnalysis view stops at the first such threat and leaves an incomplete
threats.csv; Report Export shows no error but leaves an incompletethreatcatalog.tex(see Analysis results and exports);if a countermeasure with a non-empty
scopeis a candidate for such a threat (bound to the threatened element and mitigating its threat type), the risk calculation fails; the view then shows a risk of 0.
Give every 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,DataFloworTrustBoundaryContainer(without spaces). Any other attribute after the dot yields the textUNSUPPORTED ATTRIBUTE.
Placeholders are substituted in:
the Name of the leaf ThreatType, shown in the Name column of the ThreatAnalysis view and of the CSV export;
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. The XLSX output of the command-line tool shows the raw threat type name, without substitution.
Placeholders only read pattern parameters, not local variables. In 2026.0:
a placeholder for a parameter that the pattern does not declare makes SPARTA drop that entire name or description, not just the placeholder: for example, if the pattern has no parameter
server, the name<$server$> spoofedbecomes empty instead ofspoofed, and a description with that placeholder shows asDescription missing.;a placeholder for a parameter that is not bound to a model element (for example an
EString) causes aClassCastException;if the name of an element used in a placeholder contains
$or\, the substitution fails with anIllegalArgumentException.
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.0.
A threat type name such as
<$location$> spoofedand a description such as<$location$> is spoofed on <$df$>.make the results readable.DataFlow.senderandDataFlow.recipientare 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 asCommunicationbelow.
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, so in 2026.0 it only works in the ThreatAnalysis view (see the warning above):
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 (throughactualSenderandactualRecipient).processToProcessComm(location, p2, df)and the otherxToYCommhelpersFor processes, data stores and external entities: the first argument sends
dfto the second; the element types are fixed by the name.xThroughYCommvariants andflowThroughCommThe 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)andcontainmentContainment 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 , 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; SPARTA only prints them to the console (standard output).
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’s description is empty or a placeholder names a parameter that does not exist.
If the command-line analysis fails with a NullPointerException, or an export leaves an incomplete file, add a data flow parameter.
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.0
Patterns without a data flow parameter make the command-line analysis fail and the CSV and report exports incomplete (see The role of the data flow).
Pattern Dependencies does not work: leave it empty.
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 drops the entire name or description, 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.
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.0 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 all 41 keys on each of its threat types.
Keys
A key is an entry of the patterns map of a threat type or group (, 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 (all nine combinations exist).
A key without * places the threat on the sender; a trailing * places it on the recipient.
“Crosses a trust boundary” means that some TrustBoundaryContainer (directly or indirectly) contains one endpoint of the flow but not the other.
The keys are:
DataFlowThreat located at the data flow. No condition.
DataFlowThroughThreat 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.
ProcessTo*Process,ProcessTo*DataStoreandExternalEntityTo*ProcessThreat located at the data flow, if the flow crosses a trust boundary (despite the “To” in the name).
That is 41 keys in total. Other spellings, such as Process*ToProcess, never match.
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:
tis enabled;tor one of its enabled ancestors haskwith the valuetrue;neither
tnor any ancestor is disabled;no enabled ancestor-or-self has
kwith the valuefalse(afalseoverrides atrue);no ThreatSpecification for
tor 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
patternsentry with the valuefalse);disable threats located at a given element type (a
typesentry with the keyProcess,DataStore,ExternalEntityorDataFlowand the valuefalse).
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.