Skip to main content

fallow_types/
results_security_finding.rs

1//! A security candidate of the `fallow security` command.
2
3use super::*;
4
5/// A local security candidate for downstream agent verification, not a verified
6/// vulnerability. Emitted only by `fallow security`, never under bare `fallow`
7/// or the `audit` gate. There is deliberately no `confidence` or
8/// `signal_strength` field: fallow does not prove exploitability, so the trace
9/// (its hops and length) is the only honest signal.
10#[derive(Debug, Clone, Serialize, Deserialize)]
11#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
12pub struct SecurityFinding {
13    /// Location id (rule, path, line, column), equal to SARIF `fallowSecurity/v2`; edits move it.
14    pub finding_id: String,
15    /// Line-independent id (`sec1:<hash>`, `~k` for repeats); a verdict may use it.
16    #[serde(default, skip_serializing_if = "Option::is_none")]
17    pub stable_finding_id: Option<String>,
18    /// The rule that produced this candidate.
19    pub kind: SecurityFindingKind,
20    /// The catalogue category id (e.g. `"dangerous-html"`). `Some` for
21    /// `TaintedSink`. For `ClientServerLeak` it is `"client-server-leak"` for the
22    /// secret leak (older releases omit it) or `"server-only-import"` when a
23    /// `"use client"` cone reaches server-only code.
24    #[serde(default, skip_serializing_if = "Option::is_none")]
25    pub category: Option<String>,
26    /// The CWE number declared by the matched catalogue entry. `None` for
27    /// `ClientServerLeak`; never fabricated beyond the catalogue's value.
28    #[serde(default, skip_serializing_if = "Option::is_none")]
29    pub cwe: Option<u32>,
30    /// File the finding is anchored on (the client boundary). Absolute
31    /// internally; JSON strips the project root via `serde_path::serialize`.
32    #[serde(serialize_with = "serde_path::serialize")]
33    pub path: PathBuf,
34    /// 1-based line number of the anchor.
35    pub line: u32,
36    /// 0-based byte column offset of the anchor.
37    pub col: u32,
38    /// Agent/human-readable evidence (e.g. the named env var the chain reaches).
39    pub evidence: String,
40    /// Whether the sink argument was associated with a known untrusted source by
41    /// the intra-module source-to-sink back-trace (issue #859): a local binding
42    /// referenced in the argument was sourced from a catalogue source path
43    /// (`req.query`, `process.argv`, message-event `data`, etc.). `true` ranks
44    /// the candidate higher and annotates the evidence; `false` does NOT
45    /// suppress the finding (the association is conservative, never a proof, and
46    /// fallow prefers false-negatives over false-positives). Always `false` for
47    /// `ClientServerLeak`. Skipped from JSON when `false` for output stability.
48    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
49    pub source_backed: bool,
50    /// Internal cross-pass carrier (NEVER serialized): the (1-based line, 0-based
51    /// col) of the arg-level source read, resolved by the detector when
52    /// `source_backed` is true and a concrete read span was captured. The ranking
53    /// pass uses it to anchor the taint trace's source node at the real read
54    /// instead of the module import line. `None` for module-level findings and
55    /// for arg-level findings with no concrete read span (synthetic
56    /// framework-param / helper-return sources), where the trace falls back to
57    /// the sink site.
58    #[serde(skip)]
59    pub source_read: Option<(u32, u32)>,
60    /// Verification-priority tier derived from existing reachability, boundary,
61    /// source-backed, and runtime signals. Candidate-only: this does not prove
62    /// exploitability and does not change gates.
63    pub severity: SecuritySeverity,
64    /// Structural import-hop trace from the client boundary to the secret source.
65    /// The hop count is the uncalibrated signal; fallow does not prove the path
66    /// is exploitable.
67    pub trace: Vec<TraceHop>,
68    /// Machine-actionable next steps. Always emitted (possibly empty for
69    /// forward-compat). For security candidates this is a single file-level
70    /// suppress hint (`auto_fixable: false`); there is no auto-fix because
71    /// verification is the agent's job, not fallow's.
72    pub actions: Vec<IssueAction>,
73    /// Dead-code cross-link when the same sink candidate sits in code fallow also
74    /// reports as removable. Agents should verify the dead-code finding and delete
75    /// the code instead of hardening the sink when deletion is safe.
76    #[serde(default, skip_serializing_if = "Option::is_none")]
77    pub dead_code: Option<SecurityDeadCodeContext>,
78    /// Graph-derived reachability ranking signal (issues #860 and #885). `None`
79    /// until the post-detection ranking pass fills it; additive on the wire
80    /// (skipped when absent). Drives the order findings are emitted in:
81    /// runtime-reachable candidates sort first, followed by source-backed and
82    /// source-reachable candidates, then wider blast radius.
83    #[serde(default, skip_serializing_if = "Option::is_none")]
84    pub reachability: Option<SecurityReachability>,
85    /// Agent-actionable candidate record: the untrusted input kind, the sink, and the boundary
86    /// the flow crosses. fallow fills these three slots; the exploitability verdict is the
87    /// agent's job and is not a field here. Always present.
88    pub candidate: SecurityCandidate,
89    /// Source-to-sink taint-flow triple, present only when an untrusted source
90    /// is import-reachable to this sink. Absent (skipped) otherwise.
91    #[serde(default, skip_serializing_if = "Option::is_none")]
92    pub taint_flow: Option<SecurityTaintFlow>,
93    /// Production runtime coverage context for the function enclosing this
94    /// security sink. Present only when `fallow security --runtime-coverage`
95    /// runs and the candidate is a `tainted-sink`.
96    #[serde(default, skip_serializing_if = "Option::is_none")]
97    pub runtime: Option<SecurityRuntimeContext>,
98    /// Internal projection used by `fallow security --surface`. The CLI strips this from
99    /// per-finding JSON and promotes it to the top-level `attack_surface` field only when requested.
100    #[serde(default, skip_serializing_if = "Option::is_none")]
101    pub attack_surface: Option<SecurityAttackSurfaceEntry>,
102    /// Internal input of `stable_finding_id`. Never serialized; `None` after a JSON round trip.
103    #[serde(skip)]
104    pub stable_id_input: Option<crate::security_stable_id::SecurityStableIdInput>,
105}