|
| 1 | +# sbom-diff-and-risk |
| 2 | + |
| 3 | +`sbom-diff-and-risk` is a local, deterministic CLI for comparing two SBOMs or dependency manifests and producing JSON plus Markdown reports. |
| 4 | + |
| 5 | +It uses conservative heuristics for change intelligence. By default it does not resolve CVEs, does not act as a reputation oracle, and does not perform hidden network enrichment. |
| 6 | + |
| 7 | +## Scope |
| 8 | + |
| 9 | +- Normalize two local inputs into a shared component schema. |
| 10 | +- Diff components as `added`, `removed`, and `changed`. |
| 11 | +- Apply conservative, heuristic risk buckets to newly added and changed components. |
| 12 | +- Produce machine-friendly JSON and reviewer-friendly Markdown reports. |
| 13 | +- Stay fully local-file based by default. |
| 14 | + |
| 15 | +## v0.1 Internal Component Model |
| 16 | + |
| 17 | +The normalized schema is the core design choice for the project: |
| 18 | + |
| 19 | +- `name: str` |
| 20 | +- `version: str | None` |
| 21 | +- `ecosystem: str` |
| 22 | +- `purl: str | None` |
| 23 | +- `license_id: str | None` |
| 24 | +- `supplier: str | None` |
| 25 | +- `source_url: str | None` |
| 26 | +- `bom_ref: str | None` |
| 27 | +- `raw_type: str | None` |
| 28 | +- `evidence: dict` |
| 29 | + |
| 30 | +Diff identity is intentionally conservative and uses this precedence: |
| 31 | + |
| 32 | +1. `purl` |
| 33 | +2. `bom_ref` |
| 34 | +3. `(ecosystem, name)` |
| 35 | + |
| 36 | +When a `purl` includes a version, the tool keeps the full value in `Component.purl` for auditability but uses the versionless package coordinate for identity so upgrades still diff as `changed`. |
| 37 | + |
| 38 | +## Non-goals |
| 39 | + |
| 40 | +- No vulnerability database integration in v0.1. |
| 41 | +- No CVE, advisory, or exploit resolution in v0.1. |
| 42 | +- No reputation scoring or malware verdicts. |
| 43 | +- No hidden enrichment or implicit network access. |
| 44 | +- No web UI. |
| 45 | + |
| 46 | +## Supported Formats |
| 47 | + |
| 48 | +- CycloneDX JSON |
| 49 | +- SPDX JSON |
| 50 | +- `requirements.txt` |
| 51 | +- `pyproject.toml` |
| 52 | + |
| 53 | +## Risk Bucket Semantics |
| 54 | + |
| 55 | +The current heuristic buckets are: |
| 56 | + |
| 57 | +- `new_package` |
| 58 | +- `major_upgrade` |
| 59 | +- `version_change_unclassified` |
| 60 | +- `unknown_license` |
| 61 | +- `stale_package` |
| 62 | +- `suspicious_source` |
| 63 | +- `not_evaluated` |
| 64 | + |
| 65 | +Offline `stale_package` evaluation is intentionally deferred. When enrichment is disabled, the tool emits `not_evaluated` findings instead of guessing. |
| 66 | + |
| 67 | +## Output Formats |
| 68 | + |
| 69 | +- `report.json` |
| 70 | +- `report.md` |
| 71 | + |
| 72 | +## Install |
| 73 | + |
| 74 | +```bash |
| 75 | +python -m pip install -e .[dev] |
| 76 | +``` |
| 77 | + |
| 78 | +## Usage |
| 79 | + |
| 80 | +Generate reports from the bundled CycloneDX example inputs: |
| 81 | + |
| 82 | +```bash |
| 83 | +sbom-diff-risk compare \ |
| 84 | + --before examples/cdx_before.json \ |
| 85 | + --after examples/cdx_after.json \ |
| 86 | + --format auto \ |
| 87 | + --out-json outputs/report.json \ |
| 88 | + --out-md outputs/report.md |
| 89 | +``` |
| 90 | + |
| 91 | +Generate reports from the `requirements.txt` examples: |
| 92 | + |
| 93 | +```bash |
| 94 | +sbom-diff-risk compare \ |
| 95 | + --before examples/requirements_before.txt \ |
| 96 | + --after examples/requirements_after.txt \ |
| 97 | + --format auto \ |
| 98 | + --out-json outputs/requirements-report.json \ |
| 99 | + --out-md outputs/requirements-report.md |
| 100 | +``` |
| 101 | + |
| 102 | +Use explicit format flags when you do not want auto-detection: |
| 103 | + |
| 104 | +```bash |
| 105 | +sbom-diff-risk compare \ |
| 106 | + --before examples/spdx_before.json \ |
| 107 | + --after examples/spdx_after.json \ |
| 108 | + --before-format spdx-json \ |
| 109 | + --after-format spdx-json \ |
| 110 | + --out-json outputs/spdx-report.json \ |
| 111 | + --out-md outputs/spdx-report.md |
| 112 | +``` |
| 113 | + |
| 114 | +Generate reports from PEP 621 `pyproject.toml` examples: |
| 115 | + |
| 116 | +```bash |
| 117 | +sbom-diff-risk compare \ |
| 118 | + --before examples/pyproject_before.toml \ |
| 119 | + --after examples/pyproject_after.toml \ |
| 120 | + --format auto \ |
| 121 | + --out-json outputs/pyproject-report.json \ |
| 122 | + --out-md outputs/pyproject-report.md |
| 123 | +``` |
| 124 | + |
| 125 | +## CLI Flags |
| 126 | + |
| 127 | +- `--before path` |
| 128 | +- `--after path` |
| 129 | +- `--format auto|cyclonedx-json|spdx-json|requirements-txt|pyproject-toml` |
| 130 | +- `--before-format cyclonedx-json|spdx-json|requirements-txt|pyproject-toml` |
| 131 | +- `--after-format cyclonedx-json|spdx-json|requirements-txt|pyproject-toml` |
| 132 | +- `--out-json path` |
| 133 | +- `--out-md path` |
| 134 | +- `--strict` |
| 135 | +- `--enrich-pypi` |
| 136 | +- `--source-allowlist pypi.org,files.pythonhosted.org,github.com` |
| 137 | + |
| 138 | +`--enrich-pypi` is reserved for future work and currently returns a clear error. |
| 139 | + |
| 140 | +## Examples |
| 141 | + |
| 142 | +The [`examples/`](D:/OneDrive/Code/scientific-computing-toolkit/tools/sbom-diff-and-risk/examples) directory includes: |
| 143 | + |
| 144 | +- before/after inputs for CycloneDX JSON, SPDX JSON, `requirements.txt`, and `pyproject.toml` |
| 145 | +- a sample CycloneDX-based JSON report at [`sample-report.json`](D:/OneDrive/Code/scientific-computing-toolkit/tools/sbom-diff-and-risk/examples/sample-report.json) |
| 146 | +- a sample CycloneDX-based Markdown report at [`sample-report.md`](D:/OneDrive/Code/scientific-computing-toolkit/tools/sbom-diff-and-risk/examples/sample-report.md) |
| 147 | +- requirements-based sample reports at [`sample-requirements-report.json`](D:/OneDrive/Code/scientific-computing-toolkit/tools/sbom-diff-and-risk/examples/sample-requirements-report.json) and [`sample-requirements-report.md`](D:/OneDrive/Code/scientific-computing-toolkit/tools/sbom-diff-and-risk/examples/sample-requirements-report.md) |
| 148 | + |
| 149 | +## Limitations |
| 150 | + |
| 151 | +- v0.1 is local-file based only. |
| 152 | +- `generated_at` remains `null` to preserve deterministic report output. |
| 153 | +- `stale_package` is not resolved offline. The report emits `not_evaluated` instead. |
| 154 | +- No vulnerability database integration, CVE matching, or advisory enrichment. |
| 155 | +- `requirements.txt` support intentionally covers a conservative subset: plain PEP 508 requirement entries, comments, direct URL requirements, and line continuations. |
| 156 | +- `requirements.txt` intentionally does not support pip include/constraint directives such as `-r`, `-c`, or arbitrary install flags in v0.1. |
| 157 | +- `pyproject.toml` support intentionally covers a conservative subset: PEP 621 `[project.dependencies]` and `[project.optional-dependencies]`. |
| 158 | +- `pyproject.toml` intentionally does not support tool-specific layouts such as Poetry, Hatch, or PDM sections in v0.1. |
| 159 | +- Risk buckets are heuristics, not security verdicts. |
| 160 | +- Runtime-generated `outputs/` artifacts are ignored; tracked examples live in `examples/`. |
| 161 | + |
| 162 | +## Current Status |
| 163 | + |
| 164 | +The project now normalizes local CycloneDX JSON, SPDX JSON, `requirements.txt`, and PEP 621 `pyproject.toml` inputs into the shared component model, diffs them deterministically, and generates stable JSON/Markdown reports with golden tests. |
0 commit comments