Skip to content
SlateGitOrgPublic

About

Builds CSAF 2.0 advisories from a YAML product matrix and rejects any whose product statuses contradict, whose IDs dangle, whose CVSS disagrees with its vector or whose affected products lack a fix.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

csafcheck

CI

csafcheck

csafcheck builds CSAF 2.0 security advisories from a YAML product matrix and checks advisories for the mistakes that make customer tooling mis-match or drop them: contradicting product statuses, dangling product and group IDs, CVSS scores that disagree with their vectors, version ranges typed into version names, and affected products with no remediation. It also compares two revisions of an advisory and flags revision-hygiene errors and fixed-to-affected regressions.

The vendor (Nimbrel Networks), its products and every advisory in this repository are fictional. CVE identifiers are of the form CVE-2099-NNNN and do not refer to real vulnerabilities.

The problem

A product security team at a network-equipment vendor publishes machine-readable advisories that customers' scanners ingest automatically, so a mistake propagates silently. Hand-edited CSAF JSON regularly ships with a product listed as both known_affected and fixed, product IDs that are referenced but never defined, a base score that does not match its CVSS vector, a version range typed into a product version name, or an affected firmware train with no remediation.

csafcheck removes most of those by generating the document from one source of truth, and catches the rest in hand-edited or third-party documents with a rule engine whose findings carry an RFC 6901 JSON pointer to the offending value.

How it works

flowchart LR
    A["YAML product matrix<br/>and vulnerability list"] --> B["csafcheck build"]
    B --> C["CSAF 2.0 document<br/>deterministic product IDs,<br/>computed CVSS scores"]
    C --> D["csafcheck check<br/>rule engine"]
    D --> E["references, status families,<br/>scores, version names,<br/>remediations"]
    C --> F["csafcheck diff<br/>old vs new revision"]
    F --> G["status transitions and<br/>revision errors"]
Loading
  • source.py loads and validates the YAML: products with firmware trains and versions, per-train status written as vers: ranges, a fixed version, remediations, notes and the revision history.
  • build.py assigns product IDs (CSAFPID-0001, ...), builds the vendor / product_family / product_name / product_version tree, adds a product_version_range branch for every affected range, one product group per firmware train, and the vulnerabilities with product_status, remediations and scores.
  • cvss.py and vers.py hold the CVSS 3.1 calculator and the vers: range parser, which the builder and the rules share, so a score is computed one way everywhere.
  • rules.py runs fifteen rules; diff.py compares revisions; cli.py exposes build, check, diff and cvss.

Rules (each has a fixture in tests/fixtures/broken/ that violates that rule and nothing else):

Rule Fires when
missing-product-id a product id is used in product_status, remediations, scores, threats, flags, groups or relationships but never defined
duplicate-product-id a product id is defined twice
circular-relationship a relationship's result is transitively one of its own references
missing-group-id a group id is used but not defined
duplicate-group-id a group id is defined twice
contradicting-status a product is in more than one of: affected, not affected, fixed, under investigation
duplicate-score-version a product has two cvss_v3 scores of one version in one vulnerability
cvss-mismatch baseScore (compared exactly, so 9.84 against a 9.8 vector fails), baseSeverity, version or a metric field disagrees with the vector
revision-history-order the revision history is not sorted by date, oldest first
latest-version tracking.version is not the number of the newest revision
duplicate-cve one CVE appears in two vulnerabilities
version-range-in-name a product_version name contains <, >, prior to, and later, before, through or a .x wildcard
remediation-without-product a remediation has neither product_ids nor group_ids
V1-affected-without-remediation a known_affected product, after expanding group ids, has no remediation
V2-fix-without-fixed-status a vendor_fix, after expanding group ids, covers any product not listed as fixed or first_fixed in that vulnerability

Quick start

python3 -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"

csafcheck build examples/routers.yaml --out advisory.json --now 2026-11-20T09:00:00Z
csafcheck check advisory.json
csafcheck check tests/fixtures/broken/contradicting-status.json
csafcheck cvss CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
csafcheck diff examples/revisions/advisory-v2.json examples/revisions/advisory-v3.json
pytest -q

check and diff exit 1 when they find a problem and 2 when a file cannot be read or parsed. build needs --now so that the same source and the same timestamp always give the same bytes.

An advisory source looks like this (see examples/ for three complete ones):

families:
  - name: Edge Routers
    products:
      - name: NR Edge Router
        scheme: generic            # or semver
        trains:
          - name: "4.2"
            versions: ["4.2.0", "4.2.3", "4.2.7"]
vulnerabilities:
  - cve: CVE-2099-0101
    title: Out-of-bounds write in the OSPF packet parser
    cvss: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
    product: NR Edge Router
    status:
      "4.2": { affected: "vers:generic/>=4.2.0|<4.2.7", fixed: "4.2.7" }
    remediations:
      - category: vendor_fix
        url: https://psirt.nimbrel.example/fixes/nr-sa-0101

Quote train names and versions: unquoted 4.10 would be read as the number 4.1.

Example output

