Sprint 018 — Vulnerability Intelligence: TIDB Gap Analysis

1. Scope of analysis

This report inventories the Target Intelligence Database (TIDB) surface that the vulnerability intelligence capability reads and writes, identifies what already exists (reused unchanged), what is extended, and what is created new, and fixes the migration + registry steps needed so the canonical vulnerability knowledge, matches, risk assessments and history are first-class TIDB citizens — never memory-only.

2. Existing TIDB surface reused unchanged (no writes)

Existing table/entity Why it is a consumption input
tidb_technology_observations (TechnologyObservation) The observed technology inventory (canonical name, vendor, product, version, version confidence, category) that drives correlation.
tidb_technology_versions (TechnologyVersion) Evidence-backed version specifications.
tidb_topology_relationships (TopologyRelationship) Existing asset→technology edges reused for correlation; vulnerability edges are written here (same table).
tidb_web_origins / tidb_url_observations Web-surface context for asset exposure assessment.
tidb_js_intelligence_dependencies / JSIntelligenceDependency Supply-chain component hints (package name/version) for software-supply-chain correlation.
tidb_api_hosts / tidb_auth_* / tidb_authorization_* / tidb_cloud_* Authentication / authorization / cloud context consumed as exposure input for risk scoring.
tidb_knowledge_cves / tidb_knowledge_cwes / tidb_knowledge_epss (legacy CVE/CWE/EPSS) Pre-existing mirrored reference tables — kept unchanged, read-only.

These are read-only inputs: the vulnerability capability folds them into correlation and exposure context; it never mutates them.

3. Existing TIDB surface extended (schema additions)

None of the existing tables require column additions or constraint changes. The Wave 12 canonical knowledge, correlation and risk inventory is carried by new tables (below), which is the least-risk path: no migration of populated rows, no breaking changes, and the registry’s name-based auto-mapping (<Name>Model<Name>) keeps the existing entities untouched.

4. New TIDB entities required (created)

All new entities derive from TidbEntity and get mirrored ORM models in infrastructure/db/sql/tidb_models/vulnerability_models.py. Names follow the <Entity>Model<Entity> convention so the generic registry derives repositories automatically. Envelope fields (id, created_at, updated_at, first_seen, last_seen, version, revision, schema_version, deleted_at, meta) are present on every table.

4.1 Vulnerabilitytidb_vulnerabilities

Canonical vulnerability record (CVE projection with full knowledge context).

Column Type Notes
cve_id String(64) index
description Text untrusted content stored verbatim
status String(32) received/awaiting-analysis/analyzed/…
published / modified String(32) nullable ISO
cwes JSON related CWE ids
cvss / epss / kev / exploitability JSON normalized summaries
references JSON reference URLs (stored, never fetched)
source String(64) knowledge source name (index)
analysis_version String(32) normalizer version
mission_id / execution_id / correlation_id String provenance

4.2 CVERecordtidb_cve_records

Knowledge-layer CVE projection (vendor/product, CVSS v3/v4, KEV/PoC flags).

Column Type Notes
cve_id String(64) index
description / status / published / modified CVE metadata
vendor / product String(255) primary affected vendor/product
cwes JSON  
cvss_v3 / cvss_v4 Float nullable  
known_exploited / poc_available Boolean  
source String(64)  

4.3 CWERecordtidb_cwe_records

Canonical CWE with hierarchy.

Column Type Notes
cwe_id String(64) index
name / description String(255) / Text  
parents / children / relationships JSON CWE hierarchy
category String(64)  
source String(64)  

4.4 Cpetidb_cpes

Canonical CPE 2.3 identifier.

Column Type Notes
formatted String(512) canonical 2.3 string (index)
part String(8) a/o/h
vendor / product String(255) index + composite index
version_attr / update / edition / language / sw_edition / target_sw / target_hw / other String CPE attributes
source_format String(8) 2.3 / 2.2
source String(64)  

