SARIF
| Full name | Static Analysis Results Interchange Format |
|---|---|
| Type | File format (JSON, UTF-8) |
| Current version | 2.1.0, OASIS Standard of 27 March 2020; Errata 01 approved 28 August 2023 |
| File extension | .sarif, optionally .sarif.json |
| Standards body | OASIS, SARIF Technical Committee |
| Read by | GitHub code scanning, SonarQube |
Every static analysis tool used to write its findings in a format of its own, usually XML or JSON with little else in common, and a large team running dozens of tools had that many formats to learn and no common way to file the results as bugs or count them.1 The Static Analysis Results Interchange Format (SARIF) is the OASIS standard that replaces those formats with one: a JSON file that a tool can write directly, or that another tool's output can be converted into.2 Version 2.1.0 is the current one. Static analysis scanners, linters (tools that flag mistakes and style problems in code) and dependency scanners write it, and platforms such as GitHub code scanning read it.34
Structure of a log
A SARIF file is called a log. Its top-level object holds the version, a link to the JSON schema and an array of runs. Each run describes one execution of one tool: tool.driver names the tool and lists the rules it applied, and results holds what it found.4 A producer with no run to report writes an empty runs array, and one that tried and failed writes null.2 The whole file is UTF-8.2
A minimal log with one finding:
{
"version": "2.1.0",
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
"runs": [{
"tool": { "driver": {
"name": "ExampleScanner",
"rules": [{ "id": "sql-concat", "defaultConfiguration": { "level": "error" } }]
}},
"results": [{
"ruleId": "sql-concat",
"level": "error",
"message": { "text": "Query text joined with request data." },
"locations": [{ "physicalLocation": {
"artifactLocation": { "uri": "src/orders.js" },
"region": { "startLine": 42 }
}}]
}]
}]
}The ruleId ties the result to a rule in the driver's list. The location points at a file, through an address (URI) that is either absolute or relative to the root of the project, and at a region of lines and columns inside it.24
Levels, kinds and classification
A result's level is note for a minor problem or a chance to improve the code, warning for a problem, and error for a serious one.2 A result can also record that a check passed (kind: "pass") or did not apply to the file ("notApplicable"), so a log can show what was tested as well as what failed.2
The standard asks tools not to mark a CWE entry with a tag such as CWE/622. A classification goes in a taxonomy: CWE is stored once in run.taxonomies, and each rule declares which entries it falls under.2 Tools that trace execution can attach codeFlows to a result: the path through the program that leads to the possible problem.2
Tracking results between runs
A scanner runs on every change, and a finding that was reported yesterday should not reappear as new today because a line was added above it. SARIF handles this with fingerprints, values that identify a result over time even when the file around it changes.2 A tool that compares a run with an earlier one sets baselineState on each result to new, unchanged, updated or absent; if one result has it, every result in the run must.2
A suppressed result stays in the log but is left out of error lists and bug counts. The suppression's kind is inSource when a construct of the programming language sets it, such as the .NET SuppressMessage attribute, and external when the decision is kept in a separate store.2
Upload to GitHub code scanning
GitHub reads only SARIF 2.1.0, and of that only a listed subset of properties.4 Semgrep writes the format with --sarif, Trivy with --format sarif, and ESLint through a formatter plugin.531 A continuous integration workflow then uploads the file:
permissions:
security-events: write
# the next two are needed only in private repositories
actions: read
contents: read
steps:
- uses: actions/checkout@v6
# a step here runs the scanner and writes results.sarif
- uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: results.sarif
category: my-analysis-toolA second upload for the same commit, tool and category replaces the first, so one tool that writes several result files, for example one per part of a large repository, needs a different category for each.6 ESLint exits with code 1 when it reports anything, so GitHub's example workflow adds || true to the scan step and the upload still runs.6
GitHub matches results across uploads by the partialFingerprints property, and the upload action tries to compute it from the source files when the tool left it out. The file paths and the ruleId must stay the same between runs; when a path changes, GitHub closes the old alert and opens a new one for the same problem.4
For security rules, GitHub reads severity from the rule property security-severity, a score above 0.0 and up to 10.0, and shows it as low (0.1 to 3.9), medium (4.0 to 6.9), high (7.0 to 8.9) or critical (over 9.0). A rule that sets it has its results treated as security results. A rule's precision, from low to very-high, says how often its findings are real, and GitHub lists high-precision results first.4
| Item | Maximum | Shown |
|---|---|---|
| File size, gzip-compressed | 10 MB | |
| Runs per file | 20 | All |
| Results per run | 25,000 | Top 5,000 by severity |
| Locations per result | 1,000 | 100 |
| Tags per rule | 20 | 10 |
Sensitive data in a log
Some fields describe the machine that ran the scan. Absolute paths name the user account (file:///C:/Users/Mary/...), the recorded command line can show the machine's directory layout, and the standard warns that environment variables are likely to reveal highly sensitive information.2 It marks such fields as redactable: a tool or post-processor that removes the value puts one of the run's redactionTokens in its place.2 A region can also carry a snippet of the source, so a log passed outside the team can contain lines of private code.2
See also
- Static application security testing
- Software composition analysis
- Secret scanning
- Vulnerability scanning
- Common Weakness Enumeration
- CycloneDX and SPDX
- Category: Testing and standards
References
- a b Microsoft. "Introduction". SARIF tutorials. GitHub.
- a b c d e f g h i j k l m n OASIS (28 August 2023). "Static Analysis Results Interchange Format (SARIF) Version 2.1.0 Plus Errata 01". OASIS Standard.
- a b "Reporting". Trivy documentation. Aqua Security.
- a b c d e f "SARIF support for code scanning". GitHub Docs. GitHub.
- back "CLI reference". Semgrep Docs. Semgrep.
- a b "Uploading a SARIF file to GitHub". GitHub Docs. GitHub.