$ csafcheck build examples/routers.yaml --out advisory.json --now 2026-11-20T09:00:00Z
wrote advisory.json: 20 products, 3 vulnerabilities
$ csafcheck check advisory.json
ok: no violations

$ csafcheck check tests/fixtures/broken/contradicting-status.json
contradicting-status  /vulnerabilities/0/product_status/fixed/0  product CSAFPID-0002 is listed as affected and fixed
1 violation(s)

$ csafcheck check tests/fixtures/broken/V1-affected-without-remediation.json
V1-affected-without-remediation  /vulnerabilities/1/product_status/known_affected/0  known_affected product CSAFPID-0007 has no remediation
1 violation(s)

$ csafcheck cvss CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H
10.0 Critical
$ csafcheck cvss CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
6.1 Medium

$ csafcheck diff examples/revisions/advisory-v2.json examples/revisions/advisory-v3.json
CVE-2099-0901  CSAFPID-0002 (NR Edge Router 4.2.7): fixed -> known_affected
CVE-2099-0901  CSAFPID-0004 (NR Edge Router 5.0.1): known_not_affected -> under_investigation
error  fixed-regression  /vulnerabilities/0/product_status/known_affected/1  CVE-2099-0901: product CSAFPID-0002 moved from fixed to known_affected without a note of category 'other' on the vulnerability
error  revision-entry-missing  /document/tracking/version  version '3' has no revision_history entry

The last command exits 1. The long lines are as printed.

Design decisions

  • Product IDs: sorted order, frozen by pins. Without pins, IDs are assigned in sorted branch-path order, which is deterministic but renumbers everything after an insertion. A published advisory must keep its IDs when a product is added, so a source can carry a pinned_ids map; pinned paths keep their ID and new paths take the next numbers in sorted order. The cost is a generated block in the YAML that has to be refreshed with csafcheck build SOURCE --emit-pins when products are added. A test shows the same edit renumbers existing products when the pins are removed.
  • Exact CVSS arithmetic. The calculator works in fractions and applies the specification's Roundup on the integer obtained from five decimals, so a sum such as 4.000000000000001 cannot round up to 4.1. A test scores all 2,592 base vectors and checks the range and one-decimal form; a table of known vectors checks the values.
  • A vendor_fix names only fixed releases. V2 requires every product a vendor_fix covers to be listed fixed or first_fixed, so the builder points a vendor_fix at the fixed releases by product id, never at a train group (a group also holds the affected versions). The affected ranges it replaces get a companion mitigation remediation ("Upgrade to X. Until then the affected versions have no other fix.") so V1 still sees them covered; a train that already has its own mitigation or workaround gets no companion. Other remediations attach to firmware-train groups, and V1 expands groups before testing coverage, so a product covered only through its group passes. The cost is one extra remediation per vendor_fix in built documents.
  • Rules read defensively and report one violation per offending value. A rule skips values of the wrong type instead of raising, because the checker exists to read broken documents. Pointers are built from array indexes and fixed keys, escaped per RFC 6901, and a test resolves every pointer it reports.
  • Dates without an offset are read as UTC. 2026-10-01 and 2026-10-01T00:00:00Z compare, so mixed forms never crash the date rules.
  • latest-version uses the newest revision by date, not the last listed. A history in the wrong order is then one revision-history-order violation and not two.
  • diff accepts a status regression only with an explanation. A product moving from fixed to an affected status is an error unless the vulnerability in the new revision carries a note of category other that the old revision did not have. The note is not tied to a product, so one note excuses every regression on its vulnerability. This is a convention of this tool, not part of CSAF.

Not covered: JSON-schema validation of the CSAF document (csafcheck applies rules, not the schema), and vers: schemes other than generic and semver.

Testing

GITHUB_ACTIONS=true CI=true COLUMNS=80 pytest -q

148 tests, run offline with no network access. They cover a table of known CVSS vectors and the rejection of malformed vectors, vers: parsing and containment, one broken fixture per rule with the expected rule id and pointer, the valid fixture, a build-then-check round trip for each bundled source, byte-identical output for identical input, product ID stability when a product is added, group expansion for V1, the revision pair for diff, and the command line.

Project layout

src/csafcheck/
  cvss.py      CVSS 3.1 vector parsing and base score
  vers.py      vers: range parsing, ordering and containment
  pointer.py   RFC 6901 pointers
  source.py    advisory source loading and validation
  build.py     source to CSAF 2.0 document, product id assignment
  rules.py     the fifteen rules and check_document
  diff.py      revision comparison
  cli.py       build, check, diff, cvss
examples/      three advisory sources and a revision pair for diff
tests/         unit tests, fixtures/valid.json, fixtures/broken/, fixture_cases.py

python tests/fixture_cases.py rewrites tests/fixtures/broken/ from valid.json; a test checks the committed files match.

License

MIT

About

Builds CSAF 2.0 advisories from a YAML product matrix and rejects any whose product statuses contradict, whose IDs dangle, whose CVSS disagrees with its vector or whose affected products lack a fix.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages