Command-line tools
SPARTA provides two command-line tools, built on the standalone libraries (see SPARTA Standalone libraries):
sparta-cliA tool for the threat elicitation and risk analysis of a SPARTA model from the command line, with exports of the threats to CSV, XLSX, text files, a statistics report or a code-quality report, or a submission to a server that is not part of SPARTA.
sparta-ciA tool for continuous integration pipelines, configured with a
.sparta.ymlfile, that analyzes a model and submits the threats and the model to a server that is not part of SPARTA.
Both tools use the threat elicitation and risk analysis engine of sparta-core, with the threat type catalogs that the model references.
Obtaining the tools
Each tool is a single runnable jar that contains all its dependencies (EMF, VIATRA, …):
Tool |
Maven coordinates |
Runnable jar |
Main class |
|---|---|---|---|
sparta-cli |
|
|
|
sparta-ci |
|
|
|
The jars without classifier (sparta-cli-2026.1.0.jar and sparta-ci-2026.1.0.jar) are library jars and cannot be run with java -jar.
Download the runnable jars from the GitHub release page. Put them in a folder without spaces in its path (see Known limitations in 2026.1). The 2026.1.0 artifacts are not available from the SPARTA Maven repository.
You can also build the jars from source.
Building the whole repository with mvn clean package from the repository root (see Building SPARTA from source) produces them in the target folders of the standalone modules:
standalone/sparta-cli/target/sparta-cli-2026.1.0-shaded.jarstandalone/sparta-ci/target/sparta-ci-2026.1.0-shaded.jar
The tools are compiled for Java 11 and run on Java 11 or later (tested with Java 11 and Java 21).
Run them with java -jar, for example:
java -jar sparta-cli-2026.1.0-shaded.jar -i MyModel.sparta -oc threats.csv
sparta-cli
Usage
sparta-cli loads one model, runs threat elicitation and risk analysis, and passes the resulting threats to every exporter whose option you give, so a single run can produce several outputs.
-h prints the following help (the jar name in the usage line is always sparta-cli.jar):
usage: java -jar sparta-cli.jar [-ab] [-cqr <arg>] [-h] [-i <arg>] [-it
<arg>] [-oc <arg>] [-os <arg>] [-ot <arg>] [-ox <arg>] [-sc <arg>]
[-st <arg>] [-su <arg>] [-v] [-ve]
-ab,--about About SPARTA
-cqr,--codequalityreport <arg> Export Code Quality Report
-h,--help Show help
-i,--input <arg> Model to analyze
-it,--inputtree <arg> Threat Tree to process
-oc,--outcsv <arg> CSV Export file
-os,--outstatistics <arg> Output txt file with threat statistics
-ot,--outtxt <arg> TXT export files
-ox,--outxlsx <arg> XLSX export file
-sc,--commitid <arg> Server submission commit id
-st,--token <arg> Server submission token
-su,--server <arg> Server submission url
-v,--verbose Provide verbose output
-ve,--version Show version info
A run proceeds as follows:
The arguments are parsed. An unknown option or a missing option argument prints an error and the help, and ends the run with exit status 1.
--about,--helpand--versionare handled, in that order. They do not stop the run:-h -i MyModel.spartaprints the help and also analyzes the model.If
-iis given, the model is loaded and analyzed, and the exporters run in this order: CSV, XLSX, text files, statistics, code-quality report, server submission. Without-i, nothing is analyzed or exported.
Options
No option is required and no option has a default value.
You can use the short and the long form of each option (for example -oc threats.csv or --outcsv threats.csv).
Short |
Long |
Argument |
Description |
|---|---|---|---|
|
|
file |
Model to analyze: a |
|
|
file |
Write the threats to a CSV file. |
|
|
file |
Write the threats to an Excel (XLSX) file. Does not work in 2026.1, see Known limitations in 2026.1. |
|
|
directory |
Write one text file per threat into this directory. |
|
|
file |
Write a plain-text statistics report. |
|
|
file |
Write a code-quality report (JSON). |
|
|
URL |
Submit the threats to this URL. Requires |
|
|
token |
Value of the |
|
|
commit id |
Value of the |
|
|
Print the help to standard output. |
|
|
|
Log the version, for example |
|
|
|
Log a short description of the tool. |
|
|
|
No effect in 2026.1. See Logging for more detailed output. |
|
|
|
file |
No effect in 2026.1. |
Input model
The
-ipath is always appended to the working directory, so it must be a relative path, such asMyModel.spartaormodels/MyModel.sparta. An absolute path fails with aFileNotFoundException.Only the extensions
.spartaand.securitydfd(the legacy name) are accepted. Any other extension fails withCannot create a resource for ....After loading the model,
sparta-cliloads every resource the model references, such as the threat type catalogs and solution catalogs that are linked to it (see Pairing existing threat type catalogs). Relative references are resolved against the location of the model file, so the catalog files must be at the same relative location as in your workspace. Catalog files that the model does not reference are not loaded, and there is no option to add catalogs or pattern files.If a referenced catalog cannot be loaded, for example because the file is missing or the reference is an Eclipse workspace URI (
platform:/resource/...), the run still succeeds, without a warning, but finds no threats from that catalog (no threats at all if no catalog could be loaded).Risk is calculated with a Monte Carlo simulation of 1000 samples and no fixed seed, so risk values differ slightly between runs. The order of the threats is not stable either.
Exports
After the analysis, sparta-cli passes the threats to every exporter whose option you give; you can combine several.
The first five exporters below write the threats to files; the server submission sends them to a server instead.
For the files:
Output paths are relative to the working directory.
Missing parent directories are not created: the exporter logs an error and the run continues.
Existing files are overwritten.
Text files use the default character encoding of the JVM (UTF-8 on Java 18 and later).
CSV (-oc)
One header line followed by one line per threat.
Fields are separated by ; and every field is enclosed in double quotes; quotes inside values are not escaped.
The format is the same as the CSV export of the ThreatAnalysis view; Analysis results and exports describes the columns.
For legacy key-based threat types (see Writing threat type patterns), Type and Name are both the name of the threat type.
Numbers have at most 4 decimals and are formatted with the default locale of the JVM, including grouping separators: for example 7,700.1363 in en-US and 7.700,1363 in nl-BE.
To get a predictable format, set the locale explicitly, for example java -Duser.language=en -Duser.country=US -jar ....
"Type";"Name";"Location";"Flow From";"Data Flow";"Flow To";"Vulnerability";"Risk";"Risk (lower)";"Risk (upper)";"Risk (potential)"
"Repudiation";"Contoso repudiates action";"Contoso";"Contoso";"Write";"Database";"1";"7,700.1363";"78.9585";"45,704.8636";"7,700.1363"
XLSX (-ox)
In 2026.1, this option fails; see Known limitations in 2026.1 and use -oc instead.
The columns of the XLSX file are those of ThreatXlsxOutputStream (see Exporters).
Text files (-ot)
Creates the directory (one level only) and writes one file per threat, with one line for each CSV column: the column name, a colon, a tab character, and the value:
Type: Tampering
Name: Database corrupted
Location: Database
Flow From: Contoso
Data Flow: Write
Flow To: Database
Vulnerability: 1
Risk: 23,763.1892
Risk (lower): 959.8419
Risk (upper): 118,439.7156
Risk (potential): 23,763.1892
The file name joins the raw threat type name, the threatened element name and the data flow name with _, replaces every run of other characters than ASCII letters, digits and _ with one space, and appends .txt.
For example, the threat type <$location$> corrupted on element Database and flow Write gives a file named location corrupted_Database_Write.txt preceded by a space.
Threats with the same threat type, element and flow overwrite each other’s file.
Statistics (-os)
Writes a plain-text report with statistics over all threats, computed with ThreatAggregationAnalysis (see Aggregated risk analyses):
the number of threats, threat types and element types;
the total risk reduction by the countermeasures;
the average number of threats per threatened element;
the risk reduction per threat type and per element type;
the number of threats per threat type and per element type, with their share of all threats.
For example:
SPARTA Threat Statistics Report
===============================
55 threats encountered (9 threat types, 3 element types)
Risk reduction: 13.33% (389262.23/449107.86)
Average threat count: 9.17
Threat Type Reduction Progress
------------------------------
<$location$> spoofed
42.82% (42323.46/74013.39)
...
Element Type Reduction Progress
-------------------------------
Process
14.47% (277608.07/324559.27)
...
Threat Type Threat Counts
-------------------------
<$location$> spoofed
10 (18.18%)
...
Element Type Threat Counts
--------------------------
Process
44 (80.00%)
...
The totals are sums of the expected risk values of the threats. The numbers in parentheses are residual risk / potential risk; the percentage is the reduction, 1 - residual / potential.
“Average threat count” is the average number of threats per threatened element.
Threat types are listed with their raw names (placeholders are not replaced), and element types by class name (
Process,DataFlow,DataStore,ExternalEntity, …).The order of the entries within a section is unspecified, and numbers use the default locale of the JVM.
Code-quality report (-cqr)
Writes a report in the format of GitLab Code Quality reports, so that a CI system can show the threats as code-quality findings on the model file. The report is a single-line JSON array with one entry per threat, which identifies the threat, gives it a severity based on its risk, and points to the model file.
For example:
[{"description":" location disrupted_Database_Write.txt","fingerprint":"795a653ba8f51ca08131f1d80afd2232","severity":"blocking","location":{"path":"Contoso.sparta","lines":{"begin":1}}}]
descriptionThe text file name of the threat (see Text files (-ot)).
fingerprintThe MD5 hash of
description. Threats with the same threat type, element and flow therefore share a fingerprint.severityThe risk of the threat relative to the highest potential risk among all threats (r = risk / maximum potential risk):
info(r < 0.125),minor(r < 0.375),major(r < 0.625),critical(r < 0.875) orblocking. GitLab expectsblockerfor the highest severity: it shows threats withblockingwith the severity “Unknown”, at the bottom of the list (see Using the tools in a CI pipeline for a workaround).locationpathis the path of the model file relative to the working directory, andlines.beginis always 1. For a model in a subdirectory, the path contains a double slash, for examplemodels//MyModel.sparta.
Server submission (-su, -st, -sc)
Note
The server is not part of SPARTA: to use the submission, you need a server of your own that accepts the request described below.
Sends the threats as JSON to a server, together with a token and a commit id.
-su gives the URL of the server, -st the token and -sc the commit id.
sparta-cli only sends the threats if all three options are given; if one of them is missing, it sends nothing and does not report this.
sparta-cli sends POST <url> with the headers Content-Type: application/json; utf-8, token: <token> and commitId: <commit id>.
The body is a JSON array with one object per threat, with these properties:
threatTypeName, threatName, description, vulnerability, risk, potentialRisk, threatenedElementName, threatenedElementTypeName, threatenedElementId, dataFlowName, dataFlowFromName and dataFlowToName.
The body is written in the default character encoding of the JVM (UTF-8 on Java 18 and later), whatever the Content-Type header says.
For example, one object of the array:
{"dataFlowName":"Write","dataFlowToName":"Database","dataFlowFromName":"Contoso","risk":7803.1698230017455,
"description":"Contoso claims not to have written to Database.","vulnerability":1.0,"threatName":"Contoso repudiates action",
"threatTypeName":"Repudiation","potentialRisk":7803.1698230017455,"threatenedElementTypeName":"Process",
"threatenedElementId":"652176954","threatenedElementName":"Contoso"}
threatenedElementId is an in-memory identifier that changes between runs.
The response body is logged, followed by SPARTA Server submission successful.
HTTP and connection errors are logged as IOError submitting to SPARTA Server: ...; the exit status stays 0.
Logging
sparta-cli logs to standard error at level INFO, in the form [main] INFO <logger> - <message>; the help goes to standard output.
The --version and --about texts are logged, so they also appear on standard error.
For more detail, set the log level with a system property:
java -Dorg.slf4j.simpleLogger.defaultLogLevel=debug -jar sparta-cli-2026.1.0-shaded.jar -i MyModel.sparta
At level debug, the log shows the working directory, the name of the loaded model and one Threat: ... line per threat; at level trace it also lists the threat types and threat specifications that were loaded.
The pattern parser also prints some lines to standard output, such as WARNING:Recursive pattern call: ... and empty lines.
These are harmless.
Exit status
sparta-cli exits with status 0 in most situations, including when an exporter fails.
Check the outputs yourself (for example, test that the expected files exist) if a pipeline must fail on errors.
Situation |
Exit status |
|---|---|
Successful run, run without options, |
0 |
Referenced catalogs not found (no threats) |
0 |
Exporter error (for example a missing output directory or an HTTP error) |
0 (error is logged) |
Unknown option or missing option argument |
1 |
Model not found, absolute model path, or unsupported file extension |
1 (uncaught exception) |
|
1 (uncaught exception) |
There is no option to fail on a risk threshold.
Examples
Analyze Contoso.sparta in the working directory and write a CSV file, text files, a statistics report and a code-quality report:
java -jar sparta-cli-2026.1.0-shaded.jar -i Contoso.sparta -oc threats.csv -ot txt -os stats.txt -cqr cqr.json
The same with long options, writing into an existing directory out:
java -jar sparta-cli-2026.1.0-shaded.jar --input Contoso.sparta --outcsv out/threats.csv --outtxt out/threats --outstatistics out/statistics.txt --codequalityreport out/gl-code-quality-report.json
Write the CSV with en-US number formatting:
java -Duser.language=en -Duser.country=US -jar sparta-cli-2026.1.0-shaded.jar -i Contoso.sparta -oc threats.csv
Submit the threats to a server:
java -jar sparta-cli-2026.1.0-shaded.jar -i Contoso.sparta -su https://server.example.org/api/submit -st <token> -sc <commit id>
A typical run logs:
[main] INFO be.kuleuven.cs.distrinet.sparta.cli.SpartaCliProcessor - LS: false
[main] INFO be.kuleuven.cs.distrinet.sparta.cli.SpartaCliProcessor - Rete: true
[main] INFO be.kuleuven.cs.distrinet.sparta.cli.SpartaCliProcessor - Running SPARTA Analysis ...
[main] INFO be.kuleuven.cs.distrinet.sparta.cli.cmd.export.ExportCSV - Exporting to csv
[main] INFO be.kuleuven.cs.distrinet.sparta.cli.cmd.export.ExportTXT - Exporting to txt files
[main] INFO be.kuleuven.cs.distrinet.sparta.cli.cmd.export.ExportStatistics - Exporting threat statistics
[main] INFO be.kuleuven.cs.distrinet.sparta.cli.cmd.export.ExportCQR - Exporting to cqr
sparta-ci
Note
The server that sparta-ci submits to is not part of SPARTA: you need a server of your own that accepts the request described below and in Server submission (-su, -st, -sc).
sparta-ci analyzes the model configured in .sparta.yml and submits the threats, together with the model, to a server.
It writes no local output files and ignores all command-line arguments (including --help).
Run it in the directory that contains .sparta.yml:
java -jar sparta-ci-2026.1.0-shaded.jar
A run proceeds as follows:
sparta-cireads.sparta.ymlfrom the working directory.It looks for a git repository, starting from the directory of
.sparta.ymland searching upward (theGIT_DIRenvironment variable is honored). If it finds one, the commit id ofHEADbecomes the commit id of the submission; a detachedHEAD, as in many CI checkouts, works as well.It analyzes the model exactly like
sparta-cli, so the same Input model rules apply.It builds a self-contained copy of the model: the catalogs and other SPARTA resources that the model references are copied into the model, and the legacy key-based
patternsandtypesmaps of threat types and threat specifications are cleared. The VQL patterns of the catalogs are kept. This copy is serialized as XMI (UTF-8).It sends
POST <server.url>with the headersContent-Type: application/json; utf-8,token: <server.token>andcommitId: <commit id>, and logs the response followed bySPARTA Server submission finished.
Configuration file
.sparta.yml has the following keys.
Unknown keys are ignored.
Key |
Required |
Meaning |
|---|---|---|
|
yes |
Path of the model, relative to the working directory ( |
|
yes |
URL to submit the results to. |
|
no |
Value of the |
|
no |
Commit id to send when no git repository is found. Inside a git repository, the |
|
no |
An integer. Read but not used in 2026.1. |
For example:
version: 1
input:
model: Contoso.sparta
server:
url: https://server.example.org/api/submit
token: <submission token>
overrideCommit: deadbeef # only used outside a git repository
Warning
Because the token is read literally from the file, do not commit a real token to your repository.
Payload
The request body is a JSON object with two properties:
threatListThe threats, with the same properties as the
sparta-cliserver submission (see Server submission (-su, -st, -sc)).modelThe self-contained model as an XMI string.
As with sparta-cli, the body is written in the default character encoding of the JVM (UTF-8 on Java 18 and later), whatever the Content-Type header says.
{"threatList":[{"dataFlowName":"Write", ... }, ...],"model":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<spartamodel:DFDModel ...>"}
Exit status
sparta-ci exits with status 0 even when the submission fails, so a failed submission does not fail a pipeline job.
Situation |
Result |
Exit status |
|---|---|---|
Successful run |
Results submitted |
0 |
No |
Logs |
0 |
Server unreachable or HTTP error |
Logs |
0 |
|
Logs an error |
0 |
|
|
1 |
Model not found, absolute path, or unsupported extension |
Uncaught exception |
1 |
Using the tools in a CI pipeline
The SPARTA 2026.1 repository contains no ready-made pipeline configuration.
You can run the tools in any CI system that can run Java.
For example, the following GitLab CI job runs sparta-cli on a model.
It assumes that the shaded jar and the model, with its catalogs at the referenced relative paths, are available in the job’s working directory:
threat-model:
image: eclipse-temurin:21-jre
script:
- java -jar sparta-cli-2026.1.0-shaded.jar -i model/MySystem.sparta -oc threats.csv -os threat-statistics.txt -cqr gl-code-quality-report.json
- test -s threats.csv
- sed -i 's/"severity":"blocking"/"severity":"blocker"/g' gl-code-quality-report.json
artifacts:
paths: [threats.csv, threat-statistics.txt]
reports:
codequality: gl-code-quality-report.json
The test -s threats.csv step makes the job fail when no CSV was written, because sparta-cli itself exits with status 0 on most errors.
It does not detect a run that finds no threats (for example when catalogs are missing): the CSV then contains only the header line.
The sed step replaces the severity blocking, which GitLab does not know, by blocker, so that GitLab shows the threats with the highest risk as “Blocker” instead of “Unknown”.
To use sparta-ci instead, commit a .sparta.yml in the directory the job runs from and run java -jar sparta-ci-2026.1.0-shaded.jar.
The commit id is then taken from the checked-out commit.
Keep in mind that sparta-ci reads the token from the file; with sparta-cli, you can pass the token on the command line (-st) from a protected CI variable, but sparta-cli does not send the model.
Known limitations in 2026.1
- XLSX export fails
-oxaborts the run withNoClassDefFoundError: org/apache/poi/util/POILogFactoryand exit status 1, leaving an empty file. The exporters that come after it (text files, statistics, code-quality report, server submission) do not run. The cause is a conflict between the Apache POI versions in the jar (see Known limitation: XLSX export). Use-ocinstead and open the CSV file in a spreadsheet program.- Catalogs with patterns without a data flow fail
Every threat must have a data flow in 2026.1. If a referenced catalog contains patterns that bind no
flowordfparameter, for example a STRIDE-per-element catalog, the analysis fails with aNullPointerExceptionbefore any exporter runs.FileNotFoundExceptionfor an existing model-i(andinput.modelin.sparta.yml) must be relative to the working directory.- Severity “Unknown” in GitLab
The code-quality report uses the severity
blockingfor the threats with the highest risk, but GitLab only knowsblocker. GitLab still reads the report, but shows these threats with the severity “Unknown”, at the bottom of the list. Replace the severity in the report before GitLab reads it, as in Using the tools in a CI pipeline.ProvisionExceptionat startupWhen the path of the jar contains a space, for example
C:\Users\Jane Doe\tools\sparta-cli-2026.1.0-shaded.jar, both tools abort before the analysis with acom.google.inject.ProvisionExceptionand exit status 1. The cause is aNoSuchFileExceptionfor the jar itself, with the space written as%20. Put the jar in a folder without spaces in its path..txtmodels insparta-cisparta-citries to convert aninput.modelthat ends withtxtfrom a simple YAML description into a model. This does not work in 2026.1: the conversion fails with aNullPointerException, and the converted model would not be found anyway. Use a.spartamodel.- Exit status 0 after errors
sparta-cliexits with status 0 in most situations, including when an exporter fails, andsparta-cialso when the submission fails. A CI job therefore does not fail by itself; see Using the tools in a CI pipeline for a check you can add.
Troubleshooting
- No threats found
The catalogs referenced by the model were not found. Check that the catalog files exist at the relative paths stored in the model, and that the model does not reference them with
platform:/resource/...URIs. See Input model.- Risk values differ between runs
The risk calculation uses Monte Carlo sampling without a fixed seed. Small differences between runs on the same model are expected; the order of the threats can also differ.
- Unexpected number format
CSV, text and statistics output use the default locale of the JVM. Set
-Duser.languageand-Duser.countryto choose a locale.