CWE::Catalog
The in-memory CWE catalog.
The default instance (CWE::Catalog.default) is built once from the JSON
blob embedded at compile time and cached for the life of the process.
All CWE.find, CWE.search, etc. helpers route through this default
catalog.
Constructing your own Catalog (e.g. from a different JSON file or a
filtered subset) is supported but rarely necessary — the embedded blob
is sourced from the MITRE CWE Research view (view 1000), which is the
comprehensive set.
Constants
Embedded source data. Loaded at compile time so the resulting binary is self-contained — no I/O is required to look up any CWE entry.
Constructors
The catalog backed by the embedded MITRE data. Built on first access; subsequent calls return the cached instance. Thread-safe — concurrent first calls won't race on the lazy parse.
Build a Catalog from a JSON document with the schema produced by
data/build_data.cr. Useful for testing and for callers that ship
their own subset.
Instance methods
All weaknesses, sorted by numeric id.
Returns a fresh array on each call — the catalog's own storage is never
handed out, so a caller is free to sort/reject/clear the result without
corrupting the catalog. Use each to iterate without the copy.
All ancestors (transitive closure of ChildOf), nearest first.
max_depth guards against pathological catalogs; the real CWE has
chains of length 3-4. view_id filters edges to a single CWE view.
The MITRE catalog version string, e.g. "4.20", or "unknown" if the
build script was not given a sibling XML to read it from.
Direct children of id. Resolved via the pre-built children index in
O(children); when view_id is given, only children whose ChildOf
edge belongs to that view are returned. The returned array is a copy of
the index bucket, so mutating it does not disturb the catalog.
All descendants (transitive closure of children), nearest first.
Look up any entry by id — returns a Weakness, Category, or View
(in that order of preference). Useful when you don't know up front
which kind of CWE entity a given id refers to.
Resolve a Reference_ID such as "REF-2" to its full citation. Returns
nil if the id is not in the registry. The REF- prefix is optional and
case-insensitive, so "REF-2", "ref-2" and "2" are equivalent.
All catalog-level external references (citations), in Reference_ID
order (REF-1, REF-2, … REF-10, …).
Find by "CWE-79" / "cwe-79" / "79". Returns nil if the string
does not parse as a CWE id or the id is not in the catalog.
Member weaknesses (resolved) of a category or view. Members that
reference Categories or Views (rare nesting) are skipped — use
Category#members / View#members for the raw edge list.
Direct parents of id per the catalog's ChildOf edges. When
view_id is given, only edges declared in that CWE view are returned
(CWE catalog records the same parent twice when it appears in multiple
views — view 1000 vs 1003 most commonly).
String-id forms of the traversal API, so callers holding a "CWE-79"
can walk the hierarchy without converting first — the same way find,
category, view and entry already accept either form. An id that
does not parse is a miss, not an error.
The pillar (top-level entry) reached by walking ChildOf edges from
id. Returns the entry itself if it is already a Pillar. Returns
nil if id is not in the catalog. If the ancestor chain contains a
Pillar, that is returned; otherwise the most distant ancestor is
returned (some chains topple out at a Class rather than a Pillar).
Case-insensitive substring search over name + description + extended description + alternate terms. Returns matches in id order.
Like search but returns only entries with at least one hit in the
name field. Useful when callers want strong matches only.