4.5 Purltidb_purls

Canonical Package URL.

Column Type Notes
canonical String(512) index
ecosystem String(64) index
name / namespace / version_value String(255)  
qualifiers JSON  
subpath String(512)  
source String(64)  

4.6 Vendor / Producttidb_vendors / tidb_products

Canonical vendor/product references with aliases and CPE hints.

4.7 Version / VersionRangetidb_versions / tidb_version_ranges

Canonical version records and version intervals with inclusive/exclusive bounds.

4.8 Advisorytidb_advisories

Normalized vendor security advisories (advisory id, vendor, title, CVE ids, severity, release date, URL, affected product descriptors).

4.9 CvssRecordtidb_cvss_records

Normalized CVSS (version, vector, base score, severity, parsed metrics).

4.10 EpssRecordtidb_epss_records

Normalized EPSS (probability, percentile, predicted date).

4.11 KevRecordtidb_kev_records

CISA KEV membership (in_kev, date added, due date, vendor, product).

4.12 ExploitabilityIndicatortidb_exploitability_indicators

Safe exploit-availability metadata (availability, indicators, public-exploit/ metasploit/exploit-db/github-poc/known-exploited flags, references).

4.13 AffectedProducttidb_affected_products

Affected product / version-range per CVE (vendor, product, CPE, ranges, versions, fixed versions, platform).

4.14 FixedVersiontidb_fixed_versions

Version that fixes a CVE for a product.

4.15 VulnerabilityMatchtidb_vulnerability_matches

The technology→vulnerability correlation result with explicit match state.

Column Type Notes
asset String(512) index
technology String(255) index
cve_id String(64) index
state String(32) match/partial_match/possible_match/no_match/unknown (index)
reason String(64) match (or refusal) reason
observed_version String(255)  
version_confidence String(32)  
confidence Float  
asset_type String(16)  
evidence JSON MatchEvidence descriptors
cvss_score / cvss_severity Float/String nullable knowledge snapshot
epss Float  
in_kev / public_exploit Boolean  
affected JSON matched affected-product descriptor
mission_id / execution_id / correlation_id String provenance
composite indexes (asset, cve), (asset, technology, cve)

4.16 RiskAssessmenttidb_risk_assessments

Deterministic risk assessment (score, priority, factor breakdown, formula version, calculated at, match/asset/CVE provenance).

4.17 AssetRisktidb_asset_risks

Aggregated asset risk (max score/priority, band counts, KEV count, knowledge version, assessed at).

4.18 VulnerabilityEvidencetidb_vulnerability_evidence

Evidence fragment per match (evidence type, value, source, confidence, detail).

4.19 HistoricalVulnerabilityStatetidb_historical_vulnerability_states

Immutable per-asset vulnerability snapshot (CVE ids, top risk, band counts, knowledge version, recorded at).

4.20 KnowledgeSourcetidb_knowledge_sources

Knowledge-source freshness (last refreshed, record count, effective date, schema version, analysis version, stale flag, last error).

4.21 KnowledgeRefreshtidb_knowledge_refreshes

Refresh run observability record (sources, status, records, duration, summary, error).

5. Migration plan

6. Registry + repository wiring

7. Verification steps (gates)

  1. python -m alembic upgrade head — applies the migration.
  2. python -m alembic downgrade base then upgrade head — round-trips.
  3. python -m pytest tests/architecture — no regression (API baseline in sync).
  4. python -m pytest tests/unit -k vulnerability — entity + repository tests.
  5. python -m pytest tests/integration/test_vulnerability_platform.py — SQL write/read round-trip via the assembled platform.
  6. python -m pytest tests/security/test_vulnerability_security.py — boundary + contamination tests.
  7. python -m pytest tests/acceptance/test_vulnerability_acceptance.py — end-to-end persistence.
  8. python -m ruff check src tests/unit tests/integration tests/acceptance tests/security tests/performance — clean.