Skip to main content

solve/
taxonomy.rs

1//! The specification's appendices: weakness classes, exploit techniques, expertise domains.
2//!
3//! Only the *counts* of CWEs and techniques feed the arithmetic. These types exist so an
4//! assessment records which ones were counted, which is what makes a score auditable.
5
6use core::fmt;
7
8/// A MITRE CWE identifier.
9///
10/// Appendix A is deliberately a hand-picked subset of MITRE's catalogue, not a closed set —
11/// the specification expects it to grow. Any identifier is representable; [`Cwe::in_appendix_a`]
12/// reports whether it is one the specification currently names.
13#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15#[cfg_attr(feature = "serde", serde(transparent))]
16pub struct Cwe(pub u16);
17
18macro_rules! appendix_a {
19    ($($konst:ident = $num:literal, $name:literal;)*) => {
20        impl Cwe {
21            $(
22                #[doc = $name]
23                pub const $konst: Self = Self($num);
24            )*
25        }
26
27        /// Every CWE named in Appendix A, paired with its short description.
28        pub const APPENDIX_A: &[(Cwe, &str)] = &[$((Cwe($num), $name)),*];
29    };
30}
31
32appendix_a! {
33    PATH_TRAVERSAL = 22, "Path traversal";
34    SQL_INJECTION = 89, "SQL injection";
35    CODE_INJECTION = 94, "Code injection";
36    OUT_OF_BOUNDS_READ = 125, "Out-of-bounds read";
37    FORMAT_STRING = 134, "Attacker-controlled format string";
38    UNICODE_HANDLING = 176, "Improper handling of Unicode";
39    URL_ENCODING = 177, "Improper handling of URL encoding";
40    INCORRECT_REGEX = 185, "Incorrect regex";
41    OFF_BY_ONE = 193, "Off-by-one";
42    INFO_LEAK = 200, "Info leak";
43    TIMING_DIFFERENCE = 208, "Observable timing difference";
44    PARAMETER_HANDLING = 233, "Improper handling of parameters";
45    UNNECESSARY_PRIVILEGES = 250, "Execution with unnecessary privileges";
46    PLAINTEXT_PASSWORD = 256, "Plaintext storage of password";
47    NONCE_REUSE = 323, "Nonce/key-pair reuse";
48    WEAK_ENCRYPTION_STRENGTH = 326, "Inadequate encryption strength";
49    BROKEN_CRYPTO_ALGORITHM = 327, "Broken or risky cryptographic algorithm";
50    WEAK_HASH = 328, "Weak hash";
51    WEAK_PRNG_SEED = 335, "Weak PRNG seed";
52    WEAK_PRNG_ALGORITHM = 338, "Weak PRNG algorithm";
53    PREDICTABLE_RANDOM_IDS = 340, "Predictable random IDs";
54    BAD_ORIGIN_VALIDATION = 346, "Bad origin validation";
55    RACE_CONDITION = 362, "Race condition";
56    USE_AFTER_FREE = 416, "Use after free";
57    UNRESTRICTED_UPLOAD = 434, "Unrestricted upload of dangerous file type";
58    UNINITIALIZED_VARIABLE = 457, "Uninitialized variable";
59    UNSAFE_DESERIALIZATION = 502, "Deserialization of untrusted data";
60    SENSITIVE_CACHE = 524, "Use of cache containing sensitive information";
61    OUT_OF_BOUNDS_WRITE = 787, "Out-of-bounds write";
62    DANGLING_POINTER = 825, "Dangling pointer";
63    MISSING_MINIMUM_RANGE_CHECK = 839, "Numeric range check without minimum";
64    TYPE_CONFUSION = 843, "Type confusion";
65    MISSING_AUTHORIZATION = 862, "Missing authorization";
66    NOSQL_INJECTION = 943, "Data query injection";
67    WRONG_COMPARISON_FACTORS = 1025, "Comparison using wrong factors";
68    WEAK_PASSWORD = 1391, "Weak password";
69}
70
71impl Cwe {
72    /// A weakness that was counted but not classified.
73    ///
74    /// Only the number of distinct weaknesses feeds the arithmetic, so an assessment can be
75    /// scored before its classes are pinned down. Such an assessment is not auditable, and
76    /// [`Cwe::in_appendix_a`] reports `false` for it.
77    pub const UNSPECIFIED: Self = Self(0);
78
79    /// The Appendix A description, if this identifier is one the specification names.
80    #[must_use]
81    pub fn name(self) -> Option<&'static str> {
82        APPENDIX_A
83            .iter()
84            .find_map(|&(cwe, name)| (cwe == self).then_some(name))
85    }
86
87    /// Whether the specification currently names this identifier.
88    #[must_use]
89    pub fn in_appendix_a(self) -> bool {
90        self.name().is_some()
91    }
92}
93
94impl fmt::Display for Cwe {
95    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
96        write!(f, "CWE-{}", self.0)
97    }
98}
99
100/// An exploitation technique, per Appendix B.
101///
102/// The specification describes this list as "far from comprehensive" and intends it to become a
103/// CAPEC- or ATT&CK-style taxonomy, so [`Technique::Other`] carries anything not yet named.
104#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
105#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
106#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
107pub enum Technique {
108    /// Mitigation bypass, such as ROP.
109    MitigationBypass,
110    /// Leaking memory layout or content needed by a later stage.
111    MemoryLeak,
112    /// Memory shaping, such as advanced heap grooming.
113    MemoryShaping,
114    /// Timing-sensitive or probabilistic attacks, and probability-enhancing tricks.
115    ProbabilisticAttack,
116    /// Use of deep OS internals.
117    OsSpecific,
118    /// Architecture-specific effects, such as speculative execution.
119    ArchSpecific,
120    /// Cryptographic work needing non-trivial compute.
121    CryptographicCompute,
122    /// A technique that was counted but not classified.
123    Unspecified,
124    /// A technique outside the current appendix.
125    Other(String),
126}
127
128/// A domain of expertise, per Appendix C.
129///
130/// A domain is general knowledge that is neither classical vulnerability-research skill nor
131/// knowledge of the specific system under attack. See [`NON_DOMAINS`] for categories the
132/// specification considered and rejected.
133#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
134#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
135#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
136pub enum Domain {
137    /// Advanced web technologies such as OAuth, passkeys, or CORS bypasses — not XSS basics.
138    Web,
139    /// Network infrastructure and protocols.
140    ComputerNetworks,
141    /// Binary exploitation lore: kernel and ABI internals, standard library and compiler
142    /// internals, memory-safety mitigations, and hardware or CPU issues.
143    LowLevel,
144    /// Cloud service platforms.
145    Cloud,
146    /// Special or niche systems, from ICS and automotive to legacy operating systems.
147    SpecialSystems,
148    /// Cryptography, excluding cryptocurrency.
149    Cryptography,
150    /// Data storage, media encodings, and intricate container formats.
151    DataAndFormats,
152    /// Machine learning implementation and algorithms.
153    MachineLearning,
154    /// A domain outside the current appendix.
155    Other(String),
156}
157
158/// Categories the specification considered as domains of expertise and rejected.
159///
160/// Each was rejected on the grounds that there is no body of lore to have studied — the work
161/// only demands skill. Scoring one of these as expert knowledge inflates a SOLVE score.
162pub const NON_DOMAINS: &[&str] = &[
163    "Hypervisors",
164    "Browsers",
165    "VMs and sandboxed execution environments",
166    "Cryptocurrency",
167    "Difficult code analysis",
168    "Reverse engineering in general",
169    "Databases, excluding the data storage part",
170];