Skip to main content

csaf-check

CI PyPI Python License

Validate CSAF 2.0 advisories from Python, using the same validator Secvisogram runs - and get an honest answer when that validator is not installed.

The problem

If you publish security advisories as CSAF, you want schema validation in your release pipeline, not in a browser tab at the end. The authoritative implementation of the CSAF 2.0 mandatory tests is @secvisogram/csaf-validator-lib, which is JavaScript. Reimplementing the schema in Python means maintaining a second, subtly different opinion about what "valid" means - and yours will be the wrong one.

So this package does not reimplement anything. It bridges to the real validator and handles the part that is annoying to get right: what happens when the validator is not there.

The contract

validate() never raises. Not when Node is missing, not when the library is absent, not when the validator times out or returns something unexpected. Each of those returns a result that says so:

from csaf_check import validate

result = validate(advisory_dict)

result.available   # could the validator run at all?
result.is_valid    # True / False / None when no verdict was reached
result.errors      # one message per failed mandatory test
result.note        # why there is no verdict, when there isn't
result.conclusive  # available and a verdict exists

This matters because the alternative - a validator that throws on a missing optional dependency - turns a quality gate into a hard dependency, and every caller ends up wrapping it in try/except and swallowing real failures along with the boring ones.

Install

pip install csaf-check

That gives you the Python API and CLI. For actual validation you also need Node.js and the validator library:

npm install @secvisogram/csaf-validator-lib

Without them, csaf-check reports UNKNOWN - validator unavailable and exits 0, so it can sit in a pipeline that has no Node without breaking it. Add --require-validator where the absence itself should be a failure.

The validator is found either next to the installed package or under node_modules in your current working directory, so running npm install in your own project directory is enough - you do not have to install it into site-packages. NODE_PATH is honoured as well.

CLI

csaf-check advisory.json                      # human-readable verdict
csaf-check advisory.json --json               # machine-readable
csaf-check - < advisory.json                  # stdin
csaf-check advisory.json --require-validator  # fail if no verdict is possible

Exit codes: 0 valid (or inconclusive without --require-validator) - 1 invalid - 2 unreadable or malformed input - 3 no verdict possible and --require-validator was set.

Python API

import json
from csaf_check import validate, validator_available

if not validator_available():
    print("install Node.js to enable strict validation")

with open("advisory.json", encoding="utf-8") as fh:
    result = validate(json.load(fh))

if result.conclusive and not result.is_valid:
    for message in result.errors:
        print("FAIL", message)

What this does NOT do

  • It does not generate CSAF documents. It only validates ones you already have.
  • It runs the mandatory tests only, not the informative or optional profiles.
  • It does not check that your advisory is correct, only that it is well-formed. A schema-valid document can still describe the wrong product or the wrong affected range.
  • It does not publish anything, sign anything, or talk to any network service.
  • It is not legal advice about the EU Cyber Resilience Act. CRA is format-neutral and does not mandate CSAF. CSAF is a good machine-readable choice for advisories and VEX, not a compliance checkbox.

Examples

examples/advisory-minimal.json is a small synthetic advisory for a fictional vendor using a placeholder CVE identifier. examples/advisory-invalid.json is deliberately missing the mandatory tracking object. Both exist to exercise this wrapper; neither describes a real product or a real vulnerability.

Testing

pip install -e ".[dev]"
pytest -q

The suite runs without Node.js on purpose - the degradation path is the part most likely to rot.

License

Apache-2.0. See LICENSE.

Built and maintained by Gexiro Global Enterprises Ltd.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csaf_check-0.1.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

csaf_check-0.1.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file csaf_check-0.1.0.tar.gz.

File metadata

  • Download URL: csaf_check-0.1.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for csaf_check-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f79eb1425ba00f547ef7b3479a4e5073c078766cbb01ed87cfd1b05ba7778e26
MD5 0bd75719539ff64a9dcafc4d98f5375d
BLAKE2b-256 2732fe0f99af878823f3064f39a847f23e9b0fe730b6c63d643bc9763c31b46d

See more details on using hashes here.

File details

Details for the file csaf_check-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: csaf_check-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for csaf_check-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4299709188d486cc6ce303d0b98e98dc0c79d1a28d38a0a91017a996724dd37a
MD5 75e6d7c1101b91b937c7664aea667669
BLAKE2b-256 4d87e749dbeb67e272a37047418bb38bcce53b326a6050d08aca8d58e8c80e13

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page