cpefit maps free-text operational technology (OT) asset inventory, such as QUILLMARK AUTO QX-2000 CPU FW 4.1.2, to CPE 2.3 names. A logistic regression scores each candidate and abstains below a threshold fitted on a validation split for 97% precision. Mapped assets are then tested against advisory applicability configurations with the NISTIR 7696 name-matching relations, version bounds and firmware-on-hardware rules. All vendors, products, inventory rows and advisories are fictional and generated from a seed.
A water utility has about 900 PLCs, HMIs, RTUs and industrial switches described in a passive network monitor export and old spreadsheets. Advisories name affected products as CPE 2.3 names with version ranges, often only for a firmware version running on specific hardware. Matching by hand takes weeks. Fuzzy matching is fast but returns confident wrong answers: a sibling model (QX-200 for QX-2000) or the hardware CPE instead of the firmware CPE, which makes a vulnerable controller look clean. A wrong match hides a vulnerability, while an abstention only sends a row to a person, so cpefit prefers to abstain, and it never counts an abstained asset as unaffected.
flowchart LR
A[Inventory text] --> B[Normalise<br/>vendor alias, model key,<br/>version, hw revision]
B --> C[Candidates<br/>vendor first, top 10 by<br/>trigram TF-IDF cosine]
C --> D[Logistic score<br/>7 features, NumPy L2 fit]
D --> E{score >= threshold<br/>fitted for 97% precision?}
E -- yes --> F[Firmware and hardware CPEs]
E -- no --> G[Abstain with top 3<br/>candidates for review]
F --> H[Advisory configurations<br/>NISTIR 7696 relations,<br/>version bounds, AND/negate]
H --> I[Affected assets with<br/>matching path]
G --> J[Listed as unmapped]
The data is split 60/20/20 by product line, so no line appears in two splits. The model is fitted on the training split, the threshold is the lowest score reaching precision 0.97 on the validation split, and precision and coverage are reported on the held-out test split. The generated inventory's unlisted products are rejected by a rule (no listed model is named) before any score is compared, so the validation split also carries injected look-alikes: models one digit away from a listed one that the dictionary does not hold (stress.py, built from validation products only, fixed seed). The model scores these like real typos, and only the threshold keeps them out, which is what the fitted value is calibrated on. The table's injected rows count only in the validation columns; the test split and its figures are unchanged generated data.
Python 3.12 or newer.
python -m venv .venv
. .venv/bin/activate
pip install -e ".[dev]"
cpefit generate --seed 9 --out data # regenerates the committed data
cpefit fit --data data --out model.json
cpefit map data/inventory.csv --model model.json > mapped.csv
cpefit match data/inventory.csv --model model.json --advisories data/advisories
cpefit parse "cpe:2.3:o:quillmark:qx-2000_firmware:4.1.2:*:*:*:*:*:*:*"
cpefit relate "cpe:2.3:o:quillmark:*:*:*:*:*:*:*:*:*" \
"cpe:2.3:o:quillmark:qx-2000_firmware:4.1.2:*:*:*:*:*:*:*"
pytestcpefit fit --data data --out model.json:
validation precision-coverage (rows: 206, of which 33 injected look-alikes, target precision 0.97)
threshold precision coverage mapped wrong
0.5000 0.850 0.994 180 27
0.7000 0.974 0.961 152 4
0.7156 0.974 0.961 152 4 <- chosen
0.8000 1.000 0.961 148 0
0.9000 1.000 0.896 138 0
0.9500 1.000 0.721 111 0
0.9800 1.000 0.571 88 0
0.9900 1.000 0.188 29 0
0.9990 n/a 0.000 0 0
chosen threshold: 0.7156
validation: precision 0.974, coverage 0.961
test (189 rows): precision 1.000, coverage 0.977, not-in-dictionary rows mapped 0/15
test baseline (best trigram cosine, never abstains): precision 0.921
model written to model.json
cpefit map data/inventory.csv --model model.json, five rows from the CSV (a sibling-model row that maps to the shared firmware product and its own hardware, a hardware revision, a hardware-only device, a row held back by the threshold, and a row with no listed model; ... marks an elided tail). A0070 reads MRL-1196A for the real MRL-4196A: its score 0.6035 is under the threshold, so a person confirms it:
asset_id,status,score,firmware_cpe,hardware_cpe,hw_revision,reason,review_candidates
A0300,mapped,0.9955,cpe:2.3:o:quillmark:qx-2000_firmware:4.2.1:*:*:*:*:*:*:*,cpe:2.3:h:quillmark:qx-200:-:*:*:*:*:*:*:*,,,
A0019,mapped,0.9697,cpe:2.3:o:tarnhollow:mxn-7781_firmware:2.3.0:*:*:*:*:*:*:*,cpe:2.3:h:tarnhollow:mxn-7781:-:*:*:*:*:*:*:*,B,,
A0017,mapped,0.8571,,cpe:2.3:h:ostenvale:sg-1396a:-:*:*:*:*:*:*:*,,,
A0070,abstain,0.6035,,,,below_threshold,cpe:2.3:h:corvane:mrl-4196a:-:*:*:*:*:*:*:* (0.6035) | ...
A0022,abstain,0.0336,,,,no_model_match,cpe:2.3:h:sundermere:gm-511:-:*:*:*:*:*:*:* (0.0336) | ...
cpefit match ... --advisory DEMO-ICSA-26-011 (firmware on one hardware model only; the unmapped list is cut with ...):
DEMO-ICSA-26-011 Memory corruption in firmware, larger model only
affected (2):
A0288 via configurations[0].children[0].cpeMatch[0] cpe:2.3:o:kestrelway:laf-9250_firmware:*:*:*:*:*:*:*:* [>=3.9 <3.17]
A0713 via configurations[0].children[0].cpeMatch[0] cpe:2.3:o:kestrelway:laf-9250_firmware:*:*:*:*:*:*:*:* [>=3.9 <3.17]
unmapped, not evaluated (91): A0022 A0032 A0042 A0056 A0068 A0070 ...
- Relations, not string prefixes.
cpefit.relateimplements the NISTIR 7696 attribute table cell by cell, including UNDEFINED when the target holds wildcards. A version-range entry is compared with the version attribute set to ANY, and the asset's version is then checked against the bounds, soversionEndExcludingnever degrades to a prefix test. - Abstain by calibration. The threshold is a fitted value, not a constant: the lowest validation score at which precision reaches 0.97. If no score reaches it, the threshold sits above 1 and nothing maps. The validation split includes injected look-alike rows, so the threshold has errors to trade against: without it the open-door precision on validation is 0.850 (27 wrong of 180 mapped at 0.5), with it 0.974. The price is coverage: 19 rows of the 900 abstain as
below_threshold, mostly real typos of listed models whose version is not in the dictionary, and a person reviews them. On look-alikes of test-split products, which were never used for fitting, the model alone maps all of them and the threshold withholds 33 of 39. - A small, inspectable model. Seven features and a logistic regression trained by full-batch gradient descent with L2. It is deterministic, needs only NumPy, and the weights are readable in the model file. A tree ensemble might score a little better but would need another dependency and is harder to audit.
- Vendor first, then trigrams. The vendor is resolved through the alias table before any similarity is computed, so candidates are the top 10 models of that vendor. This keeps vector work small and stops a model number from matching another vendor's product.
- Review candidates. Abstained rows list up to three candidates ranked by score, with ties broken by trigram cosine. An asset version that cannot be ordered against an advisory's bounds is a
ConfigError, never silently unaffected; an emptynegatenode does not match. - Sibling guard as a feature. A row whose model key equals a different model in the same vendor, or differs by one edit from a listed model, is flagged. Rows whose text names no model the dictionary lists abstain regardless of score.
- Firmware-on-hardware via AND nodes. The asset contributes both its firmware and hardware CPE. An AND node with a firmware branch and a hardware branch matches only when both branches match, so the same firmware on
qx-200is not flagged by an advisory written forqx-2000. Non-vulnerable entries (the hardware branch) take part in matching but are not reported as the vulnerable component. - Synthetic data with a documented seed. A splitmix64 stream in the generator keeps the files byte-identical on any Python and NumPy version. The data holds 12 fictional vendors, a 396-entry CPE dictionary, 900 inventory rows (72 for products not in the dictionary, 45 sibling-model near-collisions) and 20 advisories. A test regenerates it and compares all 26 files (inventory, labels, dictionary, splits, alias and truth files, 20 advisories) byte for byte.
GITHUB_ACTIONS=true CI=true COLUMNS=80 pytest163 tests pass in the last run. They cover CPE parsing and round trips (including Hypothesis), every cell of the relation table, version bound types (checked against hand-written orderings, so the matcher and the generator's ground truth do not only agree with each other), negate and firmware-on-hardware configurations, version extraction, mapper precision and coverage on the test split, the threshold trading coverage for precision on injected look-alikes (including held-out ones, where precision on test rows plus look-alikes misses 0.95 without the threshold and meets it with it, and the below_threshold branch of the decision), abstention of unlisted products, the QX-200 / QX-2000 pair, advisory matching against truth, generator reproducibility and determinism of fit and map.
src/cpefit/
cpe.py CPE 2.3 parse, bind and WFN conversion
relate.py NISTIR 7696 attribute and name relations
config.py NVD-style applicability configuration evaluation
versions.py firmware version parsing and ordering
normalise.py vendor alias table, tokens, model and version extraction
catalog.py CPE dictionary and trigram TF-IDF index
mapper.py candidates, features, logistic regression, abstain decision
fit.py training, threshold calibration, held-out evaluation
stress.py injected look-alike rows for threshold calibration
match.py advisory matching over a mapped inventory
generate.py seeded fictional data generator
cli.py Typer commands
data/ generated dictionary, inventory, labels, splits, advisories
tests/
MIT. See LICENSE.
