CtrlK
BlogDocsLog inGet started
Tessl Logo
PluginPublic

trysac/sarif-merge

Merge SARIF 2.1.0 logs from several scanners into one de-duplicated log and mark results new, unchanged or absent versus a baseline. Use when the user has several .sarif files or asks what a scan newly introduced.

Quality

97%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide
SecuritybySnyk

Low

Low-risk findings worth noting

Overview
Quality
Evals
Security
Files

merge-rules.mdreferences/

SARIF merge rules

Reference for scripts/sarif_merge.py. Behaviour is the same as the sarif_merge Python package.

Input validation (load_sarif)

CheckError code
Text larger than 50 MiB (52,428,800 bytes)input_too_large
Not valid JSON or nested too deeplyinvalid_json
Top level is not an object, runs is not a list, a run/tool/driver is not an object, tool.driver.name is empty, results is not a listinvalid_sarif
version missinginvalid_sarif
version is not 2.1.0unsupported_version
More than 100,000 results across all runstoo_many_results

Merge

  1. Runs are grouped by (tool.driver.name, semanticVersion or version or "").
  2. In each group the rule definitions are merged in first-seen order; the first definition of an id wins.
  3. The rule id of a result comes from ruleId, else rule.id, else tool.driver.rules[ruleIndex].id. A result without any rule id is an error.
  4. Each result gets a key (below). The first result with a key is kept, later ones count as duplicates.
  5. ruleIndex is recomputed against the merged rule list (removed if the rule has no definition).
  6. artifacts arrays are dropped and every artifactLocation.index is removed.
  7. The output run is a copy of the first run of the group with properties.sarifMerge = {inputResults, duplicates} added. Output runs are sorted by (name, version).
  8. An empty input list gives a log with runs: [].

Result key

SHA-256 of one of these strings:

  • With partialFingerprints.primaryLocationLineHash: ruleId|fp|<hash>
  • Otherwise: ruleId|uriBaseId|uri|startLine|message.text, where the uri has backslashes turned into / and a leading ./ removed.

Consequence: two scanners that report the same rule id at the same place with the same message are duplicates; different rule ids never collapse, even for the same line.

Baseline (compare_baseline)

Both logs are merged first. For each tool group present in the current log:

  • result key present in baseline: baselineState = "unchanged"
  • not present: "new"
  • baseline-only results are appended with "absent" and their rule definitions are copied into the rule list.
  • a tool group that does not exist in the baseline marks all its results "new".

--fail-on-new makes the command exit 1 if any result is new; absent and unchanged never fail the run.

Output

JSON with two-space indentation, UTF-8, written to the --output path. The output path is overwritten if it exists.

references

SKILL.md

tile.json