From 40cc5867b108140d16666a729c0bfb36dcc1157d Mon Sep 17 00:00:00 2001 From: Timothy Wayne Gregg Date: Sun, 25 Oct 2026 19:26:31 -0400 Subject: [PATCH 1/6] Implement standalone private report projection to SARIF and NDJSON --- .github/workflows/tests.yml | 37 + .gitignore | 3 + AGENTS.md | 20 +- BRAND_ASSETS.md | 4 + LICENSING.md | 3 + README.md | 116 +- SHA256SUMS | 1 + examples/report.json | 74 + scan_results_bridge.py | 787 +++++++ schemas/OASIS-LICENSE.md | 7 + schemas/sarif-schema-2.1.0.json | 3389 +++++++++++++++++++++++++++++++ test_bridge.py | 120 ++ tools/validate_sarif.py | 17 + 13 files changed, 4562 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/tests.yml create mode 100644 .gitignore create mode 100644 BRAND_ASSETS.md create mode 100644 SHA256SUMS create mode 100644 examples/report.json create mode 100644 scan_results_bridge.py create mode 100644 schemas/OASIS-LICENSE.md create mode 100644 schemas/sarif-schema-2.1.0.json create mode 100644 test_bridge.py create mode 100644 tools/validate_sarif.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..9a9fdd2 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,37 @@ +name: Tests + +on: + push: + pull_request: + workflow_dispatch: + +permissions: + contents: read + +jobs: + test: + name: Python ${{ matrix.python }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + timeout-minutes: 10 + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + python: ['3.10', '3.14'] + steps: + - name: Check out repository + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + persist-credentials: false + - name: Set up Python + uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6 + with: + python-version: ${{ matrix.python }} + - name: Run local-only tests + run: python -m unittest -v + - name: Check CLI help + run: python scan_results_bridge.py --help + - name: Install optional schema validation dependency + run: python -m pip install jsonschema==4.25.1 + - name: Validate emitted SARIF against bundled OASIS schema + run: python tools/validate_sarif.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9ce9046 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +*.py[cod] +.venv*/ diff --git a/AGENTS.md b/AGENTS.md index 3ad79b5..8607f21 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,16 +1,10 @@ # Repository instructions Read README.md, CONTRIBUTING.md, SECURITY.md and LICENSING.md before changes. -This is optional supporting infrastructure for node2shell-check issue #12. -Keep the Python entry point independently usable with the standard library. -Never execute native/package code, run Docker, extract archive members to disk, -follow links, infer runtime versions from tags/filenames, or expose config Env, -Cmd, hostnames, credentials or registry data. Preserve no-network defaults, -whiteout ordering, data/structure/expansion limits, exact digest evidence, -uncertainty, consumer provenance and protected/atomic publication. - -Use synthetic local fixtures only. Run python -m unittest -v, actual CLI help -and git diff --check. GitHub Copilot must review published changes; address and -resolve findings and read exact-head hosted CI before merging. Report local -checks, hosted checks and artifact/runtime observations separately. Preserve -unrelated work and uncertain inputs. Never shut down or terminate WSL. +This is optional offline report conversion for node2shell-check issue #14. +Keep the entry point standalone and stdlib-only. No uploads, network requests, +credentials or target execution. Preserve uncertainty and not_tested; do not +fabricate source locations. Keep bounds, privacy projection, stable fingerprints, +input protection and atomic output. Test synthetic reports only. +Run python -m unittest -v, CLI help and git diff --check. Require GitHub Copilot +review and exact-head hosted CI before merge. Never terminate or shut down WSL. diff --git a/BRAND_ASSETS.md b/BRAND_ASSETS.md new file mode 100644 index 0000000..019f1c4 --- /dev/null +++ b/BRAND_ASSETS.md @@ -0,0 +1,4 @@ +# Brand assets + +No logo or trademark license is granted by the code license. CompleteTech LLC +names identify the publisher; obtain separate permission for other brand uses. diff --git a/LICENSING.md b/LICENSING.md index 51caad3..e44faa7 100644 --- a/LICENSING.md +++ b/LICENSING.md @@ -31,3 +31,6 @@ CompleteTech LLC names and logos are not covered by the code license. See Contribution terms are described in [CONTRIBUTING.md](CONTRIBUTING.md#licensing-of-contributions), including the grant that permits CompleteTech LLC to include contributions in both editions. + +The unmodified OASIS SARIF schema and accompanying terms under schemas/ retain +their upstream licensing, separately from the checker code license. diff --git a/README.md b/README.md index a8e52c1..76786c0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,113 @@ -# scan-results-bridge - -Offline checker report conversion. Implementation under review; no transports or uploads. +# scan-results-bridge + +Optional offline report conversion for the CompleteTech security checker family. +Python 3.10+, one standalone file, standard library only. It converts existing +JSON reports into SARIF 2.1.0 or NDJSON. It never scans targets, executes code, +loads packages, reads credentials, or uploads data. Individual checkers do not +depend on this tool. Code: AGPL-3.0 or commercial; see LICENSING.md. + +```sh +python scan_results_bridge.py --input examples/report.json --format sarif --output report.sarif +python scan_results_bridge.py --input examples/report.json --format ndjson --include-relative-paths +python scan_results_bridge.py --input node-report.json --input-schema node2shell-v1 --fail-on either +python -m unittest -v +python scan_results_bridge.py --help +``` + +The example is synthetic. Output defaults to stdout. Existing files require +`--force`; checker/input aliases and hardlinks remain protected. Rendering occurs +before an atomic file publication. Interruptions exit 130 without publication +retry; interrupted stdout or an interrupt at the commit boundary may leave an +incomplete/indeterminate publication. Keep unrelated reports out of commits. + +## Accepted contracts + +Select the schema explicitly; one profile applies to all inputs in an invocation. +Unsupported tools/versions and malformed or contradictory canonical evidence fail +closed with exit 2. The canonical validator is bundled from +[Sharp's common contract](https://github.com/CompleTetech-Security/sharp-rsvg-rce-check/blob/14955717ab29676828dc215e993d987c40e3f575/vendor/common.py) +under the same code license; no installed shared package is required. + +| Profile | Input | +| --- | --- | +| `contract-v1.0` (default) | Complete schema 1.0 object with tool/rules/results, including semantic evidence-reference validation | +| `node2shell-v1` | Legacy unversioned node2shell-check tool_version 1.0.0 JSON; named adapter only, not a universal schema | +| `copyescape-v1.1` | copyescape-check schema_version `1.1` | +| `vm2-v1.1` | vm2-nesting-check report_schema_version `1.1` | +| `simplegit-v1.1` | simplegit-rce-check report_schema_version `1.1` | +| `atlassian-v1` | atlassian-cve-2026-21589-check integer schema_version 1 | +| `flowise-v1` | flowise-cve-2026-69254-check integer schema_version 1; version_status maps to normalized status | + +Legacy adapters validate consumed envelope/status/exploitability/version fields; +they do not claim validation of every unused legacy report field. Threat metadata +is kept separate from local `exploitability: not_tested`. No input status becomes +confirmed exploitation, and fixed-version observations never become safety claims. +Confidence is retained when its vocabulary matches; otherwise it is `unknown`. +The original evidence receives a deterministic digest for local reconciliation. + +## Privacy and evidence + +Default exports use a structural privacy projection: asset labels, URLs, paths, +arbitrary object keys, evidence prose, versions, secrets and original remediation +text are replaced by SHA-256 identifiers. Known evidence kinds/states, confidence, +booleans/numbers and uncertainty survive. Exported remediation directs the reader +to the original private report and vendor guidance. This deliberately omits raw +prose rather than claiming a regex can remove every possible credential. Retain +the original report securely to interpret the projected evidence. Hashes are +linkable and dictionary-guessable; they are not anonymous identifiers. Public tool +and rule identifiers are retained as required by SARIF. + +Relative source paths are also omitted unless `--include-relative-paths` is set. +That switch explicitly permits publishing those reported paths; review filenames +for secrets before enabling it. Only bounded relative paths and integer source +lines from source evidence qualify. Inventory paths, network URLs and missing +locations do not produce fabricated code locations. Absolute paths, drive/URL +schemes, backslashes, empty/traversal components and control characters are rejected +as locations. Valid Unicode paths are percent-encoded in SARIF URIs. + +Fingerprints combine tool, rule, private asset identity, component instance and +reported source location; they exclude status, run time and input ordering. +This preserves identity across status changes at the same location. Moving a line +or changing an asset identifier changes its fingerprint; this is not semantic +code matching. Exact projected duplicates collapse; conflicting statuses or +evidence remain separate observations. Results and rules have deterministic +ordering, with no generated timestamp. All output is JSON escaped. + +## Severity and CI policy + +SARIF uses warning for potentially_affected/precondition_present/likely_exposed, +note for unknown, unsupported, fixed or mitigated observations. This is a triage +level, not a CVSS score or an exploitability claim. Original status/confidence and +complete state remain properties; incomplete SARIF invocations are unsuccessful. +NDJSON ends with an explicit summary record, including empty results. + +Exit 0 means complete conversion with selected policy satisfied. `--fail-on` +findings, unknown or either returns 1 **after** successful output. Unknown includes +unsupported_runtime and source_discrepancy. Default none does not fail on findings. +Operational/malformed/unsupported input or incomplete input returns 2. A policy +exit never suppresses results. No HEC/syslog transport or credential configuration +is implemented; conversion remains offline. + +Bounds: 20 inputs, four MiB each, 16 MiB combined, depth 40/250,000 JSON nodes per +input, 16,384 characters per string, 10,000 combined results, 32 MiB output. A +single invocation uses one profile. No silent truncation. Local inputs and output +directories should be stable and controlled by the operator; this is not a +concurrent hostile-filesystem service. + +## SARIF schema validation + +The unmodified official OASIS schema is bundled under `schemas/` with its original +license terms. The checker CLI and normal tests need no third-party dependencies. +An optional development check uses jsonschema; CI runs it locally against the +bundled schema, including source, inventory-only, Unicode, findings, unknowns, +and empty/incomplete runs. No remote schema references are fetched by tests. + +```sh +python -m pip install jsonschema==4.25.1 +python tools/validate_sarif.py +``` + +Sources: [OASIS SARIF schema](https://github.com/oasis-tcs/sarif-spec/blob/main/sarif-2.1/schema/sarif-schema-2.1.0.json), +[GitHub SARIF support](https://docs.github.com/en/code-security/reference/code-scanning/sarif-files/sarif-support). +Schema validation is format verification; it does not prove GitHub ingestion or +live code-scanning display. No upload or production acceptance was performed. diff --git a/SHA256SUMS b/SHA256SUMS new file mode 100644 index 0000000..45a0973 --- /dev/null +++ b/SHA256SUMS @@ -0,0 +1 @@ +d8ff44637966e10e6a9ec1a72cf527e4077ec7de2ba3896eb03859113e6f7b23 scan_results_bridge.py diff --git a/examples/report.json b/examples/report.json new file mode 100644 index 0000000..15f938d --- /dev/null +++ b/examples/report.json @@ -0,0 +1,74 @@ +{ + "schema_version": "1.0", + "tool": { + "name": "synthetic-check", + "version": "1.0.0" + }, + "rules": { + "snapshot_id": "synthetic-1", + "verified_at": "2026-10-25", + "sha256": null + }, + "complete": true, + "limitations": [], + "results": [ + { + "asset_id": "private-asset", + "component": { + "name": "node", + "version": "24.22.0", + "build_source": "unknown" + }, + "rule_id": "CVE-2026-111497", + "status": "unknown", + "version_assessment": "unknown", + "confidence": "unknown", + "evidence": [ + { + "id": "e1", + "kind": "source", + "state": "candidate", + "detail": "token=SECRET https://private.invalid?q=SECRET", + "path": "src/worker α.js", + "line": 4 + }, + { + "id": "v1", + "kind": "version", + "state": "present", + "detail": "24.22.0 operator reported" + } + ], + "preconditions": [], + "mitigation": { + "state": "unknown", + "evidence_ids": [] + }, + "reachability": { + "state": "not_tested", + "evidence_ids": [], + "authorized": false, + "asset_id": "private-asset", + "component": "node" + }, + "threat": { + "kev": { + "state": "unknown", + "as_of": null, + "source": null + }, + "vendor_exploitation": { + "state": "unknown", + "as_of": null, + "source": null + } + }, + "exploitability": "not_tested", + "reasons": [], + "recommendation": "Inspect C:/private/path token=SECRET", + "sources": [ + "https://nodejs.org/en/blog/vulnerability/october-2026-security-releases" + ] + } + ] +} diff --git a/scan_results_bridge.py b/scan_results_bridge.py new file mode 100644 index 0000000..f20b14d --- /dev/null +++ b/scan_results_bridge.py @@ -0,0 +1,787 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-CompleteTech-Commercial +# Copyright (c) 2026 CompleteTech LLC. See LICENSING.md. +"""Vendoring-friendly checker contract, validation and offline reports. Python 3.10+.""" +from __future__ import annotations + +import csv +import base64 +import hashlib +import html +import io +import json +import math +import os +import re +import stat +import tempfile +from copy import deepcopy +from datetime import date +from pathlib import Path +from urllib.parse import urlsplit + +CONTRACT_VERSION = "1.0" +COMMON_VERSION = "0.1.0" +MAX_JSON_BYTES = 4 * 1024 * 1024 +STATUSES = ( + "potentially_affected", "precondition_present", "likely_exposed", + "mitigated_configuration", "fixed_version_reported", "unsupported_runtime", "unknown", +) +VERSION_STATES = ("affected", "fixed_reported", "not_affected", "unsupported", "unknown") +EVIDENCE_STATES = ("present", "absent", "unknown", "conflicting", "candidate") +CONDITION_STATES = ("present", "absent", "unknown", "conflicting") +FINDING_STATUSES = frozenset({"potentially_affected", "precondition_present", "likely_exposed", "unsupported_runtime"}) + + +class ContractError(ValueError): + """Invalid, ambiguous or inconsistent canonical data. Messages omit values.""" + + +def _text(max_length=2048, *, min_length=0): + return {"type": "string", "minLength": min_length, "maxLength": max_length, + "pattern": r"^[^\x00-\x1f\x7f-\x9f]*(?![\s\S])"} + + +def _enum(values): + return {"type": "string", "enum": list(values)} + + +def _object(properties, required=None): + return {"type": "object", "properties": properties, + "required": list(properties if required is None else required), "additionalProperties": False} + + +def _array(items, maximum=1000, minimum=0): + return {"type": "array", "items": items, "minItems": minimum, "maxItems": maximum} + + +ID_SCHEMA = {"type": "string", "pattern": r"^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}(?![\s\S])", "maxLength": 128} +DATE_SCHEMA = {"type": "string", "format": "date"} +URL_SCHEMA = {"type": "string", "format": "uri", "maxLength": 2048} +NULLABLE_DATE = {"anyOf": [DATE_SCHEMA, {"type": "null"}]} +NULLABLE_URL = {"anyOf": [URL_SCHEMA, {"type": "null"}]} +VERSION_SCHEMA = {"anyOf": [_text(128, min_length=1), {"type": "null"}]} +EVIDENCE_SCHEMA = _object({ + "id": ID_SCHEMA, + "kind": _enum(("version", "configuration", "source", "reachability", "mitigation", "inventory")), + "state": _enum(EVIDENCE_STATES), "detail": _text(2048), + "path": {"type": "string", "format": "relative-path", "maxLength": 512}, + "line": {"type": "integer", "minimum": 1, "maximum": 100000000}, +}, required=("id", "kind", "state", "detail")) +CONDITION_SCHEMA = _object({"id": ID_SCHEMA, "state": _enum(CONDITION_STATES), + "evidence_ids": _array(ID_SCHEMA, 100)}) +MITIGATION_SCHEMA = _object({"state": _enum(("observed", "not_observed", "unknown", "conflicting")), + "evidence_ids": _array(ID_SCHEMA, 100)}) +REACHABILITY_SCHEMA = _object({ + "state": _enum(("not_tested", "metadata_observed", "unknown")), + "evidence_ids": _array(ID_SCHEMA, 100), "authorized": {"type": "boolean"}, + "asset_id": ID_SCHEMA, "component": _text(128, min_length=1), +}) + + +def _threat_schema(states): + return _object({"state": _enum(states), "as_of": NULLABLE_DATE, "source": NULLABLE_URL}) + + +THREAT_SCHEMA = _object({ + "kev": _threat_schema(("listed", "not_listed", "unknown")), + "vendor_exploitation": _threat_schema(("reported", "not_reported", "unknown")), +}) +RESULT_SCHEMA = _object({ + "asset_id": ID_SCHEMA, + "component": _object({"name": _text(128, min_length=1), "version": VERSION_SCHEMA, + "build_source": _enum(("upstream", "vendor", "custom", "unknown"))}), + "rule_id": ID_SCHEMA, "status": _enum(STATUSES), + "version_assessment": _enum(VERSION_STATES), + "confidence": _enum(("low", "medium", "high", "unknown")), + "evidence": _array(EVIDENCE_SCHEMA, 1000), "preconditions": _array(CONDITION_SCHEMA, 100), + "mitigation": MITIGATION_SCHEMA, "reachability": REACHABILITY_SCHEMA, + "threat": THREAT_SCHEMA, "exploitability": {"const": "not_tested"}, + "reasons": _array(_text(2048), 100), "recommendation": _text(4096), + "sources": _array(URL_SCHEMA, 100), +}) +REPORT_SCHEMA = _object({ + "schema_version": {"const": CONTRACT_VERSION}, + "tool": _object({"name": ID_SCHEMA, "version": _text(64, min_length=1)}), + "rules": _object({ + "snapshot_id": ID_SCHEMA, "verified_at": DATE_SCHEMA, + "sha256": {"anyOf": [{"type": "string", "pattern": r"^[a-f0-9]{64}(?![\s\S])"}, {"type": "null"}]}, + }), + "complete": {"type": "boolean"}, + "limitations": _array(_text(2048), 1000), "results": _array(RESULT_SCHEMA, 10000), +}) +SOURCE_SCHEMA = _object({"id": ID_SCHEMA, "url": URL_SCHEMA, "publisher": _text(128, min_length=1), + "verified_at": DATE_SCHEMA}) +CLAIM_SCHEMA = _object({"id": ID_SCHEMA, "description": _text(4096, min_length=1), + "source_ids": _array(ID_SCHEMA, 100, 1)}) +BRANCH_SCHEMA = _object({ + "branch": _text(64, min_length=1), "introduced": VERSION_SCHEMA, + "fixed": VERSION_SCHEMA, "last_affected": VERSION_SCHEMA, + "source_ids": _array(ID_SCHEMA, 100, 1), +}) +RULE_SCHEMA = _object({ + "id": ID_SCHEMA, "revision": {"type": "integer", "minimum": 1}, + "title": _text(256, min_length=1), "component": _text(128, min_length=1), + "advisories": _array(ID_SCHEMA, 100), "enabled": {"type": "boolean"}, + "verification_status": _enum(("verified", "unverified", "disputed")), + "verified_at": NULLABLE_DATE, "version_scheme": _enum(("semver", "vendor")), + "affected": _array(BRANCH_SCHEMA, 100), "preconditions": _array(CLAIM_SCHEMA, 100), + "mitigations": _array(CLAIM_SCHEMA, 100), "sources": _array(SOURCE_SCHEMA, 100), + "notes": _array(_text(4096), 100), +}) +SNAPSHOT_SCHEMA = _object({ + "schema_version": {"const": CONTRACT_VERSION}, "snapshot_id": ID_SCHEMA, + "created_at": DATE_SCHEMA, "rules": _array(RULE_SCHEMA, 1000), +}) +INVENTORY_SCHEMA = _object({ + "schema_version": {"const": CONTRACT_VERSION}, + "records": _array(_object({ + "asset_id": ID_SCHEMA, "component": _text(128, min_length=1), "version": VERSION_SCHEMA, + "build_source": _enum(("upstream", "vendor", "custom", "unknown")), + "evidence": _array(EVIDENCE_SCHEMA, 1000), + }), 10000, 1), +}) + + +def _check_format(value, fmt, path): + if fmt == "date": + try: + if not re.fullmatch(r"\d{4}-\d{2}-\d{2}", value): + raise ValueError + date.fromisoformat(value) + except ValueError: + raise ContractError(f"{path}: invalid ISO date") from None + elif fmt == "uri": + try: + parsed = urlsplit(value) + valid = (parsed.scheme == "https" and parsed.hostname and parsed.username is None + and parsed.password is None and not parsed.query and not parsed.fragment + and not any(ord(c) <= 32 or ord(c) >= 127 for c in value) and "\\" not in value) + _ = parsed.port + except ValueError: + valid = False + if not valid: + raise ContractError(f"{path}: expected credential-free HTTPS source URL without query or fragment") + elif fmt == "relative-path": + pieces = value.split("/") + if (not value or value.startswith("/") or "\\" in value or ":" in value + or any(part in {"", ".", ".."} for part in pieces) + or any(ord(c) < 32 or 127 <= ord(c) <= 159 for c in value)): + raise ContractError(f"{path}: expected normalized relative path") + + +def validate_schema(value, schema, path="$", depth=0): + """Validate this repository's bounded schema vocabulary; never resolve references.""" + if depth > 40: + raise ContractError(f"{path}: nesting limit exceeded") + if "anyOf" in schema: + for alternative in schema["anyOf"]: + try: + validate_schema(value, alternative, path, depth + 1) + return + except ContractError: + pass + raise ContractError(f"{path}: no permitted type or value matched") + if "const" in schema and (type(value) is not type(schema["const"]) or value != schema["const"]): + raise ContractError(f"{path}: invalid constant") + typ = schema.get("type") + types = {"object": dict, "array": list, "string": str, "integer": int, "boolean": bool, "null": type(None)} + if typ and type(value) is not types[typ]: + raise ContractError(f"{path}: expected {typ}") + if "enum" in schema and value not in schema["enum"]: + raise ContractError(f"{path}: unsupported value") + if typ == "object": + properties = schema["properties"] + if set(value) - set(properties): + raise ContractError(f"{path}: unexpected field") + if set(schema["required"]) - set(value): + raise ContractError(f"{path}: missing required field") + for key, item in value.items(): + validate_schema(item, properties[key], f"{path}.{key}", depth + 1) + elif typ == "array": + if not schema.get("minItems", 0) <= len(value) <= schema.get("maxItems", 10000): + raise ContractError(f"{path}: item count outside bounds") + for index, item in enumerate(value): + validate_schema(item, schema["items"], f"{path}[{index}]", depth + 1) + elif typ == "string": + if not schema.get("minLength", 0) <= len(value) <= schema.get("maxLength", 4096): + raise ContractError(f"{path}: string length outside bounds") + if "pattern" in schema and re.fullmatch(schema["pattern"], value) is None: + raise ContractError(f"{path}: invalid string") + if "format" in schema: + _check_format(value, schema["format"], path) + elif typ == "integer": + if not schema.get("minimum", -2**63) <= value <= schema.get("maximum", 2**63-1): + raise ContractError(f"{path}: integer outside bounds") + + +def _evidence_map(evidence): + by_id = {item["id"]: item for item in evidence} + if len(by_id) != len(evidence): + raise ContractError("duplicate evidence identifier") + for item in evidence: + if "line" in item and "path" not in item: + raise ContractError("source line requires a relative path") + return by_id + + +def _references(ids, evidence): + if len(set(ids)) != len(ids) or any(key not in evidence for key in ids): + raise ContractError("unknown or duplicate evidence reference") + return [evidence[key] for key in ids] + + +def validate_result(result): + validate_schema(result, RESULT_SCHEMA) + evidence = _evidence_map(result["evidence"]) + conditions = result["preconditions"] + if len({item["id"] for item in conditions}) != len(conditions): + raise ContractError("duplicate precondition identifier") + for condition in conditions: + refs = _references(condition["evidence_ids"], evidence) + if condition["state"] in {"present", "absent"}: + if not refs or not all(item["state"] == condition["state"] for item in refs): + raise ContractError("established precondition requires matching observed evidence") + mitigation = result["mitigation"] + mrefs = _references(mitigation["evidence_ids"], evidence) + if mitigation["state"] == "observed" and (not mrefs or not all(item["state"] == "present" for item in mrefs)): + raise ContractError("observed mitigation requires observed evidence") + reachability = result["reachability"] + rrefs = _references(reachability["evidence_ids"], evidence) + if reachability["asset_id"] != result["asset_id"] or reachability["component"] != result["component"]["name"]: + raise ContractError("reachability belongs to a different asset or component") + if reachability["state"] == "metadata_observed": + if not reachability["authorized"] or not rrefs or not all(item["kind"] == "reachability" and item["state"] == "present" for item in rrefs): + raise ContractError("reachability requires explicit authorization and matching metadata evidence") + for threat in result["threat"].values(): + if threat["state"] != "unknown" and (threat["as_of"] is None or threat["source"] is None): + raise ContractError("external threat assertion requires dated source") + status = result["status"] + version_state = result["version_assessment"] + version_evidence = [item for item in evidence.values() if item["kind"] == "version"] + if version_state in {"affected", "fixed_reported", "not_affected", "unsupported"}: + if (result["component"]["version"] is None or not version_evidence + or not all(item["state"] == "present" for item in version_evidence)): + raise ContractError("version assessment requires exact, consistent version evidence") + if status != "unknown" and not result["sources"]: + raise ContractError("assessment requires primary source references") + expected = {"fixed_version_reported": "fixed_reported", "unsupported_runtime": "unsupported", + "potentially_affected": "affected", "precondition_present": "affected", + "likely_exposed": "affected", "mitigated_configuration": "affected"} + if status in expected and version_state != expected[status]: + raise ContractError("status contradicts version assessment") + if status == "fixed_version_reported" and result["component"]["build_source"] in {"vendor", "custom"}: + raise ContractError("vendor or custom build cannot be cleared by upstream version") + if status in {"precondition_present", "likely_exposed"}: + if not conditions or not all(item["state"] == "present" for item in conditions): + raise ContractError("status requires all declared preconditions to be established") + if status == "likely_exposed" and reachability["state"] != "metadata_observed": + raise ContractError("likely_exposed requires authorized same-component reachability evidence") + if status == "mitigated_configuration" and mitigation["state"] != "observed": + raise ContractError("mitigated_configuration requires an observed mitigation") + return result + + +def validate_report(report): + validate_schema(report, REPORT_SCHEMA) + for result in report["results"]: + validate_result(result) + return report + + +def make_result(asset_id, component, rule_id, status="unknown", *, version=None, + build_source="unknown", version_assessment="unknown", evidence=None, + preconditions=None, mitigation=None, reachability=None, threat=None, + reasons=None, recommendation="", sources=None, confidence="unknown"): + result = { + "asset_id": asset_id, "component": {"name": component, "version": version, "build_source": build_source}, + "rule_id": rule_id, "status": status, "version_assessment": version_assessment, "confidence": confidence, + "evidence": deepcopy(evidence or []), "preconditions": deepcopy(preconditions or []), + "mitigation": deepcopy(mitigation or {"state": "unknown", "evidence_ids": []}), + "reachability": deepcopy(reachability or {"state": "not_tested", "evidence_ids": [], + "authorized": False, "asset_id": asset_id, "component": component}), + "threat": deepcopy(threat or { + "kev": {"state": "unknown", "as_of": None, "source": None}, + "vendor_exploitation": {"state": "unknown", "as_of": None, "source": None}, + }), + "exploitability": "not_tested", "reasons": deepcopy(reasons or []), + "recommendation": recommendation, "sources": deepcopy(sources or []), + } + return validate_result(result) + + +def make_report(tool, tool_version, snapshot_id, rules_as_of, results, *, complete=True, + limitations=None, snapshot_digest=None): + report = {"schema_version": CONTRACT_VERSION, "tool": {"name": tool, "version": tool_version}, + "rules": {"snapshot_id": snapshot_id, "verified_at": rules_as_of, "sha256": snapshot_digest}, + "complete": complete, "limitations": deepcopy(limitations or []), "results": deepcopy(results)} + return validate_report(report) + + +def validate_rule(rule): + validate_schema(rule, RULE_SCHEMA) + source_ids = {source["id"] for source in rule["sources"]} + if len(source_ids) != len(rule["sources"]): + raise ContractError("duplicate rule source identifier") + for entry in rule["affected"] + rule["preconditions"] + rule["mitigations"]: + if len(set(entry["source_ids"])) != len(entry["source_ids"]) or not set(entry["source_ids"]) <= source_ids: + raise ContractError("rule contains unresolved source reference") + if rule["enabled"]: + if rule["verification_status"] != "verified" or not rule["verified_at"] or not source_ids or not rule["affected"]: + raise ContractError("enabled rules require verified primary-source version boundaries") + if any(branch["introduced"] is None and branch["fixed"] is None and branch["last_affected"] is None for branch in rule["affected"]): + raise ContractError("enabled rule branch has no version boundary") + if any(source["verified_at"] > rule["verified_at"] for source in rule["sources"]): + raise ContractError("rule verification predates source verification") + return rule + + +def validate_snapshot(snapshot): + validate_schema(snapshot, SNAPSHOT_SCHEMA) + if len({rule["id"] for rule in snapshot["rules"]}) != len(snapshot["rules"]): + raise ContractError("duplicate rule identifier") + for rule in snapshot["rules"]: + validate_rule(rule) + if rule["verified_at"] and rule["verified_at"] > snapshot["created_at"]: + raise ContractError("snapshot predates rule verification") + return snapshot + + +def validate_inventory(inventory): + validate_schema(inventory, INVENTORY_SCHEMA) + for record in inventory["records"]: + _evidence_map(record["evidence"]) + return inventory + + +def _json_bytes(value): + return (json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":"), allow_nan=False) + "\n").encode("utf-8") + + +def snapshot_digest(snapshot): + """Integrity identifier for canonical snapshot bytes; not a signature.""" + validate_snapshot(snapshot) + return hashlib.sha256(_json_bytes(snapshot)).hexdigest() + + +def canonical_json(report): + validate_report(report) + return _json_bytes(report).decode("utf-8") + + +def _unique_object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ContractError("duplicate JSON object key") + result[key] = value + return result + + +def _read_regular_file(path, max_bytes): + """Read one bounded regular file without following symlinks or blocking on FIFOs.""" + if type(max_bytes) is not int or not 0 < max_bytes <= 64 * 1024 * 1024: + raise ContractError("invalid byte bound") + fd = None + try: + before = Path(path).lstat() + if not stat.S_ISREG(before.st_mode): + raise ContractError("input must be a regular file, not a link or special file") + flags = os.O_RDONLY | getattr(os, "O_NONBLOCK", 0) | getattr(os, "O_NOFOLLOW", 0) | getattr(os, "O_BINARY", 0) + fd = os.open(path, flags) + opened = os.fstat(fd) + if not stat.S_ISREG(opened.st_mode) or (before.st_dev, before.st_ino) != (opened.st_dev, opened.st_ino): + raise ContractError("input identity changed while opening") + if opened.st_size > max_bytes: + raise ContractError("input byte limit exceeded") + with os.fdopen(fd, "rb") as stream: + fd = None + raw = stream.read(max_bytes + 1) + except OSError: + raise ContractError("input could not be read") from None + finally: + if fd is not None: + os.close(fd) + if len(raw) > max_bytes: + raise ContractError("input byte limit exceeded") + return raw + + +def load_json(path, max_bytes=MAX_JSON_BYTES): + """Read bounded JSON; error messages deliberately omit paths and raw input.""" + raw = _read_regular_file(path, max_bytes) + try: + value = json.loads(raw.decode("utf-8-sig"), object_pairs_hook=_unique_object, + parse_constant=lambda _: (_ for _ in ()).throw(ContractError("non-finite JSON number"))) + except (UnicodeError, json.JSONDecodeError, RecursionError, ValueError) as exc: + if isinstance(exc, ContractError): + raise + raise ContractError("invalid JSON encoding, syntax or nesting") from None + pending = [(value, 0)] + nodes = 0 + while pending: + item, depth = pending.pop() + nodes += 1 + if nodes > 200000 or depth > 40: + raise ContractError("JSON structure limit exceeded") + if isinstance(item, float) and not math.isfinite(item): + raise ContractError("non-finite JSON number") + if isinstance(item, dict): + pending.extend((v, depth + 1) for v in item.values()) + elif isinstance(item, list): + pending.extend((v, depth + 1) for v in item) + return value + + +def _csv_safe(value): + value = str(value) + return "'" + value if value.lstrip().startswith(("=", "+", "-", "@")) else value + + +def render_csv(report): + validate_report(report) + output = io.StringIO(newline="") + fields = ("record_type", "asset_id", "component", "version", "rule_id", "status", "version_assessment", "confidence", + "exploitability", "complete", "rules_as_of", "evidence", "preconditions", "mitigation", + "reachability", "threat", "reasons", "recommendation", "sources", "limitations") + writer = csv.DictWriter(output, fieldnames=fields, lineterminator="\n") + writer.writeheader() + for result in report["results"]: + row = {key: result[key] for key in fields if key in result} + row.update(record_type="result", component=result["component"]["name"], version=result["component"]["version"] or "", + complete=report["complete"], rules_as_of=report["rules"]["verified_at"], limitations=report["limitations"]) + writer.writerow({key: _csv_safe(json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":")) + if isinstance(value, (dict, list)) else value) for key, value in row.items()}) + if not report["results"]: + writer.writerow({"record_type": "summary", "complete": report["complete"], + "rules_as_of": report["rules"]["verified_at"], "exploitability": "not_tested", + "limitations": json.dumps(report["limitations"], ensure_ascii=False, sort_keys=True, separators=(",", ":"))}) + return output.getvalue() + + +def _logo_uri(path): + if path is None: + return "" + data = _read_regular_file(path, 1024 * 1024) + if data.startswith(b"\x89PNG\r\n\x1a\n"): + mime = "image/png" + elif data.startswith(b"\xff\xd8\xff"): + mime = "image/jpeg" + elif data.startswith((b"GIF87a", b"GIF89a")): + mime = "image/gif" + elif data.startswith(b"RIFF") and data[8:12] == b"WEBP": + mime = "image/webp" + else: + raise ContractError("logo must be a bounded PNG, JPEG, GIF or WebP raster file") + return "data:" + mime + ";base64," + base64.b64encode(data).decode("ascii") + + +def render_html(report, brand="CompleteTech LLC", logo=None): + validate_report(report) + esc = lambda value: html.escape(str(value), quote=True) + logo_data = _logo_uri(logo) + logo_html = '' if logo_data else "" + rows = [] + for result in report["results"]: + evidence = "".join("
  • " + esc(item["kind"] + ": " + item["state"] + " — " + item["detail"]) + + (" " + esc(item["path"]) + (":" + str(item["line"]) if "line" in item else "") + "" if "path" in item else "") + + "
  • " for item in result["evidence"]) + reasons = "".join("
  • " + esc(reason) + "
  • " for reason in result["reasons"]) + sources = " ".join('Source' for url in result["sources"]) + dimensions = {key: result[key] for key in ("version_assessment", "confidence", "preconditions", "mitigation", "reachability", "threat")} + rows.append("

    " + esc(result["asset_id"]) + " · " + esc(result["component"]["name"]) + + "

    " + esc(result["status"]) + "

    Reported version: " + + esc(result["component"]["version"] or "unknown") + " · Rule: " + esc(result["rule_id"]) + + " · Exploitability: not_tested

    " + esc(result["recommendation"]) + + "

    Evidence and assessment dimensions
      " + + evidence + "
    " + esc(json.dumps(dimensions, ensure_ascii=False, indent=2, sort_keys=True))
    +                    + "

    " + sources + "

    ") + limitations = "".join("
  • " + esc(item) + "
  • " for item in report["limitations"]) + counts = " · ".join(esc(status) + ": " + str(sum(r["status"] == status for r in report["results"])) + for status in STATUSES if any(r["status"] == status for r in report["results"])) + return """ + +Security evidence report
    """ + logo_html + "
    " + esc(brand) + "

    Security evidence report

    " + esc(report["tool"]["name"]) \ + + " " + esc(report["tool"]["version"]) + " · rules verified " + esc(report["rules"]["verified_at"]) \ + + "

    " + ("Completed assessment" if report["complete"] else "Incomplete assessment") \ + + "

    Local exploitability is not tested. Version, configuration, candidate source patterns and external exploitation reports are separate evidence.

    " \ + + counts + "

      " + limitations + "
    " + "".join(rows) \ + + "
    Schema " + CONTRACT_VERSION + " · Snapshot " + esc(report["rules"]["snapshot_id"]) \ + + " · SHA-256 " + esc(report["rules"]["sha256"] or "not supplied") + "
    \n" + + +def save_report(path, text, force=False, protected_paths=(), state=None): + """Atomic publication with protected inputs and interrupt ownership tracking.""" + state = {} if state is None else state + target = Path(path) + if target.is_symlink(): + raise ContractError("output symlink is not permitted") + for item in protected_paths: + source = Path(item) + if target.resolve() == source.resolve(): + raise ContractError("output must differ from every protected input") + if target.exists() and source.exists() and os.path.samefile(target, source): + raise ContractError("output aliases a protected input") + if not target.parent.is_dir(): + raise ContractError("output directory must exist") + temporary = None + try: + with tempfile.NamedTemporaryFile("w", encoding="utf-8", newline="", dir=target.parent, + prefix=".checker-report-", delete=False) as stream: + temporary = Path(stream.name) + stream.write(text) + stream.flush() + os.fsync(stream.fileno()) + staged_identity = os.fstat(stream.fileno()) + try: + if state is not None: + state["publication_started"] = True + if force: + os.replace(temporary, target) + else: + os.link(temporary, target) + state["published"] = True + except KeyboardInterrupt: + # A second interrupt or metadata failure must not permit a retry. + try: + owned = os.path.samestat(staged_identity, os.stat(target, follow_symlinks=False)) + if state is not None: + if owned: + state["published"] = True + else: + state["publication_started"] = False + except FileNotFoundError: + if state is not None: + state["publication_started"] = False + except OSError: + pass # Publication outcome remains indeterminate. + raise + finally: + if temporary is not None: + temporary.unlink(missing_ok=True) + +# Report bridge implementation; bundled contracts above retain their notices. +import argparse +import sys +from urllib.parse import quote + +BRIDGE_VERSION = '0.1.0' +SCHEMA_URI = 'https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json' +FINDINGS = {'potentially_affected', 'precondition_present', 'likely_exposed'} +UNKNOWNS = {'unknown', 'unsupported_runtime', 'source_discrepancy'} +PROFILES = { + 'node2shell-v1': ('node2shell-check', 'node2shell_', 'CVE-2026-111497'), + 'copyescape-v1.1': ('copyescape-check', 'copyescape_', 'CVE-2026-17106'), + 'vm2-v1.1': ('vm2-nesting-check', '', 'CVE-2026-92935'), + 'simplegit-v1.1': ('simplegit-rce-check', '', 'CVE-2026-102826'), + 'atlassian-v1': ('atlassian-cve-2026-21589-check', '', 'CVE-2026-21589'), + 'flowise-v1': ('flowise-cve-2026-69254-check', '', 'CVE-2026-69254'), +} + + +def digest(value): + return hashlib.sha256(json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(',', ':')).encode('utf-8')).hexdigest() + + +def bounded_structure(value): + stack, count = [(value, 0)], 0 + while stack: + item, depth = stack.pop() + count += 1 + if count > 250000 or depth > 40: + raise ContractError('Report structure exceeds limits') + if isinstance(item, dict): + stack.extend((v, depth+1) for v in item.values()) + elif isinstance(item, list): + stack.extend((v, depth+1) for v in item) + elif isinstance(item, str) and len(item) > 16384: + raise ContractError('Report string exceeds limits') + + +def safe_evidence(value): + """Privacy projection: preserve states/numbers; hash arbitrary text and identifiers.""" + if isinstance(value, dict): + result = {} + for key, item in value.items(): + # Do not publish arbitrary input key strings (which can themselves contain secrets). + if key in {'state','kind','confidence','build_source','name','version','id','detail','path','line','source','as_of','recommendation','preconditions','mitigation','reachability','threat','evidence','reasons'}: + if key in {'state','kind','confidence','build_source'} and isinstance(item, str) and item in {'unknown','present','absent','candidate','conflicting','observed','metadata_observed','not_reported','reported','not_tested','not_observed','low','medium','high','insufficient','version','configuration','reachability','mitigation','inventory','source','passive','operator','not_listed','listed','upstream','vendor','custom'}: + result[key] = item + else: + result[key] = safe_evidence(item) + else: + result["field_sha256_"+digest(key)] = safe_evidence(item) + return result + if isinstance(value, list): + return [safe_evidence(item) for item in value] + if isinstance(value, str): + return {'redacted_sha256': digest(value)} if value else '' + return value + + +def source_location(path, line): + if not isinstance(path, str) or not path or len(path) > 512 or any(ord(c) < 32 for c in path): + return None + if '\\' in path or ':' in path or path.startswith('/') or any(part in {'','.','..'} for part in path.split('/')): + return None + if type(line) is not int or not 1 <= line <= 10000000: + return None + return {'path': path, 'line': line} + + +def normalize(report, profile, include_paths=False): + bounded_structure(report) + if not isinstance(report, dict) or type(report.get('complete')) is not bool: + raise ContractError('Expected versioned completed-state report object') + rows = report.get('results') + if not isinstance(rows, list) or len(rows) > 10000: + raise ContractError('Expected at most 10,000 results') + canonical = profile == 'contract-v1.0' + if canonical: + validate_report(report) + tool, version = report['tool']['name'], report['tool']['version'] + prefix, fixed_rule = '', None + else: + tool, prefix, fixed_rule = PROFILES[profile] + if report.get('tool') != tool: + raise ContractError('Report tool does not match explicit profile') + expected = '1.1' if profile.endswith('v1.1') else 1 + if profile == 'node2shell-v1': + if report.get('tool_version') != '1.0.0' or 'schema_version' in report: + raise ContractError('Unsupported legacy Node2Shell report version') + elif profile.endswith('v1.1'): + if report.get('schema_version' if profile == 'copyescape-v1.1' else 'report_schema_version') != expected: + raise ContractError('Unsupported report schema version') + elif type(report.get('schema_version')) is not int or report['schema_version'] != expected: + raise ContractError('Unsupported report schema version') + version = report.get('tool_version', '') + if not isinstance(version, str) or not re.fullmatch(r'[0-9]+\.[0-9]+\.[0-9]+', version): + raise ContractError('Invalid tool version') + normalized = [] + for index, row in enumerate(rows): + if not isinstance(row, dict): + raise ContractError('Result must be an object') + status = row.get('version_status' if profile == 'flowise-v1' else prefix+'status') + if not isinstance(status,str) or status not in set(STATUSES) | UNKNOWNS: + raise ContractError('Unsupported result status') + if row.get(prefix+'exploitability') != 'not_tested': + raise ContractError('Exploitability must remain not_tested') + rule = row['rule_id'] if canonical else fixed_rule + if not isinstance(rule, str) or not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9_.-]{0,127}', rule): + raise ContractError('Unsupported rule identifier') + asset = row.get('asset_id', row.get('input_url', row.get('input_label', row.get('label', row.get('input_id',''))))) + if not isinstance(asset, str): + raise ContractError('Invalid asset identifier') + location = None + if canonical: + locations = [source_location(e.get('path'), e.get('line')) for e in row['evidence'] if e.get('kind') == 'source'] + locations = [value for value in locations if value] + if len(locations) == 1: location = locations[0] + elif row.get('evidence_type', row.get('copyescape_evidence_type')) in ('lexical_source_candidate','lexical_workflow_candidate'): + location = source_location(row.get('source_path'), row.get('source_line')) + identity = {'tool':tool,'rule':rule,'asset':asset,'location':location, 'instance': [row.get(key) for key in ('package','product','install_path','component')]} + fingerprint = digest(identity) + evidence = {key: row[key] for key in ('evidence','preconditions','mitigation','reachability','threat','reasons','recommendation') if key in row} + if not canonical: + evidence = {'evidence': {key:value for key,value in row.items() if key not in {'checked_at','generated_at'}}} + confidence = row.get('confidence', row.get(prefix+'evidence_confidence','unknown')) + if not isinstance(confidence,str) or confidence not in {'low','medium','high','unknown','insufficient'}: confidence='unknown' + normalized.append(dict(schema_version='1.0', tool=tool, tool_version=version, rule_id=rule, status=status, + exploitability='not_tested', confidence=confidence, complete=report['complete'], + asset_sha256=digest(asset), fingerprint=fingerprint, + location=location if include_paths else None, location_redacted=bool(location and not include_paths), + evidence=safe_evidence(evidence), evidence_sha256=digest(evidence), + recommendation='Review the original local report and vendor guidance; metadata does not establish exploitability or safety.')) + # Deduplicate exact normalized observations only; conflicting statuses/evidence survive. + return sorted({digest(row):row for row in normalized}.values(), key=lambda row:(row['tool'],row['rule_id'],row['fingerprint'],digest(row))) + + +def to_sarif(rows, complete): + runs = [] + groups = {} + for row in rows: + groups.setdefault((row['tool'],row['tool_version']),[]).append(row) + if not groups: groups[('scan-results-bridge',BRIDGE_VERSION)]=[] + for (name,version), records in sorted(groups.items()): + ids = sorted({r['rule_id'] for r in records}) + rules = [{'id': rule,'shortDescription':{'text':rule+' metadata assessment'},'help':{'text':'Review original local evidence and vendor guidance. Exploitability remains not_tested.'}} for rule in ids] + results = [] + for row in records: + result = {'ruleId':row['rule_id'],'ruleIndex':ids.index(row['rule_id']), + 'level':'warning' if row['status'] in FINDINGS else 'note', + 'message':{'text':row['status']+'; exploitability: not_tested. '+row['recommendation']}, + 'partialFingerprints':{'checkerIdentity/v1':row['fingerprint']}, + 'properties':{k:v for k,v in row.items() if k!='location'}} + if row['location']: + result['locations']=[{'physicalLocation':{'artifactLocation':{'uri':quote(row['location']['path'],safe='/')},'region':{'startLine':row['location']['line']}}}] + results.append(result) + runs.append({'tool':{'driver':{'name':name,'version':version,'rules':rules}},'invocations':[{'executionSuccessful':complete}], 'results':results}) + return {'version':'2.1.0','$schema':SCHEMA_URI,'runs':runs} + + +def main(argv=None): + parser=argparse.ArgumentParser(description='Offline bounded checker JSON to SARIF 2.1.0 or NDJSON; no uploads',allow_abbrev=False) + parser.add_argument('--input',action='append',required=True,type=Path,help='Existing report JSON; repeatable, at most 20') + parser.add_argument('--input-schema',choices=['contract-v1.0',*PROFILES],default='contract-v1.0',help='Explicit adapter, identical for all inputs') + parser.add_argument('--format',choices=['sarif','ndjson'],default='sarif') + parser.add_argument('--include-relative-paths',action='store_true',help='Opt in to publishing valid reported source paths; never inferred inventory locations') + parser.add_argument('--fail-on',choices=['none','findings','unknown','either'],default='none',help='Policy exit 1 after successful output; operational errors exit 2') + parser.add_argument('--output',type=Path,help='New report file; default stdout') + parser.add_argument('--force',action='store_true',help='Replace output atomically; never inputs or checker') + args=parser.parse_args(argv) + try: + if len(args.input)>20: raise ContractError('At most 20 reports') + # Identity comparison protects symlink/hardlink aliases even with --force. + protected=[Path(__file__),*args.input] + if args.output: + destination=args.output.resolve() + for path in protected: + if destination==path.resolve() or (args.output.exists() and os.path.samefile(args.output,path)): + raise ContractError('Output aliases protected input') + if args.output.exists() and not args.force: raise ContractError('Output exists') + rows,complete,total=[],True,0 + for path in args.input: + raw=_read_regular_file(path,4*1024**2) + total+=len(raw) + if total>16*1024**2: raise ContractError('Combined input byte limit') + value=json.loads(raw.decode('utf-8-sig'),object_pairs_hook=_unique_object,parse_constant=lambda _: (_ for _ in ()).throw(ContractError('Non-finite JSON'))) + rows.extend(normalize(value,args.input_schema,args.include_relative_paths)) + complete=complete and value['complete'] + if len(rows)>10000: raise ContractError('Combined result limit') + rows=sorted({digest(row):row for row in rows}.values(),key=lambda row:(row['tool'],row['rule_id'],row['fingerprint'],digest(row))) + if args.format=='sarif': + rendered=json.dumps(to_sarif(rows,complete),ensure_ascii=False,sort_keys=True,indent=2)+'\n' + else: + rendered=''.join(json.dumps(row,ensure_ascii=False,sort_keys=True)+'\n' for row in rows) + # Always include an explicit summary, including empty/incomplete conversions. + rendered+=json.dumps(dict(record_type='summary',schema_version='1.0',complete=complete,result_count=len(rows)),sort_keys=True)+'\n' + if len(rendered.encode('utf-8'))>32*1024**2: raise ContractError('Output byte limit') + if args.output: + fd,name=tempfile.mkstemp(prefix='.bridge-',dir=args.output.parent) + try: + with os.fdopen(fd,'w',encoding='utf-8',newline='\n') as stream: + stream.write(rendered);stream.flush();os.fsync(stream.fileno()) + if args.force: os.replace(name,args.output) + else: os.link(name,args.output) + finally: Path(name).unlink(missing_ok=True) + else: + sys.stdout.write(rendered);sys.stdout.flush() + if not complete: return 2 + findings=any(r['status'] in FINDINGS for r in rows) + unknown=any(r['status'] in UNKNOWNS for r in rows) + return int((args.fail_on in {'findings','either'} and findings) or (args.fail_on in {'unknown','either'} and unknown)) + except KeyboardInterrupt: + sys.stderr.write('Interrupted; publication may be incomplete; no output retry.\n');return 130 + except (OSError,ValueError,UnicodeError,RecursionError): + sys.stderr.write('Conversion failed: invalid/unsupported input or protected/unwritable output.\n');return 2 + + +if __name__=='__main__': raise SystemExit(main()) diff --git a/schemas/OASIS-LICENSE.md b/schemas/OASIS-LICENSE.md new file mode 100644 index 0000000..4f6c098 --- /dev/null +++ b/schemas/OASIS-LICENSE.md @@ -0,0 +1,7 @@ +
    +

    License Terms

    + +

    Content in this GitHub code repository has been contributed by OASIS TC Members, and is governed by the OASIS policies, including the Intellectual Property Rights (IPR) Policy, the Technical Committee (TC) Process, Bylaws, and the Technical Committee's choice of IPR Mode (viz, RF on RAND Terms Mode), including any applicable declarations. Feedback from non-TC members, if any, is governed by the terms of the OASIS Feedback License.

    + +

    Description of this repository is presented in the README file, and guidelines for contribution/participation are given in the CONTRIBUTING file.

    +
    diff --git a/schemas/sarif-schema-2.1.0.json b/schemas/sarif-schema-2.1.0.json new file mode 100644 index 0000000..0f58372 --- /dev/null +++ b/schemas/sarif-schema-2.1.0.json @@ -0,0 +1,3389 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Static Analysis Results Format (SARIF) Version 2.1.0 JSON Schema", + "id": "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json", + "description": "Static Analysis Results Format (SARIF) Version 2.1.0 JSON Schema: a standard format for the output of static analysis tools.", + "additionalProperties": false, + "type": "object", + "properties": { + + "$schema": { + "description": "The URI of the JSON schema corresponding to the version.", + "type": "string", + "format": "uri" + }, + + "version": { + "description": "The SARIF format version of this log file.", + "enum": [ "2.1.0" ], + "type": "string" + }, + + "runs": { + "description": "The set of runs contained in this log file.", + "type": [ "array", "null" ], + "minItems": 0, + "uniqueItems": false, + "items": { + "$ref": "#/definitions/run" + } + }, + + "inlineExternalProperties": { + "description": "References to external property files that share data between runs.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "items": { + "$ref": "#/definitions/externalProperties" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the log file.", + "$ref": "#/definitions/propertyBag" + } + }, + + "required": [ "version", "runs" ], + + "definitions": { + + "address": { + "description": "A physical or virtual address, or a range of addresses, in an 'addressable region' (memory or a binary file).", + "additionalProperties": false, + "type": "object", + "properties": { + + "absoluteAddress": { + "description": "The address expressed as a byte offset from the start of the addressable region.", + "type": "integer", + "minimum": -1, + "default": -1 + + }, + + "relativeAddress": { + "description": "The address expressed as a byte offset from the absolute address of the top-most parent object.", + "type": "integer" + + }, + + "length": { + "description": "The number of bytes in this range of addresses.", + "type": "integer" + }, + + "kind": { + "description": "An open-ended string that identifies the address kind. 'data', 'function', 'header','instruction', 'module', 'page', 'section', 'segment', 'stack', 'stackFrame', 'table' are well-known values.", + "type": "string" + }, + + "name": { + "description": "A name that is associated with the address, e.g., '.text'.", + "type": "string" + }, + + "fullyQualifiedName": { + "description": "A human-readable fully qualified name that is associated with the address.", + "type": "string" + }, + + "offsetFromParent": { + "description": "The byte offset of this address from the absolute or relative address of the parent object.", + "type": "integer" + }, + + "index": { + "description": "The index within run.addresses of the cached object for this address.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "parentIndex": { + "description": "The index within run.addresses of the parent object.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the address.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "artifact": { + "description": "A single artifact. In some cases, this artifact might be nested within another artifact.", + "additionalProperties": false, + "type": "object", + "properties": { + + "description": { + "description": "A short description of the artifact.", + "$ref": "#/definitions/message" + }, + + "location": { + "description": "The location of the artifact.", + "$ref": "#/definitions/artifactLocation" + }, + + "parentIndex": { + "description": "Identifies the index of the immediate parent of the artifact, if this artifact is nested.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "offset": { + "description": "The offset in bytes of the artifact within its containing artifact.", + "type": "integer", + "minimum": 0 + }, + + "length": { + "description": "The length of the artifact in bytes.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "roles": { + "description": "The role or roles played by the artifact in the analysis.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "enum": [ + "analysisTarget", + "attachment", + "responseFile", + "resultFile", + "standardStream", + "tracedFile", + "unmodified", + "modified", + "added", + "deleted", + "renamed", + "uncontrolled", + "driver", + "extension", + "translation", + "taxonomy", + "policy", + "referencedOnCommandLine", + "memoryContents", + "directory", + "userSpecifiedConfiguration", + "toolSpecifiedConfiguration", + "debugOutputFile" + ], + "type": "string" + } + }, + + "mimeType": { + "description": "The MIME type (RFC 2045) of the artifact.", + "type": "string", + "pattern": "[^/]+/.+" + }, + + "contents": { + "description": "The contents of the artifact.", + "$ref": "#/definitions/artifactContent" + }, + + "encoding": { + "description": "Specifies the encoding for an artifact object that refers to a text file.", + "type": "string" + }, + + "sourceLanguage": { + "description": "Specifies the source language for any artifact object that refers to a text file that contains source code.", + "type": "string" + }, + + "hashes": { + "description": "A dictionary, each of whose keys is the name of a hash function and each of whose values is the hashed value of the artifact produced by the specified hash function.", + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + + "lastModifiedTimeUtc": { + "description": "The Coordinated Universal Time (UTC) date and time at which the artifact was most recently modified. See \"Date/time properties\" in the SARIF spec for the required format.", + "type": "string", + "format": "date-time" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the artifact.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "artifactChange": { + "description": "A change to a single artifact.", + "additionalProperties": false, + "type": "object", + "properties": { + + "artifactLocation": { + "description": "The location of the artifact to change.", + "$ref": "#/definitions/artifactLocation" + }, + + "replacements": { + "description": "An array of replacement objects, each of which represents the replacement of a single region in a single artifact specified by 'artifactLocation'.", + "type": "array", + "minItems": 1, + "uniqueItems": false, + "items": { + "$ref": "#/definitions/replacement" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the change.", + "$ref": "#/definitions/propertyBag" + } + + }, + + "required": [ "artifactLocation", "replacements" ] + }, + + "artifactContent": { + "description": "Represents the contents of an artifact.", + "type": "object", + "additionalProperties": false, + "properties": { + + "text": { + "description": "UTF-8-encoded content from a text artifact.", + "type": "string" + }, + + "binary": { + "description": "MIME Base64-encoded content from a binary artifact, or from a text artifact in its original encoding.", + "type": "string" + }, + + "rendered": { + "description": "An alternate rendered representation of the artifact (e.g., a decompiled representation of a binary region).", + "$ref": "#/definitions/multiformatMessageString" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the artifact content.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "artifactLocation": { + "description": "Specifies the location of an artifact.", + "additionalProperties": false, + "type": "object", + "properties": { + + "uri": { + "description": "A string containing a valid relative or absolute URI.", + "type": "string", + "format": "uri-reference" + }, + + "uriBaseId": { + "description": "A string which indirectly specifies the absolute URI with respect to which a relative URI in the \"uri\" property is interpreted.", + "type": "string" + }, + + "index": { + "description": "The index within the run artifacts array of the artifact object associated with the artifact location.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "description": { + "description": "A short description of the artifact location.", + "$ref": "#/definitions/message" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the artifact location.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "attachment": { + "description": "An artifact relevant to a result.", + "type": "object", + "additionalProperties": false, + "properties": { + + "description": { + "description": "A message describing the role played by the attachment.", + "$ref": "#/definitions/message" + }, + + "artifactLocation": { + "description": "The location of the attachment.", + "$ref": "#/definitions/artifactLocation" + }, + + "regions": { + "description": "An array of regions of interest within the attachment.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/region" + } + }, + + "rectangles": { + "description": "An array of rectangles specifying areas of interest within the image.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/rectangle" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the attachment.", + "$ref": "#/definitions/propertyBag" + } + }, + + "required": [ "artifactLocation" ] + }, + + "codeFlow": { + "description": "A set of threadFlows which together describe a pattern of code execution relevant to detecting a result.", + "additionalProperties": false, + "type": "object", + "properties": { + + "message": { + "description": "A message relevant to the code flow.", + "$ref": "#/definitions/message" + }, + + "threadFlows": { + "description": "An array of one or more unique threadFlow objects, each of which describes the progress of a program through a thread of execution.", + "type": "array", + "minItems": 1, + "uniqueItems": false, + "items": { + "$ref": "#/definitions/threadFlow" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the code flow.", + "$ref": "#/definitions/propertyBag" + } + }, + + "required": [ "threadFlows" ] + }, + + "configurationOverride": { + "description": "Information about how a specific rule or notification was reconfigured at runtime.", + "type": "object", + "additionalProperties": false, + "properties": { + + "configuration": { + "description": "Specifies how the rule or notification was configured during the scan.", + "$ref": "#/definitions/reportingConfiguration" + }, + + "descriptor": { + "description": "A reference used to locate the descriptor whose configuration was overridden.", + "$ref": "#/definitions/reportingDescriptorReference" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the configuration override.", + "$ref": "#/definitions/propertyBag" + } + }, + "required": [ "configuration", "descriptor" ] + }, + + "conversion": { + "description": "Describes how a converter transformed the output of a static analysis tool from the analysis tool's native output format into the SARIF format.", + "additionalProperties": false, + "type": "object", + "properties": { + + "tool": { + "description": "A tool object that describes the converter.", + "$ref": "#/definitions/tool" + }, + + "invocation": { + "description": "An invocation object that describes the invocation of the converter.", + "$ref": "#/definitions/invocation" + }, + + "analysisToolLogFiles": { + "description": "The locations of the analysis tool's per-run log files.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/artifactLocation" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the conversion.", + "$ref": "#/definitions/propertyBag" + } + + }, + + "required": [ "tool" ] + }, + + "edge": { + "description": "Represents a directed edge in a graph.", + "type": "object", + "additionalProperties": false, + "properties": { + + "id": { + "description": "A string that uniquely identifies the edge within its graph.", + "type": "string" + }, + + "label": { + "description": "A short description of the edge.", + "$ref": "#/definitions/message" + }, + + "sourceNodeId": { + "description": "Identifies the source node (the node at which the edge starts).", + "type": "string" + }, + + "targetNodeId": { + "description": "Identifies the target node (the node at which the edge ends).", + "type": "string" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the edge.", + "$ref": "#/definitions/propertyBag" + } + }, + + "required": [ "id", "sourceNodeId", "targetNodeId" ] + }, + + "edgeTraversal": { + "description": "Represents the traversal of a single edge during a graph traversal.", + "type": "object", + "additionalProperties": false, + "properties": { + + "edgeId": { + "description": "Identifies the edge being traversed.", + "type": "string" + }, + + "message": { + "description": "A message to display to the user as the edge is traversed.", + "$ref": "#/definitions/message" + }, + + "finalState": { + "description": "The values of relevant expressions after the edge has been traversed.", + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/multiformatMessageString" + } + }, + + "stepOverEdgeCount": { + "description": "The number of edge traversals necessary to return from a nested graph.", + "type": "integer", + "minimum": 0 + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the edge traversal.", + "$ref": "#/definitions/propertyBag" + } + }, + + "required": [ "edgeId" ] + }, + + "exception": { + "description": "Describes a runtime exception encountered during the execution of an analysis tool.", + "type": "object", + "additionalProperties": false, + "properties": { + + "kind": { + "type": "string", + "description": "A string that identifies the kind of exception, for example, the fully qualified type name of an object that was thrown, or the symbolic name of a signal." + }, + + "message": { + "description": "A message that describes the exception.", + "type": "string" + }, + + "stack": { + "description": "The sequence of function calls leading to the exception.", + "$ref": "#/definitions/stack" + }, + + "innerExceptions": { + "description": "An array of exception objects each of which is considered a cause of this exception.", + "type": "array", + "minItems": 0, + "uniqueItems": false, + "default": [], + "items": { + "$ref": "#/definitions/exception" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the exception.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "externalProperties": { + "description": "The top-level element of an external property file.", + "type": "object", + "additionalProperties": false, + "properties": { + + "schema": { + "description": "The URI of the JSON schema corresponding to the version of the external property file format.", + "type": "string", + "format": "uri" + }, + + "version": { + "description": "The SARIF format version of this external properties object.", + "enum": [ "2.1.0" ], + "type": "string" + }, + + "guid": { + "description": "A stable, unique identifier for this external properties object, in the form of a GUID.", + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" + }, + + "runGuid": { + "description": "A stable, unique identifier for the run associated with this external properties object, in the form of a GUID.", + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" + }, + + "conversion": { + "description": "A conversion object that will be merged with a separate run.", + "$ref": "#/definitions/conversion" + }, + + "graphs": { + "description": "An array of graph objects that will be merged with a separate run.", + "type": "array", + "minItems": 0, + "default": [], + "uniqueItems": true, + "items": { + "$ref": "#/definitions/graph" + } + }, + + "externalizedProperties": { + "description": "Key/value pairs that provide additional information that will be merged with a separate run.", + "$ref": "#/definitions/propertyBag" + }, + + "artifacts": { + "description": "An array of artifact objects that will be merged with a separate run.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "items": { + "$ref": "#/definitions/artifact" + } + }, + + "invocations": { + "description": "Describes the invocation of the analysis tool that will be merged with a separate run.", + "type": "array", + "minItems": 0, + "uniqueItems": false, + "default": [], + "items": { + "$ref": "#/definitions/invocation" + } + }, + + "logicalLocations": { + "description": "An array of logical locations such as namespaces, types or functions that will be merged with a separate run.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/logicalLocation" + } + }, + + "threadFlowLocations": { + "description": "An array of threadFlowLocation objects that will be merged with a separate run.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/threadFlowLocation" + } + }, + + "results": { + "description": "An array of result objects that will be merged with a separate run.", + "type": "array", + "minItems": 0, + "uniqueItems": false, + "default": [], + "items": { + "$ref": "#/definitions/result" + } + }, + + "taxonomies": { + "description": "Tool taxonomies that will be merged with a separate run.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/toolComponent" + } + }, + + "driver": { + "description": "The analysis tool object that will be merged with a separate run.", + "$ref": "#/definitions/toolComponent" + }, + + "extensions": { + "description": "Tool extensions that will be merged with a separate run.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/toolComponent" + } + }, + + "policies": { + "description": "Tool policies that will be merged with a separate run.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/toolComponent" + } + }, + + "translations": { + "description": "Tool translations that will be merged with a separate run.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/toolComponent" + } + }, + + "addresses": { + "description": "Addresses that will be merged with a separate run.", + "type": "array", + "minItems": 0, + "uniqueItems": false, + "default": [], + "items": { + "$ref": "#/definitions/address" + } + }, + + "webRequests": { + "description": "Requests that will be merged with a separate run.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/webRequest" + } + }, + + "webResponses": { + "description": "Responses that will be merged with a separate run.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/webResponse" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the external properties.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "externalPropertyFileReference": { + "description": "Contains information that enables a SARIF consumer to locate the external property file that contains the value of an externalized property associated with the run.", + "type": "object", + "additionalProperties": false, + "properties": { + + "location": { + "description": "The location of the external property file.", + "$ref": "#/definitions/artifactLocation" + }, + + "guid": { + "description": "A stable, unique identifier for the external property file in the form of a GUID.", + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" + }, + + "itemCount": { + "description": "A non-negative integer specifying the number of items contained in the external property file.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the external property file.", + "$ref": "#/definitions/propertyBag" + } + }, + "anyOf": [ + { "required": [ "location" ] }, + { "required": [ "guid" ] } + ] + }, + + "externalPropertyFileReferences": { + "description": "References to external property files that should be inlined with the content of a root log file.", + "additionalProperties": false, + "type": "object", + "properties": { + + "conversion": { + "description": "An external property file containing a run.conversion object to be merged with the root log file.", + "$ref": "#/definitions/externalPropertyFileReference" + }, + + "graphs": { + "description": "An array of external property files containing a run.graphs object to be merged with the root log file.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/externalPropertyFileReference" + } + }, + + "externalizedProperties": { + "description": "An external property file containing a run.properties object to be merged with the root log file.", + "$ref": "#/definitions/externalPropertyFileReference" + }, + + "artifacts": { + "description": "An array of external property files containing run.artifacts arrays to be merged with the root log file.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/externalPropertyFileReference" + } + }, + + "invocations": { + "description": "An array of external property files containing run.invocations arrays to be merged with the root log file.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/externalPropertyFileReference" + } + }, + + "logicalLocations": { + "description": "An array of external property files containing run.logicalLocations arrays to be merged with the root log file.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/externalPropertyFileReference" + } + }, + + "threadFlowLocations": { + "description": "An array of external property files containing run.threadFlowLocations arrays to be merged with the root log file.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/externalPropertyFileReference" + } + }, + + "results": { + "description": "An array of external property files containing run.results arrays to be merged with the root log file.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/externalPropertyFileReference" + } + }, + + "taxonomies": { + "description": "An array of external property files containing run.taxonomies arrays to be merged with the root log file.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/externalPropertyFileReference" + } + }, + + "addresses": { + "description": "An array of external property files containing run.addresses arrays to be merged with the root log file.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/externalPropertyFileReference" + } + }, + + "driver": { + "description": "An external property file containing a run.driver object to be merged with the root log file.", + "$ref": "#/definitions/externalPropertyFileReference" + }, + + "extensions": { + "description": "An array of external property files containing run.extensions arrays to be merged with the root log file.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/externalPropertyFileReference" + } + }, + + "policies": { + "description": "An array of external property files containing run.policies arrays to be merged with the root log file.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/externalPropertyFileReference" + } + }, + + "translations": { + "description": "An array of external property files containing run.translations arrays to be merged with the root log file.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/externalPropertyFileReference" + } + }, + + "webRequests": { + "description": "An array of external property files containing run.requests arrays to be merged with the root log file.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/externalPropertyFileReference" + } + }, + + "webResponses": { + "description": "An array of external property files containing run.responses arrays to be merged with the root log file.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/externalPropertyFileReference" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the external property files.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "fix": { + "description": "A proposed fix for the problem represented by a result object. A fix specifies a set of artifacts to modify. For each artifact, it specifies a set of bytes to remove, and provides a set of new bytes to replace them.", + "additionalProperties": false, + "type": "object", + "properties": { + + "description": { + "description": "A message that describes the proposed fix, enabling viewers to present the proposed change to an end user.", + "$ref": "#/definitions/message" + }, + + "artifactChanges": { + "description": "One or more artifact changes that comprise a fix for a result.", + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "$ref": "#/definitions/artifactChange" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the fix.", + "$ref": "#/definitions/propertyBag" + } + }, + "required": [ "artifactChanges" ] + }, + + "graph": { + "description": "A network of nodes and directed edges that describes some aspect of the structure of the code (for example, a call graph).", + "type": "object", + "additionalProperties": false, + "properties": { + + "description": { + "description": "A description of the graph.", + "$ref": "#/definitions/message" + }, + + "nodes": { + "description": "An array of node objects representing the nodes of the graph.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/node" + } + }, + + "edges": { + "description": "An array of edge objects representing the edges of the graph.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/edge" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the graph.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "graphTraversal": { + "description": "Represents a path through a graph.", + "type": "object", + "additionalProperties": false, + "properties": { + + "runGraphIndex": { + "description": "The index within the run.graphs to be associated with the result.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "resultGraphIndex": { + "description": "The index within the result.graphs to be associated with the result.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "description": { + "description": "A description of this graph traversal.", + "$ref": "#/definitions/message" + }, + + "initialState": { + "description": "Values of relevant expressions at the start of the graph traversal that may change during graph traversal.", + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/multiformatMessageString" + } + }, + + "immutableState": { + "description": "Values of relevant expressions at the start of the graph traversal that remain constant for the graph traversal.", + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/multiformatMessageString" + } + }, + + "edgeTraversals": { + "description": "The sequences of edges traversed by this graph traversal.", + "type": "array", + "minItems": 0, + "uniqueItems": false, + "default": [], + "items": { + "$ref": "#/definitions/edgeTraversal" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the graph traversal.", + "$ref": "#/definitions/propertyBag" + } + }, + "oneOf": [ + { "required": [ "runGraphIndex" ] }, + { "required": [ "resultGraphIndex" ] } + ] + }, + + "invocation": { + "description": "The runtime environment of the analysis tool run.", + "additionalProperties": false, + "type": "object", + "properties": { + + "commandLine": { + "description": "The command line used to invoke the tool.", + "type": "string" + }, + + "arguments": { + "description": "An array of strings, containing in order the command line arguments passed to the tool from the operating system.", + "type": "array", + "minItems": 0, + "uniqueItems": false, + "items": { + "type": "string" + } + }, + + "responseFiles": { + "description": "The locations of any response files specified on the tool's command line.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "items": { + "$ref": "#/definitions/artifactLocation" + } + }, + + "startTimeUtc": { + "description": "The Coordinated Universal Time (UTC) date and time at which the invocation started. See \"Date/time properties\" in the SARIF spec for the required format.", + "type": "string", + "format": "date-time" + }, + + "endTimeUtc": { + "description": "The Coordinated Universal Time (UTC) date and time at which the invocation ended. See \"Date/time properties\" in the SARIF spec for the required format.", + "type": "string", + "format": "date-time" + }, + + "exitCode": { + "description": "The process exit code.", + "type": "integer" + }, + + "ruleConfigurationOverrides": { + "description": "An array of configurationOverride objects that describe rules related runtime overrides.", + "type": "array", + "minItems": 0, + "default": [], + "uniqueItems": true, + "items": { + "$ref": "#/definitions/configurationOverride" + } + }, + + "notificationConfigurationOverrides": { + "description": "An array of configurationOverride objects that describe notifications related runtime overrides.", + "type": "array", + "minItems": 0, + "default": [], + "uniqueItems": true, + "items": { + "$ref": "#/definitions/configurationOverride" + } + }, + + "toolExecutionNotifications": { + "description": "A list of runtime conditions detected by the tool during the analysis.", + "type": "array", + "minItems": 0, + "uniqueItems": false, + "default": [], + "items": { + "$ref": "#/definitions/notification" + } + }, + + "toolConfigurationNotifications": { + "description": "A list of conditions detected by the tool that are relevant to the tool's configuration.", + "type": "array", + "minItems": 0, + "uniqueItems": false, + "default": [], + "items": { + "$ref": "#/definitions/notification" + } + }, + + "exitCodeDescription": { + "description": "The reason for the process exit.", + "type": "string" + }, + + "exitSignalName": { + "description": "The name of the signal that caused the process to exit.", + "type": "string" + }, + + "exitSignalNumber": { + "description": "The numeric value of the signal that caused the process to exit.", + "type": "integer" + }, + + "processStartFailureMessage": { + "description": "The reason given by the operating system that the process failed to start.", + "type": "string" + }, + + "executionSuccessful": { + "description": "Specifies whether the tool's execution completed successfully.", + "type": "boolean" + }, + + "machine": { + "description": "The machine on which the invocation occurred.", + "type": "string" + }, + + "account": { + "description": "The account under which the invocation occurred.", + "type": "string" + }, + + "processId": { + "description": "The id of the process in which the invocation occurred.", + "type": "integer" + }, + + "executableLocation": { + "description": "An absolute URI specifying the location of the executable that was invoked.", + "$ref": "#/definitions/artifactLocation" + }, + + "workingDirectory": { + "description": "The working directory for the invocation.", + "$ref": "#/definitions/artifactLocation" + }, + + "environmentVariables": { + "description": "The environment variables associated with the analysis tool process, expressed as key/value pairs.", + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + + "stdin": { + "description": "A file containing the standard input stream to the process that was invoked.", + "$ref": "#/definitions/artifactLocation" + }, + + "stdout": { + "description": "A file containing the standard output stream from the process that was invoked.", + "$ref": "#/definitions/artifactLocation" + }, + + "stderr": { + "description": "A file containing the standard error stream from the process that was invoked.", + "$ref": "#/definitions/artifactLocation" + }, + + "stdoutStderr": { + "description": "A file containing the interleaved standard output and standard error stream from the process that was invoked.", + "$ref": "#/definitions/artifactLocation" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the invocation.", + "$ref": "#/definitions/propertyBag" + } + }, + "required": [ "executionSuccessful" ] + }, + + "location": { + "description": "A location within a programming artifact.", + "additionalProperties": false, + "type": "object", + "properties": { + + "id": { + "description": "Value that distinguishes this location from all other locations within a single result object.", + "type": "integer", + "minimum": -1, + "default": -1 + }, + + "physicalLocation": { + "description": "Identifies the artifact and region.", + "$ref": "#/definitions/physicalLocation" + }, + + "logicalLocations": { + "description": "The logical locations associated with the result.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/logicalLocation" + } + }, + + "message": { + "description": "A message relevant to the location.", + "$ref": "#/definitions/message" + }, + + "annotations": { + "description": "A set of regions relevant to the location.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/region" + } + }, + + "relationships": { + "description": "An array of objects that describe relationships between this location and others.", + "type": "array", + "default": [], + "minItems": 0, + "uniqueItems": true, + "items": { + "$ref": "#/definitions/locationRelationship" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the location.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "locationRelationship": { + "description": "Information about the relation of one location to another.", + "type": "object", + "additionalProperties": false, + "properties": { + + "target": { + "description": "A reference to the related location.", + "type": "integer", + "minimum": 0 + }, + + "kinds": { + "description": "A set of distinct strings that categorize the relationship. Well-known kinds include 'includes', 'isIncludedBy' and 'relevant'.", + "type": "array", + "default": [ "relevant" ], + "uniqueItems": true, + "items": { + "type": "string" + } + }, + + "description": { + "description": "A description of the location relationship.", + "$ref": "#/definitions/message" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the location relationship.", + "$ref": "#/definitions/propertyBag" + } + }, + "required": [ "target" ] + }, + + "logicalLocation": { + "description": "A logical location of a construct that produced a result.", + "additionalProperties": false, + "type": "object", + "properties": { + + "name": { + "description": "Identifies the construct in which the result occurred. For example, this property might contain the name of a class or a method.", + "type": "string" + }, + + "index": { + "description": "The index within the logical locations array.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "fullyQualifiedName": { + "description": "The human-readable fully qualified name of the logical location.", + "type": "string" + }, + + "decoratedName": { + "description": "The machine-readable name for the logical location, such as a mangled function name provided by a C++ compiler that encodes calling convention, return type and other details along with the function name.", + "type": "string" + }, + + "parentIndex": { + "description": "Identifies the index of the immediate parent of the construct in which the result was detected. For example, this property might point to a logical location that represents the namespace that holds a type.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "kind": { + "description": "The type of construct this logical location component refers to. Should be one of 'function', 'member', 'module', 'namespace', 'parameter', 'resource', 'returnType', 'type', 'variable', 'object', 'array', 'property', 'value', 'element', 'text', 'attribute', 'comment', 'declaration', 'dtd' or 'processingInstruction', if any of those accurately describe the construct.", + "type": "string" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the logical location.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "message": { + "description": "Encapsulates a message intended to be read by the end user.", + "type": "object", + "additionalProperties": false, + + "properties": { + + "text": { + "description": "A plain text message string.", + "type": "string" + }, + + "markdown": { + "description": "A Markdown message string.", + "type": "string" + }, + + "id": { + "description": "The identifier for this message.", + "type": "string" + }, + + "arguments": { + "description": "An array of strings to substitute into the message string.", + "type": "array", + "minItems": 0, + "uniqueItems": false, + "default": [], + "items": { + "type": "string" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the message.", + "$ref": "#/definitions/propertyBag" + } + }, + "anyOf": [ + { "required": [ "text" ] }, + { "required": [ "id" ] } + ] + }, + + "multiformatMessageString": { + "description": "A message string or message format string rendered in multiple formats.", + "type": "object", + "additionalProperties": false, + + "properties": { + + "text": { + "description": "A plain text message string or format string.", + "type": "string" + }, + + "markdown": { + "description": "A Markdown message string or format string.", + "type": "string" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the message.", + "$ref": "#/definitions/propertyBag" + } + }, + "required": [ "text" ] + }, + + "node": { + "description": "Represents a node in a graph.", + "type": "object", + "additionalProperties": false, + + "properties": { + + "id": { + "description": "A string that uniquely identifies the node within its graph.", + "type": "string" + }, + + "label": { + "description": "A short description of the node.", + "$ref": "#/definitions/message" + }, + + "location": { + "description": "A code location associated with the node.", + "$ref": "#/definitions/location" + }, + + "children": { + "description": "Array of child nodes.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/node" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the node.", + "$ref": "#/definitions/propertyBag" + } + }, + + "required": [ "id" ] + }, + + "notification": { + "description": "Describes a condition relevant to the tool itself, as opposed to being relevant to a target being analyzed by the tool.", + "type": "object", + "additionalProperties": false, + "properties": { + + "locations": { + "description": "The locations relevant to this notification.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/location" + } + }, + + "message": { + "description": "A message that describes the condition that was encountered.", + "$ref": "#/definitions/message" + }, + + "level": { + "description": "A value specifying the severity level of the notification.", + "default": "warning", + "enum": [ "none", "note", "warning", "error" ], + "type": "string" + }, + + "threadId": { + "description": "The thread identifier of the code that generated the notification.", + "type": "integer" + }, + + "timeUtc": { + "description": "The Coordinated Universal Time (UTC) date and time at which the analysis tool generated the notification.", + "type": "string", + "format": "date-time" + }, + + "exception": { + "description": "The runtime exception, if any, relevant to this notification.", + "$ref": "#/definitions/exception" + }, + + "descriptor": { + "description": "A reference used to locate the descriptor relevant to this notification.", + "$ref": "#/definitions/reportingDescriptorReference" + }, + + "associatedRule": { + "description": "A reference used to locate the rule descriptor associated with this notification.", + "$ref": "#/definitions/reportingDescriptorReference" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the notification.", + "$ref": "#/definitions/propertyBag" + } + }, + + "required": [ "message" ] + }, + + "physicalLocation": { + "description": "A physical location relevant to a result. Specifies a reference to a programming artifact together with a range of bytes or characters within that artifact.", + "additionalProperties": false, + "type": "object", + "properties": { + + "address": { + "description": "The address of the location.", + "$ref": "#/definitions/address" + }, + + "artifactLocation": { + "description": "The location of the artifact.", + "$ref": "#/definitions/artifactLocation" + }, + + "region": { + "description": "Specifies a portion of the artifact.", + "$ref": "#/definitions/region" + }, + + "contextRegion": { + "description": "Specifies a portion of the artifact that encloses the region. Allows a viewer to display additional context around the region.", + "$ref": "#/definitions/region" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the physical location.", + "$ref": "#/definitions/propertyBag" + } + }, + + "anyOf": [ + { + "required": [ "address" ] + }, + { + "required": [ "artifactLocation" ] + } + ] + }, + + "propertyBag": { + "description": "Key/value pairs that provide additional information about the object.", + "type": "object", + "additionalProperties": true, + "properties": { + "tags": { + + "description": "A set of distinct strings that provide additional information.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "type": "string" + } + } + } + }, + + "rectangle": { + "description": "An area within an image.", + "additionalProperties": false, + "type": "object", + "properties": { + + "top": { + "description": "The Y coordinate of the top edge of the rectangle, measured in the image's natural units.", + "type": "number" + }, + + "left": { + "description": "The X coordinate of the left edge of the rectangle, measured in the image's natural units.", + "type": "number" + }, + + "bottom": { + "description": "The Y coordinate of the bottom edge of the rectangle, measured in the image's natural units.", + "type": "number" + }, + + "right": { + "description": "The X coordinate of the right edge of the rectangle, measured in the image's natural units.", + "type": "number" + }, + + "message": { + "description": "A message relevant to the rectangle.", + "$ref": "#/definitions/message" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the rectangle.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "region": { + "description": "A region within an artifact where a result was detected.", + "additionalProperties": false, + "type": "object", + "properties": { + + "startLine": { + "description": "The line number of the first character in the region.", + "type": "integer", + "minimum": 1 + }, + + "startColumn": { + "description": "The column number of the first character in the region.", + "type": "integer", + "minimum": 1 + }, + + "endLine": { + "description": "The line number of the last character in the region.", + "type": "integer", + "minimum": 1 + }, + + "endColumn": { + "description": "The column number of the character following the end of the region.", + "type": "integer", + "minimum": 1 + }, + + "charOffset": { + "description": "The zero-based offset from the beginning of the artifact of the first character in the region.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "charLength": { + "description": "The length of the region in characters.", + "type": "integer", + "minimum": 0 + }, + + "byteOffset": { + "description": "The zero-based offset from the beginning of the artifact of the first byte in the region.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "byteLength": { + "description": "The length of the region in bytes.", + "type": "integer", + "minimum": 0 + }, + + "snippet": { + "description": "The portion of the artifact contents within the specified region.", + "$ref": "#/definitions/artifactContent" + }, + + "message": { + "description": "A message relevant to the region.", + "$ref": "#/definitions/message" + }, + + "sourceLanguage": { + "description": "Specifies the source language, if any, of the portion of the artifact specified by the region object.", + "type": "string" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the region.", + "$ref": "#/definitions/propertyBag" + } + }, + + "anyOf": [ + { "required": [ "startLine" ] }, + { "required": [ "charOffset" ] }, + { "required": [ "byteOffset" ] } + ] + }, + + "replacement": { + "description": "The replacement of a single region of an artifact.", + "additionalProperties": false, + "type": "object", + "properties": { + + "deletedRegion": { + "description": "The region of the artifact to delete.", + "$ref": "#/definitions/region" + }, + + "insertedContent": { + "description": "The content to insert at the location specified by the 'deletedRegion' property.", + "$ref": "#/definitions/artifactContent" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the replacement.", + "$ref": "#/definitions/propertyBag" + } + }, + + "required": [ "deletedRegion" ] + }, + + "reportingDescriptor": { + "description": "Metadata that describes a specific report produced by the tool, as part of the analysis it provides or its runtime reporting.", + "additionalProperties": false, + "type": "object", + "properties": { + + "id": { + "description": "A stable, opaque identifier for the report.", + "type": "string" + }, + + "deprecatedIds": { + "description": "An array of stable, opaque identifiers by which this report was known in some previous version of the analysis tool.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "items": { + "type": "string" + } + }, + + "guid": { + "description": "A unique identifier for the reporting descriptor in the form of a GUID.", + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" + }, + + "deprecatedGuids": { + "description": "An array of unique identifies in the form of a GUID by which this report was known in some previous version of the analysis tool.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "items": { + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" + } + }, + + "name": { + "description": "A report identifier that is understandable to an end user.", + "type": "string" + }, + + "deprecatedNames": { + "description": "An array of readable identifiers by which this report was known in some previous version of the analysis tool.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "items": { + "type": "string" + } + }, + + "shortDescription": { + "description": "A concise description of the report. Should be a single sentence that is understandable when visible space is limited to a single line of text.", + "$ref": "#/definitions/multiformatMessageString" + }, + + "fullDescription": { + "description": "A description of the report. Should, as far as possible, provide details sufficient to enable resolution of any problem indicated by the result.", + "$ref": "#/definitions/multiformatMessageString" + }, + + "messageStrings": { + "description": "A set of name/value pairs with arbitrary names. Each value is a multiformatMessageString object, which holds message strings in plain text and (optionally) Markdown format. The strings can include placeholders, which can be used to construct a message in combination with an arbitrary number of additional string arguments.", + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/multiformatMessageString" + } + }, + + "defaultConfiguration": { + "description": "Default reporting configuration information.", + "$ref": "#/definitions/reportingConfiguration" + }, + + "helpUri": { + "description": "A URI where the primary documentation for the report can be found.", + "type": "string", + "format": "uri" + }, + + "help": { + "description": "Provides the primary documentation for the report, useful when there is no online documentation.", + "$ref": "#/definitions/multiformatMessageString" + }, + + "relationships": { + "description": "An array of objects that describe relationships between this reporting descriptor and others.", + "type": "array", + "default": [], + "minItems": 0, + "uniqueItems": true, + "items": { + "$ref": "#/definitions/reportingDescriptorRelationship" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the report.", + "$ref": "#/definitions/propertyBag" + } + }, + "required": [ "id" ] + }, + + "reportingConfiguration": { + "description": "Information about a rule or notification that can be configured at runtime.", + "type": "object", + "additionalProperties": false, + "properties": { + + "enabled": { + "description": "Specifies whether the report may be produced during the scan.", + "type": "boolean", + "default": true + }, + + "level": { + "description": "Specifies the failure level for the report.", + "default": "warning", + "enum": [ "none", "note", "warning", "error" ], + "type": "string" + }, + + "rank": { + "description": "Specifies the relative priority of the report. Used for analysis output only.", + "type": "number", + "default": -1.0, + "minimum": -1.0, + "maximum": 100.0 + }, + + "parameters": { + "description": "Contains configuration information specific to a report.", + "$ref": "#/definitions/propertyBag" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the reporting configuration.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "reportingDescriptorReference": { + "description": "Information about how to locate a relevant reporting descriptor.", + "type": "object", + "additionalProperties": false, + "properties": { + + "id": { + "description": "The id of the descriptor.", + "type": "string" + }, + + "index": { + "description": "The index into an array of descriptors in toolComponent.ruleDescriptors, toolComponent.notificationDescriptors, or toolComponent.taxonomyDescriptors, depending on context.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "guid": { + "description": "A guid that uniquely identifies the descriptor.", + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" + }, + + "toolComponent": { + "description": "A reference used to locate the toolComponent associated with the descriptor.", + "$ref": "#/definitions/toolComponentReference" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the reporting descriptor reference.", + "$ref": "#/definitions/propertyBag" + } + }, + "anyOf": [ + { "required": [ "index" ] }, + { "required": [ "guid" ] }, + { "required": [ "id" ] } + ] + }, + + "reportingDescriptorRelationship": { + "description": "Information about the relation of one reporting descriptor to another.", + "type": "object", + "additionalProperties": false, + "properties": { + + "target": { + "description": "A reference to the related reporting descriptor.", + "$ref": "#/definitions/reportingDescriptorReference" + }, + + "kinds": { + "description": "A set of distinct strings that categorize the relationship. Well-known kinds include 'canPrecede', 'canFollow', 'willPrecede', 'willFollow', 'superset', 'subset', 'equal', 'disjoint', 'relevant', and 'incomparable'.", + "type": "array", + "default": [ "relevant" ], + "uniqueItems": true, + "items": { + "type": "string" + } + }, + + "description": { + "description": "A description of the reporting descriptor relationship.", + "$ref": "#/definitions/message" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the reporting descriptor reference.", + "$ref": "#/definitions/propertyBag" + } + }, + "required": [ "target" ] + }, + + "result": { + "description": "A result produced by an analysis tool.", + "additionalProperties": false, + "type": "object", + "properties": { + + "ruleId": { + "description": "The stable, unique identifier of the rule, if any, to which this result is relevant.", + "type": "string" + }, + + "ruleIndex": { + "description": "The index within the tool component rules array of the rule object associated with this result.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "rule": { + "description": "A reference used to locate the rule descriptor relevant to this result.", + "$ref": "#/definitions/reportingDescriptorReference" + }, + + "kind": { + "description": "A value that categorizes results by evaluation state.", + "default": "fail", + "enum": [ "notApplicable", "pass", "fail", "review", "open", "informational" ], + "type": "string" + }, + + "level": { + "description": "A value specifying the severity level of the result.", + "default": "warning", + "enum": [ "none", "note", "warning", "error" ], + "type": "string" + }, + + "message": { + "description": "A message that describes the result. The first sentence of the message only will be displayed when visible space is limited.", + "$ref": "#/definitions/message" + }, + + "analysisTarget": { + "description": "Identifies the artifact that the analysis tool was instructed to scan. This need not be the same as the artifact where the result actually occurred.", + "$ref": "#/definitions/artifactLocation" + }, + + "locations": { + "description": "The set of locations where the result was detected. Specify only one location unless the problem indicated by the result can only be corrected by making a change at every specified location.", + "type": "array", + "minItems": 0, + "uniqueItems": false, + "default": [], + "items": { + "$ref": "#/definitions/location" + } + }, + + "guid": { + "description": "A stable, unique identifier for the result in the form of a GUID.", + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" + }, + + "correlationGuid": { + "description": "A stable, unique identifier for the equivalence class of logically identical results to which this result belongs, in the form of a GUID.", + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" + }, + + "occurrenceCount": { + "description": "A positive integer specifying the number of times this logically unique result was observed in this run.", + "type": "integer", + "minimum": 1 + }, + + "partialFingerprints": { + "description": "A set of strings that contribute to the stable, unique identity of the result.", + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + + "fingerprints": { + "description": "A set of strings each of which individually defines a stable, unique identity for the result.", + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + + "stacks": { + "description": "An array of 'stack' objects relevant to the result.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/stack" + } + }, + + "codeFlows": { + "description": "An array of 'codeFlow' objects relevant to the result.", + "type": "array", + "minItems": 0, + "uniqueItems": false, + "default": [], + "items": { + "$ref": "#/definitions/codeFlow" + } + }, + + "graphs": { + "description": "An array of zero or more unique graph objects associated with the result.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/graph" + } + }, + + "graphTraversals": { + "description": "An array of one or more unique 'graphTraversal' objects.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/graphTraversal" + } + }, + + "relatedLocations": { + "description": "A set of locations relevant to this result.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/location" + } + }, + + "suppressions": { + "description": "A set of suppressions relevant to this result.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "items": { + "$ref": "#/definitions/suppression" + } + }, + + "baselineState": { + "description": "The state of a result relative to a baseline of a previous run.", + "enum": [ + "new", + "unchanged", + "updated", + "absent" + ], + "type": "string" + }, + + "rank": { + "description": "A number representing the priority or importance of the result.", + "type": "number", + "default": -1.0, + "minimum": -1.0, + "maximum": 100.0 + }, + + "attachments": { + "description": "A set of artifacts relevant to the result.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/attachment" + } + }, + + "hostedViewerUri": { + "description": "An absolute URI at which the result can be viewed.", + "type": "string", + "format": "uri" + }, + + "workItemUris": { + "description": "The URIs of the work items associated with this result.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "items": { + "type": "string", + "format": "uri" + } + }, + + "provenance": { + "description": "Information about how and when the result was detected.", + "$ref": "#/definitions/resultProvenance" + }, + + "fixes": { + "description": "An array of 'fix' objects, each of which represents a proposed fix to the problem indicated by the result.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/fix" + } + }, + + "taxa": { + "description": "An array of references to taxonomy reporting descriptors that are applicable to the result.", + "type": "array", + "default": [], + "minItems": 0, + "uniqueItems": true, + "items": { + "$ref": "#/definitions/reportingDescriptorReference" + } + }, + + "webRequest": { + "description": "A web request associated with this result.", + "$ref": "#/definitions/webRequest" + }, + + "webResponse": { + "description": "A web response associated with this result.", + "$ref": "#/definitions/webResponse" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the result.", + "$ref": "#/definitions/propertyBag" + } + }, + "required": [ "message" ] + }, + + "resultProvenance": { + "description": "Contains information about how and when a result was detected.", + "additionalProperties": false, + "type": "object", + "properties": { + + "firstDetectionTimeUtc": { + "description": "The Coordinated Universal Time (UTC) date and time at which the result was first detected. See \"Date/time properties\" in the SARIF spec for the required format.", + "type": "string", + "format": "date-time" + }, + + "lastDetectionTimeUtc": { + "description": "The Coordinated Universal Time (UTC) date and time at which the result was most recently detected. See \"Date/time properties\" in the SARIF spec for the required format.", + "type": "string", + "format": "date-time" + }, + + "firstDetectionRunGuid": { + "description": "A GUID-valued string equal to the automationDetails.guid property of the run in which the result was first detected.", + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" + }, + + "lastDetectionRunGuid": { + "description": "A GUID-valued string equal to the automationDetails.guid property of the run in which the result was most recently detected.", + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" + }, + + "invocationIndex": { + "description": "The index within the run.invocations array of the invocation object which describes the tool invocation that detected the result.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "conversionSources": { + "description": "An array of physicalLocation objects which specify the portions of an analysis tool's output that a converter transformed into the result.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/physicalLocation" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the result.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "run": { + "description": "Describes a single run of an analysis tool, and contains the reported output of that run.", + "additionalProperties": false, + "type": "object", + "properties": { + + "tool": { + "description": "Information about the tool or tool pipeline that generated the results in this run. A run can only contain results produced by a single tool or tool pipeline. A run can aggregate results from multiple log files, as long as context around the tool run (tool command-line arguments and the like) is identical for all aggregated files.", + "$ref": "#/definitions/tool" + }, + + "invocations": { + "description": "Describes the invocation of the analysis tool.", + "type": "array", + "minItems": 0, + "uniqueItems": false, + "default": [], + "items": { + "$ref": "#/definitions/invocation" + } + }, + + "conversion": { + "description": "A conversion object that describes how a converter transformed an analysis tool's native reporting format into the SARIF format.", + "$ref": "#/definitions/conversion" + }, + + "language": { + "description": "The language of the messages emitted into the log file during this run (expressed as an ISO 639-1 two-letter lowercase culture code) and an optional region (expressed as an ISO 3166-1 two-letter uppercase subculture code associated with a country or region). The casing is recommended but not required (in order for this data to conform to RFC5646).", + "type": "string", + "default": "en-US", + "pattern": "^[a-zA-Z]{2}(-[a-zA-Z]{2})?$" + }, + + "versionControlProvenance": { + "description": "Specifies the revision in version control of the artifacts that were scanned.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/versionControlDetails" + } + }, + + "originalUriBaseIds": { + "description": "The artifact location specified by each uriBaseId symbol on the machine where the tool originally ran.", + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/artifactLocation" + } + }, + + "artifacts": { + "description": "An array of artifact objects relevant to the run.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "items": { + "$ref": "#/definitions/artifact" + } + }, + + "logicalLocations": { + "description": "An array of logical locations such as namespaces, types or functions.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/logicalLocation" + } + }, + + "graphs": { + "description": "An array of zero or more unique graph objects associated with the run.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/graph" + } + }, + + "results": { + "description": "The set of results contained in an SARIF log. The results array can be omitted when a run is solely exporting rules metadata. It must be present (but may be empty) if a log file represents an actual scan.", + "type": "array", + "minItems": 0, + "uniqueItems": false, + "items": { + "$ref": "#/definitions/result" + } + }, + + "automationDetails": { + "description": "Automation details that describe this run.", + "$ref": "#/definitions/runAutomationDetails" + }, + + "runAggregates": { + "description": "Automation details that describe the aggregate of runs to which this run belongs.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/runAutomationDetails" + } + }, + + "baselineGuid": { + "description": "The 'guid' property of a previous SARIF 'run' that comprises the baseline that was used to compute result 'baselineState' properties for the run.", + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" + }, + + "redactionTokens": { + "description": "An array of strings used to replace sensitive information in a redaction-aware property.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "type": "string" + } + }, + + "defaultEncoding": { + "description": "Specifies the default encoding for any artifact object that refers to a text file.", + "type": "string" + }, + + "defaultSourceLanguage": { + "description": "Specifies the default source language for any artifact object that refers to a text file that contains source code.", + "type": "string" + }, + + "newlineSequences": { + "description": "An ordered list of character sequences that were treated as line breaks when computing region information for the run.", + "type": "array", + "minItems": 1, + "uniqueItems": true, + "default": [ "\r\n", "\n" ], + "items": { + "type": "string" + } + }, + + "columnKind": { + "description": "Specifies the unit in which the tool measures columns.", + "enum": [ "utf16CodeUnits", "unicodeCodePoints" ], + "type": "string" + }, + + "externalPropertyFileReferences": { + "description": "References to external property files that should be inlined with the content of a root log file.", + "$ref": "#/definitions/externalPropertyFileReferences" + }, + + "threadFlowLocations": { + "description": "An array of threadFlowLocation objects cached at run level.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/threadFlowLocation" + } + }, + + "taxonomies": { + "description": "An array of toolComponent objects relevant to a taxonomy in which results are categorized.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/toolComponent" + } + }, + + "addresses": { + "description": "Addresses associated with this run instance, if any.", + "type": "array", + "minItems": 0, + "uniqueItems": false, + "default": [], + "items": { + "$ref": "#/definitions/address" + } + }, + + "translations": { + "description": "The set of available translations of the localized data provided by the tool.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/toolComponent" + } + }, + + "policies": { + "description": "Contains configurations that may potentially override both reportingDescriptor.defaultConfiguration (the tool's default severities) and invocation.configurationOverrides (severities established at run-time from the command line).", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/toolComponent" + } + }, + + "webRequests": { + "description": "An array of request objects cached at run level.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/webRequest" + } + }, + + "webResponses": { + "description": "An array of response objects cached at run level.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/webResponse" + } + }, + + "specialLocations": { + "description": "A specialLocations object that defines locations of special significance to SARIF consumers.", + "$ref": "#/definitions/specialLocations" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the run.", + "$ref": "#/definitions/propertyBag" + } + }, + + "required": [ "tool" ] + }, + + "runAutomationDetails": { + "description": "Information that describes a run's identity and role within an engineering system process.", + "additionalProperties": false, + "type": "object", + "properties": { + + "description": { + "description": "A description of the identity and role played within the engineering system by this object's containing run object.", + "$ref": "#/definitions/message" + }, + + "id": { + "description": "A hierarchical string that uniquely identifies this object's containing run object.", + "type": "string" + }, + + "guid": { + "description": "A stable, unique identifier for this object's containing run object in the form of a GUID.", + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" + }, + + "correlationGuid": { + "description": "A stable, unique identifier for the equivalence class of runs to which this object's containing run object belongs in the form of a GUID.", + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the run automation details.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "specialLocations": { + "description": "Defines locations of special significance to SARIF consumers.", + "type": "object", + "additionalProperties": false, + "properties": { + + "displayBase": { + "description": "Provides a suggestion to SARIF consumers to display file paths relative to the specified location.", + "$ref": "#/definitions/artifactLocation" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the special locations.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "stack": { + "description": "A call stack that is relevant to a result.", + "additionalProperties": false, + "type": "object", + "properties": { + + "message": { + "description": "A message relevant to this call stack.", + "$ref": "#/definitions/message" + }, + + "frames": { + "description": "An array of stack frames that represents a sequence of calls, rendered in reverse chronological order, that comprise the call stack.", + "type": "array", + "minItems": 0, + "uniqueItems": false, + "items": { + "$ref": "#/definitions/stackFrame" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the stack.", + "$ref": "#/definitions/propertyBag" + } + }, + "required": [ "frames" ] + }, + + "stackFrame": { + "description": "A function call within a stack trace.", + "additionalProperties": false, + "type": "object", + "properties": { + + "location": { + "description": "The location to which this stack frame refers.", + "$ref": "#/definitions/location" + }, + + "module": { + "description": "The name of the module that contains the code of this stack frame.", + "type": "string" + }, + + "threadId": { + "description": "The thread identifier of the stack frame.", + "type": "integer" + }, + + "parameters": { + "description": "The parameters of the call that is executing.", + "type": "array", + "minItems": 0, + "uniqueItems": false, + "default": [], + "items": { + "type": "string", + "default": [] + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the stack frame.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "suppression": { + "description": "A suppression that is relevant to a result.", + "additionalProperties": false, + "type": "object", + "properties": { + + "guid": { + "description": "A stable, unique identifier for the suprression in the form of a GUID.", + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" + }, + + "kind": { + "description": "A string that indicates where the suppression is persisted.", + "enum": [ + "inSource", + "external" + ], + "type": "string" + }, + + "status": { + "description": "A string that indicates the review status of the suppression.", + "enum": [ + "accepted", + "underReview", + "rejected" + ], + "type": "string" + }, + + "justification": { + "description": "A string representing the justification for the suppression.", + "type": "string" + }, + + "location": { + "description": "Identifies the location associated with the suppression.", + "$ref": "#/definitions/location" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the suppression.", + "$ref": "#/definitions/propertyBag" + } + }, + "required": [ "kind" ] + }, + + "threadFlow": { + "description": "Describes a sequence of code locations that specify a path through a single thread of execution such as an operating system or fiber.", + "type": "object", + "additionalProperties": false, + "properties": { + + "id": { + "description": "An string that uniquely identifies the threadFlow within the codeFlow in which it occurs.", + "type": "string" + }, + + "message": { + "description": "A message relevant to the thread flow.", + "$ref": "#/definitions/message" + }, + + + "initialState": { + "description": "Values of relevant expressions at the start of the thread flow that may change during thread flow execution.", + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/multiformatMessageString" + } + }, + + "immutableState": { + "description": "Values of relevant expressions at the start of the thread flow that remain constant.", + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/multiformatMessageString" + } + }, + + "locations": { + "description": "A temporally ordered array of 'threadFlowLocation' objects, each of which describes a location visited by the tool while producing the result.", + "type": "array", + "minItems": 1, + "uniqueItems": false, + "items": { + "$ref": "#/definitions/threadFlowLocation" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the thread flow.", + "$ref": "#/definitions/propertyBag" + } + }, + + "required": [ "locations" ] + }, + + "threadFlowLocation": { + "description": "A location visited by an analysis tool while simulating or monitoring the execution of a program.", + "additionalProperties": false, + "type": "object", + "properties": { + + "index": { + "description": "The index within the run threadFlowLocations array.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "location": { + "description": "The code location.", + "$ref": "#/definitions/location" + }, + + "stack": { + "description": "The call stack leading to this location.", + "$ref": "#/definitions/stack" + }, + + "kinds": { + "description": "A set of distinct strings that categorize the thread flow location. Well-known kinds include 'acquire', 'release', 'enter', 'exit', 'call', 'return', 'branch', 'implicit', 'false', 'true', 'caution', 'danger', 'unknown', 'unreachable', 'taint', 'function', 'handler', 'lock', 'memory', 'resource', 'scope' and 'value'.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "type": "string" + } + }, + + "taxa": { + "description": "An array of references to rule or taxonomy reporting descriptors that are applicable to the thread flow location.", + "type": "array", + "default": [], + "minItems": 0, + "uniqueItems": true, + "items": { + "$ref": "#/definitions/reportingDescriptorReference" + } + }, + + "module": { + "description": "The name of the module that contains the code that is executing.", + "type": "string" + }, + + "state": { + "description": "A dictionary, each of whose keys specifies a variable or expression, the associated value of which represents the variable or expression value. For an annotation of kind 'continuation', for example, this dictionary might hold the current assumed values of a set of global variables.", + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/multiformatMessageString" + } + }, + + "nestingLevel": { + "description": "An integer representing a containment hierarchy within the thread flow.", + "type": "integer", + "minimum": 0 + }, + + "executionOrder": { + "description": "An integer representing the temporal order in which execution reached this location.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "executionTimeUtc": { + "description": "The Coordinated Universal Time (UTC) date and time at which this location was executed.", + "type": "string", + "format": "date-time" + }, + + "importance": { + "description": "Specifies the importance of this location in understanding the code flow in which it occurs. The order from most to least important is \"essential\", \"important\", \"unimportant\". Default: \"important\".", + "enum": [ "important", "essential", "unimportant" ], + "default": "important", + "type": "string" + }, + + "webRequest": { + "description": "A web request associated with this thread flow location.", + "$ref": "#/definitions/webRequest" + }, + + "webResponse": { + "description": "A web response associated with this thread flow location.", + "$ref": "#/definitions/webResponse" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the threadflow location.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "tool": { + "description": "The analysis tool that was run.", + "additionalProperties": false, + "type": "object", + "properties": { + + "driver": { + "description": "The analysis tool that was run.", + "$ref": "#/definitions/toolComponent" + }, + + "extensions": { + "description": "Tool extensions that contributed to or reconfigured the analysis tool that was run.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/toolComponent" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the tool.", + "$ref": "#/definitions/propertyBag" + } + }, + + "required": [ "driver" ] + }, + + "toolComponent": { + "description": "A component, such as a plug-in or the driver, of the analysis tool that was run.", + "additionalProperties": false, + "type": "object", + "properties": { + + "guid": { + "description": "A unique identifier for the tool component in the form of a GUID.", + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" + }, + + "name": { + "description": "The name of the tool component.", + "type": "string" + }, + + "organization": { + "description": "The organization or company that produced the tool component.", + "type": "string" + }, + + "product": { + "description": "A product suite to which the tool component belongs.", + "type": "string" + }, + + "productSuite": { + "description": "A localizable string containing the name of the suite of products to which the tool component belongs.", + "type": "string" + }, + + "shortDescription": { + "description": "A brief description of the tool component.", + "$ref": "#/definitions/multiformatMessageString" + }, + + "fullDescription": { + "description": "A comprehensive description of the tool component.", + "$ref": "#/definitions/multiformatMessageString" + }, + + "fullName": { + "description": "The name of the tool component along with its version and any other useful identifying information, such as its locale.", + "type": "string" + }, + + "version": { + "description": "The tool component version, in whatever format the component natively provides.", + "type": "string" + }, + + "semanticVersion": { + "description": "The tool component version in the format specified by Semantic Versioning 2.0.", + "type": "string" + }, + + "dottedQuadFileVersion": { + "description": "The binary version of the tool component's primary executable file expressed as four non-negative integers separated by a period (for operating systems that express file versions in this way).", + "type": "string", + "pattern": "[0-9]+(\\.[0-9]+){3}" + }, + + "releaseDateUtc": { + "description": "A string specifying the UTC date (and optionally, the time) of the component's release.", + "type": "string" + }, + + "downloadUri": { + "description": "The absolute URI from which the tool component can be downloaded.", + "type": "string", + "format": "uri" + }, + + "informationUri": { + "description": "The absolute URI at which information about this version of the tool component can be found.", + "type": "string", + "format": "uri" + }, + + "globalMessageStrings": { + "description": "A dictionary, each of whose keys is a resource identifier and each of whose values is a multiformatMessageString object, which holds message strings in plain text and (optionally) Markdown format. The strings can include placeholders, which can be used to construct a message in combination with an arbitrary number of additional string arguments.", + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/multiformatMessageString" + } + }, + + "notifications": { + "description": "An array of reportingDescriptor objects relevant to the notifications related to the configuration and runtime execution of the tool component.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/reportingDescriptor" + } + }, + + "rules": { + "description": "An array of reportingDescriptor objects relevant to the analysis performed by the tool component.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/reportingDescriptor" + } + }, + + "taxa": { + "description": "An array of reportingDescriptor objects relevant to the definitions of both standalone and tool-defined taxonomies.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/reportingDescriptor" + } + }, + + "locations": { + "description": "An array of the artifactLocation objects associated with the tool component.", + "type": "array", + "minItems": 0, + "default": [], + "items": { + "$ref": "#/definitions/artifactLocation" + } + }, + + "language": { + "description": "The language of the messages emitted into the log file during this run (expressed as an ISO 639-1 two-letter lowercase language code) and an optional region (expressed as an ISO 3166-1 two-letter uppercase subculture code associated with a country or region). The casing is recommended but not required (in order for this data to conform to RFC5646).", + "type": "string", + "default": "en-US", + "pattern": "^[a-zA-Z]{2}(-[a-zA-Z]{2})?$" + }, + + "contents": { + "description": "The kinds of data contained in this object.", + "type": "array", + "uniqueItems": true, + "default": [ "localizedData", "nonLocalizedData" ], + "items": { + "enum": [ + "localizedData", + "nonLocalizedData" + ], + "type": "string" + } + }, + + "isComprehensive": { + "description": "Specifies whether this object contains a complete definition of the localizable and/or non-localizable data for this component, as opposed to including only data that is relevant to the results persisted to this log file.", + "type": "boolean", + "default": false + }, + + "localizedDataSemanticVersion": { + "description": "The semantic version of the localized strings defined in this component; maintained by components that provide translations.", + "type": "string" + }, + + "minimumRequiredLocalizedDataSemanticVersion": { + "description": "The minimum value of localizedDataSemanticVersion required in translations consumed by this component; used by components that consume translations.", + "type": "string" + }, + + "associatedComponent": { + "description": "The component which is strongly associated with this component. For a translation, this refers to the component which has been translated. For an extension, this is the driver that provides the extension's plugin model.", + "$ref": "#/definitions/toolComponentReference" + }, + + "translationMetadata": { + "description": "Translation metadata, required for a translation, not populated by other component types.", + "$ref": "#/definitions/translationMetadata" + }, + + "supportedTaxonomies": { + "description": "An array of toolComponentReference objects to declare the taxonomies supported by the tool component.", + "type": "array", + "minItems": 0, + "uniqueItems": true, + "default": [], + "items": { + "$ref": "#/definitions/toolComponentReference" + } + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the tool component.", + "$ref": "#/definitions/propertyBag" + } + }, + + "required": [ "name" ] + }, + + "toolComponentReference": { + "description": "Identifies a particular toolComponent object, either the driver or an extension.", + "type": "object", + "additionalProperties": false, + "properties": { + + "name": { + "description": "The 'name' property of the referenced toolComponent.", + "type": "string" + }, + + "index": { + "description": "An index into the referenced toolComponent in tool.extensions.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "guid": { + "description": "The 'guid' property of the referenced toolComponent.", + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the toolComponentReference.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "translationMetadata": { + "description": "Provides additional metadata related to translation.", + "type": "object", + "additionalProperties": false, + "properties": { + + "name": { + "description": "The name associated with the translation metadata.", + "type": "string" + }, + + "fullName": { + "description": "The full name associated with the translation metadata.", + "type": "string" + }, + + "shortDescription": { + "description": "A brief description of the translation metadata.", + "$ref": "#/definitions/multiformatMessageString" + }, + + "fullDescription": { + "description": "A comprehensive description of the translation metadata.", + "$ref": "#/definitions/multiformatMessageString" + }, + + "downloadUri": { + "description": "The absolute URI from which the translation metadata can be downloaded.", + "type": "string", + "format": "uri" + }, + + "informationUri": { + "description": "The absolute URI from which information related to the translation metadata can be downloaded.", + "type": "string", + "format": "uri" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the translation metadata.", + "$ref": "#/definitions/propertyBag" + } + }, + "required": [ "name" ] + }, + + "versionControlDetails": { + "description": "Specifies the information necessary to retrieve a desired revision from a version control system.", + "type": "object", + "additionalProperties": false, + "properties": { + + "repositoryUri": { + "description": "The absolute URI of the repository.", + "type": "string", + "format": "uri" + }, + + "revisionId": { + "description": "A string that uniquely and permanently identifies the revision within the repository.", + "type": "string" + }, + + "branch": { + "description": "The name of a branch containing the revision.", + "type": "string" + }, + + "revisionTag": { + "description": "A tag that has been applied to the revision.", + "type": "string" + }, + + "asOfTimeUtc": { + "description": "A Coordinated Universal Time (UTC) date and time that can be used to synchronize an enlistment to the state of the repository at that time.", + "type": "string", + "format": "date-time" + }, + + "mappedTo": { + "description": "The location in the local file system to which the root of the repository was mapped at the time of the analysis.", + "$ref": "#/definitions/artifactLocation" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the version control details.", + "$ref": "#/definitions/propertyBag" + } + }, + + "required": [ "repositoryUri" ] + }, + + "webRequest": { + "description": "Describes an HTTP request.", + "type": "object", + "additionalProperties": false, + "properties": { + + "index": { + "description": "The index within the run.webRequests array of the request object associated with this result.", + "type": "integer", + "default": -1, + "minimum": -1 + + }, + + "protocol": { + "description": "The request protocol. Example: 'http'.", + "type": "string" + }, + + "version": { + "description": "The request version. Example: '1.1'.", + "type": "string" + }, + + "target": { + "description": "The target of the request.", + "type": "string" + }, + + "method": { + "description": "The HTTP method. Well-known values are 'GET', 'PUT', 'POST', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT'.", + "type": "string" + }, + + "headers": { + "description": "The request headers.", + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + + "parameters": { + "description": "The request parameters.", + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + + "body": { + "description": "The body of the request.", + "$ref": "#/definitions/artifactContent" + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the request.", + "$ref": "#/definitions/propertyBag" + } + } + }, + + "webResponse": { + "description": "Describes the response to an HTTP request.", + "type": "object", + "additionalProperties": false, + "properties": { + + "index": { + "description": "The index within the run.webResponses array of the response object associated with this result.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + + "protocol": { + "description": "The response protocol. Example: 'http'.", + "type": "string" + }, + + "version": { + "description": "The response version. Example: '1.1'.", + "type": "string" + }, + + "statusCode": { + "description": "The response status code. Example: 451.", + "type": "integer" + }, + + "reasonPhrase": { + "description": "The response reason. Example: 'Not found'.", + "type": "string" + }, + + "headers": { + "description": "The response headers.", + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + + "body": { + "description": "The body of the response.", + "$ref": "#/definitions/artifactContent" + }, + + "noResponseReceived": { + "description": "Specifies whether a response was received from the server.", + "type": "boolean", + "default": false + }, + + "properties": { + "description": "Key/value pairs that provide additional information about the response.", + "$ref": "#/definitions/propertyBag" + } + } + } + } +} diff --git a/test_bridge.py b/test_bridge.py new file mode 100644 index 0000000..dfeb0fe --- /dev/null +++ b/test_bridge.py @@ -0,0 +1,120 @@ +"""Synthetic reports; no targets, uploads or credentials.""" +import contextlib +import copy +import io +import json +import os +from pathlib import Path +import subprocess +import sys +import tempfile +import unittest +from unittest.mock import patch +import scan_results_bridge as c + + +def report(status='unknown', source=False): + evidence=[{'id':'e1','kind':'source','state':'candidate','detail':'token=SECRET https://private.invalid?q=SECRET','path':'src/worker α.js','line':4}] if source else [] + evidence.append({'id':'v1','kind':'version','state':'present','detail':'24.22.0 operator reported'}) + row=c.make_result('private-asset','node','CVE-2026-111497',status,version='24.22.0',sources=['https://nodejs.org/en/blog/vulnerability/october-2026-security-releases'],version_assessment='affected' if status=='potentially_affected' else 'unknown',evidence=evidence,recommendation='Inspect C:/private/path token=SECRET') + return c.make_report('synthetic-check','1.0.0','synthetic-1','2026-10-25',[row]) + + +class BridgeTests(unittest.TestCase): + def cli(self,*args): + with contextlib.redirect_stdout(io.StringIO()) as out,contextlib.redirect_stderr(io.StringIO()) as err: + with patch('socket.socket',side_effect=AssertionError('network forbidden')): + code=c.main(list(args)) + return code,out.getvalue(),err.getvalue() + + def test_source_opt_in_and_inventory_never_fabricates_location(self): + for source in (True,False): + value=report(source=source) + rows=c.normalize(value,'contract-v1.0') + self.assertIsNone(rows[0]['location']) + self.assertEqual(source,rows[0]['location_redacted']) + rows=c.normalize(value,'contract-v1.0',True) + sarif=c.to_sarif(rows,True) + result=sarif['runs'][0]['results'][0] + self.assertEqual(source,'locations' in result) + if source:self.assertEqual('src/worker%20%CE%B1.js',result['locations'][0]['physicalLocation']['artifactLocation']['uri']) + + def test_privacy_projection_and_fingerprints_stable_across_status(self): + first=c.normalize(report(source=True),'contract-v1.0')[0] + later=report('potentially_affected',True) + second=c.normalize(later,'contract-v1.0')[0] + self.assertEqual(first['fingerprint'],second['fingerprint']) + text=json.dumps(c.to_sarif([first],True)) + for secret in ('SECRET','private.invalid','private-asset','C:/private/path','worker'): + self.assertNotIn(secret,text) + self.assertEqual('candidate',first['evidence']['evidence'][0]['state']) + self.assertEqual('not_tested',first['exploitability']) + + def test_duplicates_order_and_conflicts_are_distinct(self): + value=report();value['results']*=2 + self.assertEqual(1,len(c.normalize(value,'contract-v1.0'))) + other=report('potentially_affected')['results'][0] + value['results'].append(other) + left=c.normalize(value,'contract-v1.0');value['results'].reverse() + self.assertEqual(left,c.normalize(value,'contract-v1.0')) + self.assertEqual(2,len(left)) + + def test_invalid_contract_and_semantic_contradictions_reject(self): + for key,item in [('schema_version','2.0'),('complete','true')]: + value=report();value[key]=item + with self.assertRaises(ValueError):c.normalize(value,'contract-v1.0') + for key,item in [('exploitability','confirmed'),('status','safe')]: + value=report();value['results'][0][key]=item + with self.assertRaises(ValueError):c.normalize(value,'contract-v1.0') + value=report();value['results'][0]['status']='likely_exposed' + with self.assertRaises(ValueError):c.normalize(value,'contract-v1.0') + for path in ('/tmp/file','../file','C:/file','x\\y','x//y','https://private.invalid'): + self.assertIsNone(c.source_location(path,1)) + self.assertIsNone(c.source_location('src/file',True)) + + def test_policy_exit_codes_ndjson_and_incomplete_summary(self): + with tempfile.TemporaryDirectory() as directory: + path=Path(directory)/'input.json' + for status,policy,code in [('unknown','none',0),('unknown','unknown',1),('potentially_affected','findings',1),('unknown','findings',0)]: + path.write_text(json.dumps(report(status)),encoding='utf-8') + actual,out,err=self.cli('--input',str(path),'--format','ndjson','--fail-on',policy) + self.assertEqual((code,''),(actual,err));rows=[json.loads(line) for line in out.splitlines()] + self.assertEqual('summary',rows[-1]['record_type']) + value=report();value['complete']=False;value['results']=[] + path.write_text(json.dumps(value),encoding='utf-8') + code,out,_=self.cli('--input',str(path),'--format','ndjson') + self.assertEqual(2,code);self.assertFalse(json.loads(out)['complete']) + + def test_output_protection_standalone_and_no_clobber(self): + with tempfile.TemporaryDirectory() as directory: + root=Path(directory);path=root/'input.json';path.write_text(json.dumps(report()),encoding='utf-8') + for force in ([],['--force']): + self.assertEqual(2,self.cli('--input',str(path),'--output',str(path),*force)[0]) + output=root/'out.json';output.write_text('existing',encoding='utf-8') + self.assertEqual(2,self.cli('--input',str(path),'--output',str(output))[0]) + self.assertEqual('existing',output.read_text()) + self.assertEqual(0,self.cli('--input',str(path),'--output',str(output),'--force')[0]) + executable=root/'standalone.py';executable.write_bytes(Path(c.__file__).read_bytes()) + result=subprocess.run([sys.executable,str(executable),'--input',str(path)],capture_output=True,text=True) + self.assertEqual(0,result.returncode);self.assertEqual('2.1.0',json.loads(result.stdout)['version']) + + def test_malformed_bounds_and_duplicate_keys_reject_before_output(self): + with tempfile.TemporaryDirectory() as directory: + path=Path(directory)/'input.json' + for text in ('{"complete":true,"complete":false}','{"complete":NaN}', '['*60+'0'+']'*60): + path.write_text(text,encoding='utf-8');code,out,_=self.cli('--input',str(path));self.assertEqual((2,''),(code,out)) + path.write_bytes(b' '*(4*1024**2+1));self.assertEqual(2,self.cli('--input',str(path))[0]) + + def test_legacy_profiles_fail_closed_and_preserve_unknown(self): + for profile,(tool,prefix,rule) in c.PROFILES.items(): + value=dict(tool=tool,tool_version='1.0.0',complete=True,results=[{prefix+'status':'unknown',prefix+'exploitability':'not_tested','label':'private'}]) + if profile == 'flowise-v1': value['results'][0]['version_status'] = value['results'][0].pop('status') + if profile.endswith('v1.1'):value['schema_version' if profile=='copyescape-v1.1' else 'report_schema_version']='1.1' + elif profile!='node2shell-v1':value['schema_version']=1 + row=c.normalize(value,profile)[0] + self.assertEqual('unknown',row['status']);self.assertEqual(rule,row['rule_id']) + value['tool']='wrong' + with self.assertRaises(ValueError):c.normalize(value,profile) + + +if __name__=='__main__':unittest.main() diff --git a/tools/validate_sarif.py b/tools/validate_sarif.py new file mode 100644 index 0000000..5d395c7 --- /dev/null +++ b/tools/validate_sarif.py @@ -0,0 +1,17 @@ +"""Optional dev check; uses only the vendored official schema, no remote refs.""" +import json +from pathlib import Path +import sys +sys.path.insert(0,str(Path(__file__).resolve().parents[1])) +import jsonschema +import scan_results_bridge as c +from test_bridge import report +root=Path(__file__).resolve().parents[1] +schema=json.loads((root/'schemas/sarif-schema-2.1.0.json').read_text(encoding='utf-8')) +validator=jsonschema.Draft4Validator(schema,format_checker=jsonschema.FormatChecker()) +for source in (False,True): + for status in ('unknown','potentially_affected'): + rows=c.normalize(report(status,source),'contract-v1.0',True) + validator.validate(c.to_sarif(rows,True)) +validator.validate(c.to_sarif([],False)) +print('Five synthetic SARIF variants validated against bundled official OASIS schema.') From d47db0e3940b42ba5c5bb1977f5fc78a2e876c28 Mon Sep 17 00:00:00 2001 From: Timothy Wayne Gregg Date: Sun, 25 Oct 2026 19:34:08 -0400 Subject: [PATCH 2/6] Preserve assessment conflicts, stable identity and per-tool completion --- README.md | 7 +++++++ SHA256SUMS | 2 +- scan_results_bridge.py | 24 ++++++++++++++++-------- test_bridge.py | 31 +++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 76786c0..a39d1f4 100644 --- a/README.md +++ b/README.md @@ -111,3 +111,10 @@ Sources: [OASIS SARIF schema](https://github.com/oasis-tcs/sarif-spec/blob/main/ [GitHub SARIF support](https://docs.github.com/en/code-security/reference/code-scanning/sarif-files/sarif-support). Schema validation is format verification; it does not prove GitHub ingestion or live code-scanning display. No upload or production acceptance was performed. + +Canonical version assessments are retained explicitly; full component metadata +and sources are privacy-projected and included in observation identity, so +conflicts do not deduplicate. Fingerprints use the stable component name, not its +version/build assessment. Each tool/version SARIF invocation has its own combined +completion state, including tools whose input reports have no result rows. +Non-finite numbers, including overflowing JSON exponents, fail before publication. diff --git a/SHA256SUMS b/SHA256SUMS index 45a0973..79c94ec 100644 --- a/SHA256SUMS +++ b/SHA256SUMS @@ -1 +1 @@ -d8ff44637966e10e6a9ec1a72cf527e4077ec7de2ba3896eb03859113e6f7b23 scan_results_bridge.py +c4577816c4b94d6bfa3b43cc6404f1d9693baf4c36e5f3908eb8e35072269c47 scan_results_bridge.py diff --git a/scan_results_bridge.py b/scan_results_bridge.py index f20b14d..4f6869c 100644 --- a/scan_results_bridge.py +++ b/scan_results_bridge.py @@ -588,7 +588,7 @@ def save_report(path, text, force=False, protected_paths=(), state=None): def digest(value): - return hashlib.sha256(json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(',', ':')).encode('utf-8')).hexdigest() + return hashlib.sha256(json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(',', ':'),allow_nan=False).encode('utf-8')).hexdigest() def bounded_structure(value): @@ -598,6 +598,8 @@ def bounded_structure(value): count += 1 if count > 250000 or depth > 40: raise ContractError('Report structure exceeds limits') + if isinstance(item,float) and not math.isfinite(item): + raise ContractError('Non-finite numeric metadata') if isinstance(item, dict): stack.extend((v, depth+1) for v in item.values()) elif isinstance(item, list): @@ -675,7 +677,7 @@ def normalize(report, profile, include_paths=False): if row.get(prefix+'exploitability') != 'not_tested': raise ContractError('Exploitability must remain not_tested') rule = row['rule_id'] if canonical else fixed_rule - if not isinstance(rule, str) or not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9_.-]{0,127}', rule): + if not isinstance(rule, str) or not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}', rule): raise ContractError('Unsupported rule identifier') asset = row.get('asset_id', row.get('input_url', row.get('input_label', row.get('label', row.get('input_id',''))))) if not isinstance(asset, str): @@ -687,15 +689,16 @@ def normalize(report, profile, include_paths=False): if len(locations) == 1: location = locations[0] elif row.get('evidence_type', row.get('copyescape_evidence_type')) in ('lexical_source_candidate','lexical_workflow_candidate'): location = source_location(row.get('source_path'), row.get('source_line')) - identity = {'tool':tool,'rule':rule,'asset':asset,'location':location, 'instance': [row.get(key) for key in ('package','product','install_path','component')]} + identity = {'tool':tool,'rule':rule,'asset':asset,'location':location, 'instance': [row.get(key) for key in ('package','product','install_path')] + [row['component']['name'] if canonical else row.get('component')]} fingerprint = digest(identity) - evidence = {key: row[key] for key in ('evidence','preconditions','mitigation','reachability','threat','reasons','recommendation') if key in row} + evidence = {key: row[key] for key in ('component','version_assessment','sources','evidence','preconditions','mitigation','reachability','threat','reasons','recommendation') if key in row} if not canonical: evidence = {'evidence': {key:value for key,value in row.items() if key not in {'checked_at','generated_at'}}} confidence = row.get('confidence', row.get(prefix+'evidence_confidence','unknown')) if not isinstance(confidence,str) or confidence not in {'low','medium','high','unknown','insufficient'}: confidence='unknown' normalized.append(dict(schema_version='1.0', tool=tool, tool_version=version, rule_id=rule, status=status, exploitability='not_tested', confidence=confidence, complete=report['complete'], + version_assessment=row['version_assessment'] if canonical else 'see_projected_evidence', asset_sha256=digest(asset), fingerprint=fingerprint, location=location if include_paths else None, location_redacted=bool(location and not include_paths), evidence=safe_evidence(evidence), evidence_sha256=digest(evidence), @@ -704,11 +707,13 @@ def normalize(report, profile, include_paths=False): return sorted({digest(row):row for row in normalized}.values(), key=lambda row:(row['tool'],row['rule_id'],row['fingerprint'],digest(row))) -def to_sarif(rows, complete): +def to_sarif(rows, complete, completions=None): runs = [] groups = {} for row in rows: groups.setdefault((row['tool'],row['tool_version']),[]).append(row) + if completions: + for key in completions: groups.setdefault(key,[]) if not groups: groups[('scan-results-bridge',BRIDGE_VERSION)]=[] for (name,version), records in sorted(groups.items()): ids = sorted({r['rule_id'] for r in records}) @@ -723,7 +728,7 @@ def to_sarif(rows, complete): if row['location']: result['locations']=[{'physicalLocation':{'artifactLocation':{'uri':quote(row['location']['path'],safe='/')},'region':{'startLine':row['location']['line']}}}] results.append(result) - runs.append({'tool':{'driver':{'name':name,'version':version,'rules':rules}},'invocations':[{'executionSuccessful':complete}], 'results':results}) + runs.append({'tool':{'driver':{'name':name,'version':version,'rules':rules}},'invocations':[{'executionSuccessful':completions.get((name,version),complete) if completions is not None else all(row['complete'] for row in records) if records else complete}], 'results':results}) return {'version':'2.1.0','$schema':SCHEMA_URI,'runs':runs} @@ -748,19 +753,22 @@ def main(argv=None): raise ContractError('Output aliases protected input') if args.output.exists() and not args.force: raise ContractError('Output exists') rows,complete,total=[],True,0 + completions={} for path in args.input: raw=_read_regular_file(path,4*1024**2) total+=len(raw) if total>16*1024**2: raise ContractError('Combined input byte limit') value=json.loads(raw.decode('utf-8-sig'),object_pairs_hook=_unique_object,parse_constant=lambda _: (_ for _ in ()).throw(ContractError('Non-finite JSON'))) rows.extend(normalize(value,args.input_schema,args.include_relative_paths)) + identity=(value['tool']['name'],value['tool']['version']) if isinstance(value['tool'],dict) else (value['tool'],value['tool_version']) + completions[identity]=completions.get(identity,True) and value['complete'] complete=complete and value['complete'] if len(rows)>10000: raise ContractError('Combined result limit') rows=sorted({digest(row):row for row in rows}.values(),key=lambda row:(row['tool'],row['rule_id'],row['fingerprint'],digest(row))) if args.format=='sarif': - rendered=json.dumps(to_sarif(rows,complete),ensure_ascii=False,sort_keys=True,indent=2)+'\n' + rendered=json.dumps(to_sarif(rows,complete,completions),ensure_ascii=False,sort_keys=True,indent=2,allow_nan=False)+'\n' else: - rendered=''.join(json.dumps(row,ensure_ascii=False,sort_keys=True)+'\n' for row in rows) + rendered=''.join(json.dumps(row,ensure_ascii=False,sort_keys=True,allow_nan=False)+'\n' for row in rows) # Always include an explicit summary, including empty/incomplete conversions. rendered+=json.dumps(dict(record_type='summary',schema_version='1.0',complete=complete,result_count=len(rows)),sort_keys=True)+'\n' if len(rendered.encode('utf-8'))>32*1024**2: raise ContractError('Output byte limit') diff --git a/test_bridge.py b/test_bridge.py index dfeb0fe..b7159a4 100644 --- a/test_bridge.py +++ b/test_bridge.py @@ -105,6 +105,37 @@ def test_malformed_bounds_and_duplicate_keys_reject_before_output(self): path.write_text(text,encoding='utf-8');code,out,_=self.cli('--input',str(path));self.assertEqual((2,''),(code,out)) path.write_bytes(b' '*(4*1024**2+1));self.assertEqual(2,self.cli('--input',str(path))[0]) + def test_canonical_versions_sources_ids_and_fingerprint_updates(self): + value=report();first=c.normalize(value,'contract-v1.0')[0] + value['results'][0]['component']['version']='24.22.1' + value['results'][0]['component']['build_source']='upstream' + second=c.normalize(value,'contract-v1.0')[0] + self.assertEqual(first['fingerprint'],second['fingerprint']) + self.assertNotEqual(first['evidence_sha256'],second['evidence_sha256']) + row=copy.deepcopy(value['results'][0]);row['version_assessment']='affected' + value['results'].append(row) + row=copy.deepcopy(row);row['sources']=['https://example.invalid/other'];value['results'].append(row) + self.assertEqual(3,len(c.normalize(value,'contract-v1.0'))) + value['results'][0]['rule_id']='vendor:rule' + self.assertIn('vendor:rule',[r['rule_id'] for r in c.normalize(value,'contract-v1.0')]) + + def test_nonfinite_exponent_and_per_tool_empty_completion(self): + with tempfile.TemporaryDirectory() as directory: + root=Path(directory);path=root/'input.json' + data=dict(tool='node2shell-check',tool_version='1.0.0',complete=True,results=[dict(node2shell_status='unknown',node2shell_exploitability='not_tested',other=float('inf'))]) + path.write_text(json.dumps(data).replace('Infinity','1e999'),encoding='utf-8') + code,out,_=self.cli('--input',str(path),'--input-schema','node2shell-v1') + self.assertEqual((2,''),(code,out)) + first=report();first['results']=[] + second=report();second['tool']['name']='other-check';second['complete']=False + second['results']=[] + path.write_text(json.dumps(first),encoding='utf-8');other=root/'other.json';other.write_text(json.dumps(second),encoding='utf-8') + code,out,_=self.cli('--input',str(path),'--input',str(other)) + self.assertEqual(2,code) + runs={run['tool']['driver']['name']:run for run in json.loads(out)['runs']} + self.assertTrue(runs['synthetic-check']['invocations'][0]['executionSuccessful']) + self.assertFalse(runs['other-check']['invocations'][0]['executionSuccessful']) + def test_legacy_profiles_fail_closed_and_preserve_unknown(self): for profile,(tool,prefix,rule) in c.PROFILES.items(): value=dict(tool=tool,tool_version='1.0.0',complete=True,results=[{prefix+'status':'unknown',prefix+'exploitability':'not_tested','label':'private'}]) From f90e22b03e71fb534cdb5894b80fc1d8e463b9cf Mon Sep 17 00:00:00 2001 From: Timothy Wayne Gregg Date: Sun, 25 Oct 2026 19:36:08 -0400 Subject: [PATCH 3/6] Remove trailing whitespace from fingerprint declaration --- SHA256SUMS | 2 +- scan_results_bridge.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SHA256SUMS b/SHA256SUMS index 79c94ec..db53329 100644 --- a/SHA256SUMS +++ b/SHA256SUMS @@ -1 +1 @@ -c4577816c4b94d6bfa3b43cc6404f1d9693baf4c36e5f3908eb8e35072269c47 scan_results_bridge.py +08413675732f9f3de9aa43c1fbb35d7d960011452d38442df96538c63ab2a80c scan_results_bridge.py diff --git a/scan_results_bridge.py b/scan_results_bridge.py index 4f6869c..942c708 100644 --- a/scan_results_bridge.py +++ b/scan_results_bridge.py @@ -689,7 +689,7 @@ def normalize(report, profile, include_paths=False): if len(locations) == 1: location = locations[0] elif row.get('evidence_type', row.get('copyescape_evidence_type')) in ('lexical_source_candidate','lexical_workflow_candidate'): location = source_location(row.get('source_path'), row.get('source_line')) - identity = {'tool':tool,'rule':rule,'asset':asset,'location':location, 'instance': [row.get(key) for key in ('package','product','install_path')] + [row['component']['name'] if canonical else row.get('component')]} + identity = {'tool':tool,'rule':rule,'asset':asset,'location':location, 'instance': [row.get(key) for key in ('package','product','install_path')] + [row['component']['name'] if canonical else row.get('component')]} fingerprint = digest(identity) evidence = {key: row[key] for key in ('component','version_assessment','sources','evidence','preconditions','mitigation','reachability','threat','reasons','recommendation') if key in row} if not canonical: From 4e4dfa5502f03ffc4849196c356ce21982432e6e Mon Sep 17 00:00:00 2001 From: Timothy Wayne Gregg Date: Sun, 25 Oct 2026 19:57:05 -0400 Subject: [PATCH 4/6] Apply documented string bounds to legacy metadata keys --- SHA256SUMS | 2 +- scan_results_bridge.py | 2 ++ test_bridge.py | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/SHA256SUMS b/SHA256SUMS index db53329..56eb17b 100644 --- a/SHA256SUMS +++ b/SHA256SUMS @@ -1 +1 @@ -08413675732f9f3de9aa43c1fbb35d7d960011452d38442df96538c63ab2a80c scan_results_bridge.py +523d0ea6a5ba5045399e109b4d76975dfbb392b1cde3a00e9c5f8373661498b6 scan_results_bridge.py diff --git a/scan_results_bridge.py b/scan_results_bridge.py index 942c708..1c0eb97 100644 --- a/scan_results_bridge.py +++ b/scan_results_bridge.py @@ -601,6 +601,8 @@ def bounded_structure(value): if isinstance(item,float) and not math.isfinite(item): raise ContractError('Non-finite numeric metadata') if isinstance(item, dict): + if any(len(key)>16384 for key in item): + raise ContractError("Report key exceeds string limit") stack.extend((v, depth+1) for v in item.values()) elif isinstance(item, list): stack.extend((v, depth+1) for v in item) diff --git a/test_bridge.py b/test_bridge.py index b7159a4..d8c49df 100644 --- a/test_bridge.py +++ b/test_bridge.py @@ -126,6 +126,9 @@ def test_nonfinite_exponent_and_per_tool_empty_completion(self): path.write_text(json.dumps(data).replace('Infinity','1e999'),encoding='utf-8') code,out,_=self.cli('--input',str(path),'--input-schema','node2shell-v1') self.assertEqual((2,''),(code,out)) + data['results'][0].pop('other');data['results'][0]['k'*16385]=0 + path.write_text(json.dumps(data),encoding='utf-8') + self.assertEqual(2,self.cli('--input',str(path),'--input-schema','node2shell-v1')[0]) first=report();first['results']=[] second=report();second['tool']['name']='other-check';second['complete']=False second['results']=[] From 49d54c1ea1aa1dc81b37ee1874f0dd53f452a37c Mon Sep 17 00:00:00 2001 From: Timothy Wayne Gregg Date: Sun, 25 Oct 2026 20:12:23 -0400 Subject: [PATCH 5/6] Preserve source identities, rule snapshots and duplicate occurrence counts --- README.md | 8 ++++++++ SHA256SUMS | 2 +- scan_results_bridge.py | 35 ++++++++++++++++++++++++++++++----- test_bridge.py | 13 +++++++++++++ 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a39d1f4..3141a1a 100644 --- a/README.md +++ b/README.md @@ -118,3 +118,11 @@ conflicts do not deduplicate. Fingerprints use the stable component name, not it version/build assessment. Each tool/version SARIF invocation has its own combined completion state, including tools whose input reports have no result rows. Non-finite numbers, including overflowing JSON exponents, fail before publication. + +When reported, same-line source candidate ordinals and hashed input-artifact +identities disambiguate fingerprints without inventing source columns. Exact +duplicates retain an `occurrences` count; NDJSON summary includes observation_count. +The raw combined-result limit applies before deduplication. Canonical rule snapshot +metadata participates in projected evidence so different snapshots remain distinct +observations. Numeric observations, including reported line numbers in projected +evidence, remain visible; path publication still requires explicit opt-in. diff --git a/SHA256SUMS b/SHA256SUMS index 56eb17b..e351c46 100644 --- a/SHA256SUMS +++ b/SHA256SUMS @@ -1 +1 @@ -523d0ea6a5ba5045399e109b4d76975dfbb392b1cde3a00e9c5f8373661498b6 scan_results_bridge.py +bfa64e4ad4a3957dad52953b4649b2e1af5054cb5f4f90a105ccb0247810ceb5 scan_results_bridge.py diff --git a/scan_results_bridge.py b/scan_results_bridge.py index 1c0eb97..700571f 100644 --- a/scan_results_bridge.py +++ b/scan_results_bridge.py @@ -641,6 +641,17 @@ def source_location(path, line): return {'path': path, 'line': line} +def deduplicate(rows): + unique={} + for row in rows: + value=dict(row) + occurrences=value.pop("occurrences",1) + key=digest(value) + if key in unique:unique[key]["occurrences"]+=occurrences + else:unique[key]={**value,"occurrences":occurrences} + return sorted(unique.values(),key=lambda row:(row["tool"],row["rule_id"],row["fingerprint"],digest(row))) + + def normalize(report, profile, include_paths=False): bounded_structure(report) if not isinstance(report, dict) or type(report.get('complete')) is not bool: @@ -691,9 +702,19 @@ def normalize(report, profile, include_paths=False): if len(locations) == 1: location = locations[0] elif row.get('evidence_type', row.get('copyescape_evidence_type')) in ('lexical_source_candidate','lexical_workflow_candidate'): location = source_location(row.get('source_path'), row.get('source_line')) - identity = {'tool':tool,'rule':rule,'asset':asset,'location':location, 'instance': [row.get(key) for key in ('package','product','install_path')] + [row['component']['name'] if canonical else row.get('component')]} + ordinal=row.get("source_candidate",0) + source_instance=row.get("source_instance","") + if type(ordinal) is not int or not 0<=ordinal<=10000: + raise ContractError("Invalid source candidate ordinal") + if not isinstance(source_instance,str) or (source_instance and not re.fullmatch(r"[a-f0-9]{64}",source_instance)): + raise ContractError("Invalid input artifact identity") + identity = {'tool':tool,'rule':rule,'asset':asset,'location':location, + 'instance': [row.get(key) for key in ('package','product','install_path')] + [row['component']['name'] if canonical else row.get('component')], + 'source_candidate':ordinal,'source_instance':source_instance} fingerprint = digest(identity) evidence = {key: row[key] for key in ('component','version_assessment','sources','evidence','preconditions','mitigation','reachability','threat','reasons','recommendation') if key in row} + if canonical: + evidence['rule_snapshot']=report['rules'] if not canonical: evidence = {'evidence': {key:value for key,value in row.items() if key not in {'checked_at','generated_at'}}} confidence = row.get('confidence', row.get(prefix+'evidence_confidence','unknown')) @@ -706,7 +727,7 @@ def normalize(report, profile, include_paths=False): evidence=safe_evidence(evidence), evidence_sha256=digest(evidence), recommendation='Review the original local report and vendor guidance; metadata does not establish exploitability or safety.')) # Deduplicate exact normalized observations only; conflicting statuses/evidence survive. - return sorted({digest(row):row for row in normalized}.values(), key=lambda row:(row['tool'],row['rule_id'],row['fingerprint'],digest(row))) + return deduplicate(normalized) def to_sarif(rows, complete, completions=None): @@ -755,24 +776,28 @@ def main(argv=None): raise ContractError('Output aliases protected input') if args.output.exists() and not args.force: raise ContractError('Output exists') rows,complete,total=[],True,0 + raw_count=0 completions={} for path in args.input: raw=_read_regular_file(path,4*1024**2) total+=len(raw) if total>16*1024**2: raise ContractError('Combined input byte limit') value=json.loads(raw.decode('utf-8-sig'),object_pairs_hook=_unique_object,parse_constant=lambda _: (_ for _ in ()).throw(ContractError('Non-finite JSON'))) - rows.extend(normalize(value,args.input_schema,args.include_relative_paths)) + normalized=normalize(value,args.input_schema,args.include_relative_paths) + raw_count+=len(value['results']) + if raw_count>10000:raise ContractError('Combined raw result limit') + rows.extend(normalized) identity=(value['tool']['name'],value['tool']['version']) if isinstance(value['tool'],dict) else (value['tool'],value['tool_version']) completions[identity]=completions.get(identity,True) and value['complete'] complete=complete and value['complete'] if len(rows)>10000: raise ContractError('Combined result limit') - rows=sorted({digest(row):row for row in rows}.values(),key=lambda row:(row['tool'],row['rule_id'],row['fingerprint'],digest(row))) + rows=deduplicate(rows) if args.format=='sarif': rendered=json.dumps(to_sarif(rows,complete,completions),ensure_ascii=False,sort_keys=True,indent=2,allow_nan=False)+'\n' else: rendered=''.join(json.dumps(row,ensure_ascii=False,sort_keys=True,allow_nan=False)+'\n' for row in rows) # Always include an explicit summary, including empty/incomplete conversions. - rendered+=json.dumps(dict(record_type='summary',schema_version='1.0',complete=complete,result_count=len(rows)),sort_keys=True)+'\n' + rendered+=json.dumps(dict(record_type='summary',schema_version='1.0',complete=complete,result_count=len(rows),observation_count=sum(row['occurrences'] for row in rows)),sort_keys=True)+'\n' if len(rendered.encode('utf-8'))>32*1024**2: raise ContractError('Output byte limit') if args.output: fd,name=tempfile.mkstemp(prefix='.bridge-',dir=args.output.parent) diff --git a/test_bridge.py b/test_bridge.py index d8c49df..aec49f3 100644 --- a/test_bridge.py +++ b/test_bridge.py @@ -53,6 +53,7 @@ def test_privacy_projection_and_fingerprints_stable_across_status(self): def test_duplicates_order_and_conflicts_are_distinct(self): value=report();value['results']*=2 self.assertEqual(1,len(c.normalize(value,'contract-v1.0'))) + self.assertEqual(2,c.normalize(value,'contract-v1.0')[0]['occurrences']) other=report('potentially_affected')['results'][0] value['results'].append(other) left=c.normalize(value,'contract-v1.0');value['results'].reverse() @@ -119,6 +120,18 @@ def test_canonical_versions_sources_ids_and_fingerprint_updates(self): value['results'][0]['rule_id']='vendor:rule' self.assertIn('vendor:rule',[r['rule_id'] for r in c.normalize(value,'contract-v1.0')]) + def test_same_line_candidates_and_distinct_export_artifacts_keep_identity(self): + rows=[dict(copyescape_status="unknown",copyescape_exploitability="not_tested",label="src/copy.sh",component="docker-cli",copyescape_evidence_type="lexical_workflow_candidate",source_path="src/copy.sh",source_line=2,source_candidate=n) for n in (1,2)] + value=dict(tool="copyescape-check",tool_version="1.1.0",schema_version="1.1",complete=True,results=rows) + normalized=c.normalize(value,"copyescape-v1.1") + self.assertEqual(2,len({row["fingerprint"] for row in normalized})) + for index,row in enumerate(rows):row.update(copyescape_evidence_type="docker_version_export",source_instance=str(index+1)*64,source_candidate=0) + self.assertEqual(2,len({row["fingerprint"] for row in c.normalize(value,"copyescape-v1.1")})) + value=report();other=copy.deepcopy(value);other['rules']['snapshot_id']='synthetic-2' + first=c.normalize(value,'contract-v1.0')[0];second=c.normalize(other,'contract-v1.0')[0] + self.assertEqual(first['fingerprint'],second['fingerprint']) + self.assertNotEqual(first['evidence_sha256'],second['evidence_sha256']) + def test_nonfinite_exponent_and_per_tool_empty_completion(self): with tempfile.TemporaryDirectory() as directory: root=Path(directory);path=root/'input.json' From 0c8e2c5962e7e89747ae4ae541186c76c5d5b683 Mon Sep 17 00:00:00 2001 From: Timothy Wayne Gregg Date: Sun, 25 Oct 2026 20:25:54 -0400 Subject: [PATCH 6/6] Address Copilot review findings with focused regression coverage --- README.md | 2 ++ SHA256SUMS | 2 +- scan_results_bridge.py | 5 ++++- test_bridge.py | 24 ++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3141a1a..cfb1260 100644 --- a/README.md +++ b/README.md @@ -126,3 +126,5 @@ The raw combined-result limit applies before deduplication. Canonical rule snaps metadata participates in projected evidence so different snapshots remain distinct observations. Numeric observations, including reported line numbers in projected evidence, remain visible; path publication still requires explicit opt-in. + +Published tool versions must use the public numeric `major.minor.patch` format, including canonical reports and empty runs. Free-form version labels are rejected before output because they can contain private metadata. Canonical report limitations are included in the privately projected evidence digest. Corroborating source records at the same path and line retain one unambiguous location. diff --git a/SHA256SUMS b/SHA256SUMS index e351c46..92cbbc8 100644 --- a/SHA256SUMS +++ b/SHA256SUMS @@ -1 +1 @@ -bfa64e4ad4a3957dad52953b4649b2e1af5054cb5f4f90a105ccb0247810ceb5 scan_results_bridge.py +a628d4f6b92a495e67a308bcd445e65fd08d532b5984446529e455f2d3dff071 scan_results_bridge.py diff --git a/scan_results_bridge.py b/scan_results_bridge.py index 700571f..8cfa2fe 100644 --- a/scan_results_bridge.py +++ b/scan_results_bridge.py @@ -680,6 +680,8 @@ def normalize(report, profile, include_paths=False): version = report.get('tool_version', '') if not isinstance(version, str) or not re.fullmatch(r'[0-9]+\.[0-9]+\.[0-9]+', version): raise ContractError('Invalid tool version') + if not isinstance(version,str) or not re.fullmatch(r'[0-9]+\.[0-9]+\.[0-9]+',version): + raise ContractError('Published tool version must be a public numeric release version') normalized = [] for index, row in enumerate(rows): if not isinstance(row, dict): @@ -698,7 +700,7 @@ def normalize(report, profile, include_paths=False): location = None if canonical: locations = [source_location(e.get('path'), e.get('line')) for e in row['evidence'] if e.get('kind') == 'source'] - locations = [value for value in locations if value] + locations = [dict(path=path,line=line) for path,line in sorted({(value['path'],value['line']) for value in locations if value})] if len(locations) == 1: location = locations[0] elif row.get('evidence_type', row.get('copyescape_evidence_type')) in ('lexical_source_candidate','lexical_workflow_candidate'): location = source_location(row.get('source_path'), row.get('source_line')) @@ -715,6 +717,7 @@ def normalize(report, profile, include_paths=False): evidence = {key: row[key] for key in ('component','version_assessment','sources','evidence','preconditions','mitigation','reachability','threat','reasons','recommendation') if key in row} if canonical: evidence['rule_snapshot']=report['rules'] + evidence['limitations']=report.get('limitations',[]) if not canonical: evidence = {'evidence': {key:value for key,value in row.items() if key not in {'checked_at','generated_at'}}} confidence = row.get('confidence', row.get(prefix+'evidence_confidence','unknown')) diff --git a/test_bridge.py b/test_bridge.py index aec49f3..54f27d9 100644 --- a/test_bridge.py +++ b/test_bridge.py @@ -27,6 +27,30 @@ def cli(self,*args): code=c.main(list(args)) return code,out.getvalue(),err.getvalue() + def test_private_tool_versions_reject_even_empty_reports(self): + with tempfile.TemporaryDirectory() as directory: + path=Path(directory)/'input.json' + for empty in (False,True): + value=report();value['tool']['version']='https://private.invalid/?token=SYNTHETIC_SECRET' + if empty:value['results']=[] + path.write_text(json.dumps(value),encoding='utf-8') + for fmt in ('sarif','ndjson'): + code,out,_=self.cli('--input',str(path),'--format',fmt) + self.assertEqual((2,''),(code,out)) + + def test_corroborating_source_locations_and_report_limitations(self): + value=report(source=True);first=c.normalize(value,'contract-v1.0',True)[0] + corroborating=copy.deepcopy(value['results'][0]['evidence'][0]);corroborating['id']='e2' + value['results'][0]['evidence'].append(corroborating) + second=c.normalize(value,'contract-v1.0',True)[0] + self.assertEqual(first['location'],second['location']) + self.assertEqual(first['fingerprint'],second['fingerprint']) + value['limitations']=['private limitation SECRET'] + third=c.normalize(value,'contract-v1.0',True)[0] + self.assertNotEqual(second['evidence_sha256'],third['evidence_sha256']) + self.assertNotIn('SECRET',json.dumps(third)) + self.assertEqual(2,len(c.deduplicate([second,third]))) + def test_source_opt_in_and_inventory_never_fabricates_location(self): for source in (True,False): value=report(source=source)