mirror of
https://github.com/CyberSecurityUP/NeuroSploit.git
synced 2026-12-05 02:24:17 +01:00
Merge pull request #113 from JoasASantos/feat/wire-deterministic-gates
feat: wire-first deterministic gates (P0 refactor)
This commit is contained in:
3 files changed
+466
-16
No files matched your search
@@ -0,0 +1,445 @@
|
||||
//! Deterministic, wire-first gates.
|
||||
//!
|
||||
//! The LLM vote is a second opinion, not the gate. Before a finding is reported
|
||||
//! the harness re-issues a safe GET itself, keeps the real request/response as
|
||||
//! evidence, and applies class-specific rules:
|
||||
//!
|
||||
//! - sourcemap: the `.map` must be served and parse as a source map;
|
||||
//! - admin/exposed panel: a redirect, WAF page, SPA fallback or an admin shell
|
||||
//! without privileged data is not an unauthenticated admin;
|
||||
//! - rate-limit/IDOR: without a burst / identity-pair receipt it is a lead;
|
||||
//! - everything else: the CWE validator judges the measured exchange.
|
||||
//!
|
||||
//! Only POST/PUT/PATCH/DELETE findings are left alone (a replay could mutate
|
||||
//! state); they stay leads unless the agent already supplied evidence.
|
||||
|
||||
use crate::pipeline::{default_scan_headers, default_user_agent, effective_scope};
|
||||
use crate::types::Finding;
|
||||
use crate::validation::{Evidence, Exchange, Verdict};
|
||||
use std::collections::BTreeMap;
|
||||
use std::time::{Duration, Instant};
|
||||
use tokio::sync::mpsc::Sender;
|
||||
|
||||
const MAX_PROBES: usize = 40;
|
||||
const MAX_BODY: usize = 256 * 1024;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum Class {
|
||||
Sourcemap,
|
||||
Admin,
|
||||
RateLimit,
|
||||
Idor,
|
||||
Generic,
|
||||
}
|
||||
|
||||
fn class_of(f: &Finding) -> Class {
|
||||
let t = f.title.to_ascii_lowercase();
|
||||
let a = f.agent.to_ascii_lowercase();
|
||||
let cwe = f.cwe.to_ascii_lowercase();
|
||||
if a.contains("sourcemap") || t.contains("sourcemap") || t.contains("source map") {
|
||||
return Class::Sourcemap;
|
||||
}
|
||||
if t.contains("rate limit")
|
||||
|| t.contains("rate-limit")
|
||||
|| t.contains("ratelimit")
|
||||
|| a.contains("rate_limit")
|
||||
{
|
||||
return Class::RateLimit;
|
||||
}
|
||||
if t.contains("idor")
|
||||
|| t.contains("bola")
|
||||
|| t.contains("sequential")
|
||||
|| t.contains("broken object")
|
||||
|| a == "idor"
|
||||
|| a == "bola"
|
||||
{
|
||||
return Class::Idor;
|
||||
}
|
||||
if f.endpoint.to_ascii_lowercase().contains("/admin")
|
||||
|| f.endpoint.to_ascii_lowercase().contains("/administrator")
|
||||
|| t.contains("admin panel")
|
||||
|| t.contains("admin access")
|
||||
|| t.contains("exposed admin")
|
||||
|| ((cwe.contains("306") || cwe.contains("862") || cwe.contains("425")) && t.contains("admin"))
|
||||
{
|
||||
return Class::Admin;
|
||||
}
|
||||
Class::Generic
|
||||
}
|
||||
|
||||
fn unsafe_method(f: &Finding) -> bool {
|
||||
let blob = format!("{} {} {}", f.title, f.payload, f.evidence).to_ascii_lowercase();
|
||||
["post ", "put ", "patch ", "delete "].iter().any(|m| blob.contains(m))
|
||||
}
|
||||
|
||||
fn absolute(cfg: &crate::types::RunConfig, endpoint: &str) -> Option<reqwest::Url> {
|
||||
let e = endpoint.trim();
|
||||
if e.starts_with("http://") || e.starts_with("https://") {
|
||||
return reqwest::Url::parse(e).ok();
|
||||
}
|
||||
// "GET /admin" or a bare path.
|
||||
let path = if e.starts_with('/') {
|
||||
e.split_whitespace().next()?
|
||||
} else {
|
||||
e.split_whitespace().nth(1)?
|
||||
};
|
||||
let base = reqwest::Url::parse(&cfg.target)
|
||||
.or_else(|_| reqwest::Url::parse(&format!("https://{}", crate::scope::host_of(&cfg.target))))
|
||||
.ok()?;
|
||||
base.join(path).ok()
|
||||
}
|
||||
|
||||
fn same_origin_root(url: &reqwest::Url) -> Option<reqwest::Url> {
|
||||
let mut u = url.clone();
|
||||
u.set_path("/");
|
||||
u.set_query(None);
|
||||
u.set_fragment(None);
|
||||
Some(u)
|
||||
}
|
||||
|
||||
fn sourcemap_url(f: &Finding, endpoint: &reqwest::Url) -> Option<reqwest::Url> {
|
||||
if endpoint.path().ends_with(".map") {
|
||||
return Some(endpoint.clone());
|
||||
}
|
||||
if endpoint.path().ends_with(".js") {
|
||||
let mut u = endpoint.clone();
|
||||
u.set_query(None);
|
||||
u.set_fragment(None);
|
||||
let path = format!("{}.map", u.path());
|
||||
u.set_path(&path);
|
||||
return Some(u);
|
||||
}
|
||||
// The agent may have quoted the map URL in its evidence/PoC.
|
||||
for src in [&f.payload, &f.evidence] {
|
||||
for tok in src.split_whitespace() {
|
||||
if tok.starts_with("http") && tok.contains(".map") {
|
||||
if let Ok(u) = reqwest::Url::parse(tok.trim_end_matches(['.', ')', '"', '\''])) {
|
||||
return Some(u);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn client(cfg: &crate::types::RunConfig) -> reqwest::Client {
|
||||
reqwest::Client::builder()
|
||||
.danger_accept_invalid_certs(true)
|
||||
.timeout(Duration::from_secs(12))
|
||||
.redirect(reqwest::redirect::Policy::none())
|
||||
.default_headers(default_scan_headers())
|
||||
.user_agent(cfg.user_agent.clone().unwrap_or_else(default_user_agent))
|
||||
.build()
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
async fn get(client: &reqwest::Client, cfg: &crate::types::RunConfig, url: &reqwest::Url) -> Option<Exchange> {
|
||||
let start = Instant::now();
|
||||
let mut req = client.get(url.clone());
|
||||
let mut request_headers = BTreeMap::new();
|
||||
if let Some(auth) = cfg.auth.as_deref().filter(|s| !s.trim().is_empty()) {
|
||||
if let Some((k, v)) = auth.split_once(':') {
|
||||
let (k, v) = (k.trim(), v.trim());
|
||||
if !k.is_empty() {
|
||||
req = req.header(k, v);
|
||||
request_headers.insert(k.to_ascii_lowercase(), v.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
let resp = req.send().await.ok()?;
|
||||
let status = resp.status().as_u16();
|
||||
let headers: BTreeMap<String, String> = resp
|
||||
.headers()
|
||||
.iter()
|
||||
.map(|(k, v)| (k.as_str().to_ascii_lowercase(), v.to_str().unwrap_or("").to_string()))
|
||||
.collect();
|
||||
let content_type = headers.get("content-type").cloned().unwrap_or_default();
|
||||
let body = resp.text().await.ok()?.chars().take(MAX_BODY).collect::<String>();
|
||||
Some(Exchange {
|
||||
method: "GET".into(),
|
||||
url: url.to_string(),
|
||||
status,
|
||||
body,
|
||||
content_type,
|
||||
elapsed_ms: start.elapsed().as_millis() as u64,
|
||||
headers,
|
||||
request_headers,
|
||||
provenance: "wire:harness".into(),
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn summary(ex: &Exchange) -> String {
|
||||
format!(
|
||||
"GET {} -> HTTP {} ({} bytes, {})",
|
||||
ex.url,
|
||||
ex.status,
|
||||
ex.body.len(),
|
||||
if ex.content_type.is_empty() { "unknown" } else { &ex.content_type }
|
||||
)
|
||||
}
|
||||
|
||||
fn apply(f: &mut Finding, v: Verdict, evidence: Evidence) {
|
||||
f.evidence_data = Some(evidence);
|
||||
f.validation_level = "deterministic".into();
|
||||
match v {
|
||||
Verdict::Confirmed(reason) => {
|
||||
f.validated = true;
|
||||
f.review_status = "confirmed".into();
|
||||
f.review_reason = reason;
|
||||
}
|
||||
Verdict::Rejected(reason) => {
|
||||
f.validated = false;
|
||||
f.review_status = "rejected".into();
|
||||
f.review_reason = reason;
|
||||
}
|
||||
Verdict::NeedsReview(reason) => {
|
||||
f.validated = false;
|
||||
f.review_status = "needs-review".into();
|
||||
f.review_reason = reason;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn waf_blocked(ex: &Exchange) -> Option<String> {
|
||||
let v = crate::waf::classify_exchange(ex);
|
||||
if v.origin.supports_a_finding() {
|
||||
None
|
||||
} else {
|
||||
Some(format!("the response came from the {} ({}) — the application was not reached", v.origin.as_str(), v.reason))
|
||||
}
|
||||
}
|
||||
|
||||
fn admin_has_data(ex: &Exchange) -> bool {
|
||||
let b = ex.body.to_ascii_lowercase();
|
||||
let ct = ex.content_type.to_ascii_lowercase();
|
||||
(ct.contains("json")
|
||||
&& (b.contains("\"users\"") || b.contains("\"roles\"") || b.contains("\"admin\"") || b.contains("\"accounts\"")))
|
||||
|| (b.contains("<form") && (b.contains("action=\"/admin") || b.contains("action='/admin")))
|
||||
|| b.contains("user management")
|
||||
|| b.contains("role management")
|
||||
}
|
||||
|
||||
async fn gate_generic(
|
||||
client: &reqwest::Client,
|
||||
cfg: &crate::types::RunConfig,
|
||||
f: &mut Finding,
|
||||
tx: &Sender<String>,
|
||||
) {
|
||||
let Some(url) = absolute(cfg, &f.endpoint) else { return };
|
||||
let Some(attack) = get(client, cfg, &url).await else { return };
|
||||
let evidence = Evidence { attack: Some(attack.clone()), ..Default::default() };
|
||||
if let Some(reason) = waf_blocked(&attack) {
|
||||
let _ = tx.send(format!("gate {} → rejected ({reason})", f.title)).await;
|
||||
apply(f, Verdict::Rejected(reason), evidence);
|
||||
return;
|
||||
}
|
||||
f.evidence = summary(&attack);
|
||||
let v = crate::validation::judge(f, Some(&evidence));
|
||||
let label = match &v {
|
||||
Verdict::Confirmed(_) => "confirmed",
|
||||
Verdict::Rejected(_) => "rejected",
|
||||
Verdict::NeedsReview(_) => "needs-review",
|
||||
};
|
||||
let _ = tx.send(format!("gate {} → {label} ({})", f.title, summary(&attack))).await;
|
||||
apply(f, v, evidence);
|
||||
}
|
||||
|
||||
async fn gate_admin(
|
||||
client: &reqwest::Client,
|
||||
cfg: &crate::types::RunConfig,
|
||||
f: &mut Finding,
|
||||
tx: &Sender<String>,
|
||||
) {
|
||||
let Some(url) = absolute(cfg, &f.endpoint) else { return };
|
||||
let Some(attack) = get(client, cfg, &url).await else {
|
||||
apply(f, Verdict::NeedsReview("admin claim could not be replayed".into()), Evidence::default());
|
||||
return;
|
||||
};
|
||||
let baseline = match same_origin_root(&url) {
|
||||
Some(root) => get(client, cfg, &root).await,
|
||||
None => None,
|
||||
};
|
||||
let evidence = Evidence { baseline: baseline.clone(), attack: Some(attack.clone()), ..Default::default() };
|
||||
if let Some(reason) = waf_blocked(&attack) {
|
||||
let _ = tx.send(format!("gate /admin → rejected ({reason})")).await;
|
||||
apply(f, Verdict::Rejected(reason), evidence);
|
||||
return;
|
||||
}
|
||||
if attack.is_redirect() {
|
||||
apply(f, Verdict::Rejected(format!("admin path returns a {} redirect, not the panel", attack.status)), evidence);
|
||||
return;
|
||||
}
|
||||
if !attack.is_success() {
|
||||
apply(f, Verdict::Rejected(format!("admin path returned HTTP {}", attack.status)), evidence);
|
||||
return;
|
||||
}
|
||||
if let Some(b) = &baseline {
|
||||
if !attack.body.is_empty() && attack.body == b.body {
|
||||
apply(f, Verdict::Rejected("admin path serves the same SPA/fallback body as / — not a privileged panel".into()), evidence);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if admin_has_data(&attack) {
|
||||
let _ = tx.send(format!("gate /admin → confirmed (admin data, HTTP {})", attack.status)).await;
|
||||
apply(f, Verdict::Confirmed(format!("admin content served unauthenticated ({})", summary(&attack))), evidence);
|
||||
} else {
|
||||
let _ = tx.send(format!("gate /admin → needs-review (shell only, HTTP {})", attack.status)).await;
|
||||
apply(
|
||||
f,
|
||||
Verdict::NeedsReview(
|
||||
"admin shell/landing served without privileged data — needs an identity pair or admin API data".into(),
|
||||
),
|
||||
evidence,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async fn gate_sourcemap(
|
||||
client: &reqwest::Client,
|
||||
cfg: &crate::types::RunConfig,
|
||||
f: &mut Finding,
|
||||
tx: &Sender<String>,
|
||||
) {
|
||||
let Some(endpoint) = absolute(cfg, &f.endpoint) else { return };
|
||||
let Some(map_url) = sourcemap_url(f, &endpoint) else {
|
||||
apply(f, Verdict::NeedsReview("no .map URL could be derived from the finding".into()), Evidence::default());
|
||||
return;
|
||||
};
|
||||
let Some(attack) = get(client, cfg, &map_url).await else { return };
|
||||
let evidence = Evidence { attack: Some(attack.clone()), ..Default::default() };
|
||||
if let Some(reason) = waf_blocked(&attack) {
|
||||
apply(f, Verdict::Rejected(reason), evidence);
|
||||
return;
|
||||
}
|
||||
if !attack.is_success() {
|
||||
apply(f, Verdict::Rejected(format!("source map {} returned HTTP {} — not served", map_url, attack.status)), evidence);
|
||||
return;
|
||||
}
|
||||
let Ok(v) = serde_json::from_str::<serde_json::Value>(&attack.body) else {
|
||||
apply(f, Verdict::Rejected("the .map response is not JSON (HTML/SPA/404 body)".into()), evidence);
|
||||
return;
|
||||
};
|
||||
let has_map = v.get("mappings").and_then(|m| m.as_str()).map(|m| !m.is_empty()).unwrap_or(false)
|
||||
|| v.get("sources").and_then(|s| s.as_array()).map(|a| !a.is_empty()).unwrap_or(false);
|
||||
if !has_map {
|
||||
apply(f, Verdict::Rejected("JSON served, but it has no source-map `sources`/`mappings`".into()), evidence);
|
||||
return;
|
||||
}
|
||||
let has_source = v
|
||||
.get("sourcesContent")
|
||||
.and_then(|s| s.as_array())
|
||||
.map(|a| a.iter().any(|x| x.as_str().map(|s| !s.trim().is_empty()).unwrap_or(false)))
|
||||
.unwrap_or(false);
|
||||
let _ = tx.send(format!(
|
||||
"gate sourcemap → confirmed ({} sources, sourcesContent={has_source})",
|
||||
v.get("sources").and_then(|s| s.as_array()).map(|a| a.len()).unwrap_or(0)
|
||||
))
|
||||
.await;
|
||||
if !has_source {
|
||||
f.severity = "Low".into();
|
||||
}
|
||||
f.evidence = summary(&attack);
|
||||
apply(
|
||||
f,
|
||||
Verdict::Confirmed(if has_source {
|
||||
"source map served with embedded original source (sourcesContent)".into()
|
||||
} else {
|
||||
"source map served (paths/mappings only; no embedded source content)".into()
|
||||
}),
|
||||
evidence,
|
||||
);
|
||||
}
|
||||
|
||||
/// Apply the gates in place; returns the same findings with deterministic
|
||||
/// `validated`/`review_status` decisions. Only validated findings are reported.
|
||||
pub async fn enforce(
|
||||
cfg: &crate::types::RunConfig,
|
||||
mut findings: Vec<Finding>,
|
||||
tx: &Sender<String>,
|
||||
) -> Vec<Finding> {
|
||||
if cfg.offline {
|
||||
return findings;
|
||||
}
|
||||
let scope = effective_scope(cfg);
|
||||
let client = client(cfg);
|
||||
let mut probes = 0usize;
|
||||
for f in &mut findings {
|
||||
let class = class_of(f);
|
||||
if class == Class::RateLimit || class == Class::Idor {
|
||||
if f.evidence_data.is_none() && !f.validated {
|
||||
f.validated = false;
|
||||
f.review_status = "needs-review".into();
|
||||
f.review_reason = if class == Class::RateLimit {
|
||||
"gate: no burst/429 receipt — rate-limit claim unverified".into()
|
||||
} else {
|
||||
"gate: no identity pair/matrix/oracle receipt — access-control claim unverified".into()
|
||||
};
|
||||
let _ = tx.send(format!("gate {} → needs-review (no deterministic receipt)", f.title)).await;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if class == Class::Generic && f.evidence_data.is_some() {
|
||||
continue;
|
||||
}
|
||||
if unsafe_method(f) {
|
||||
if f.evidence_data.is_none() {
|
||||
f.validated = false;
|
||||
f.review_status = "needs-review".into();
|
||||
f.review_reason = "gate: state-changing request was not replayed automatically".into();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let Some(url) = absolute(cfg, &f.endpoint) else { continue };
|
||||
if !matches!(scope.check(url.as_str(), crate::scope::Action::Probe), crate::scope::Decision::Allow) {
|
||||
f.validated = false;
|
||||
f.review_status = "rejected".into();
|
||||
f.review_reason = "gate: endpoint is outside the authorized scope".into();
|
||||
continue;
|
||||
}
|
||||
if probes >= MAX_PROBES {
|
||||
break;
|
||||
}
|
||||
probes += 1;
|
||||
match class {
|
||||
Class::Sourcemap => gate_sourcemap(&client, cfg, f, tx).await,
|
||||
Class::Admin => gate_admin(&client, cfg, f, tx).await,
|
||||
_ => gate_generic(&client, cfg, f, tx).await,
|
||||
}
|
||||
}
|
||||
findings
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::types::RunConfig;
|
||||
|
||||
fn cfg() -> RunConfig {
|
||||
RunConfig::new("https://app.example.com/")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sourcemap_url_is_derived_from_the_js_bundle() {
|
||||
let f = Finding { endpoint: "https://app.example.com/static/app.js?v=15".into(), ..Default::default() };
|
||||
let u = absolute(&cfg(), &f.endpoint).unwrap();
|
||||
let map = sourcemap_url(&f, &u).unwrap();
|
||||
assert_eq!(map.as_str(), "https://app.example.com/static/app.js.map");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relative_admin_path_uses_the_target_origin() {
|
||||
let u = absolute(&cfg(), "/admin").unwrap();
|
||||
assert_eq!(u.as_str(), "https://app.example.com/admin");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classifies_the_false_positive_families() {
|
||||
let admin = Finding { endpoint: "https://x/admin".into(), title: "Unauthenticated admin panel".into(), ..Default::default() };
|
||||
assert!(matches!(class_of(&admin), Class::Admin));
|
||||
let sm = Finding { endpoint: "https://x/a.js".into(), agent: "sourcemap_exposure".into(), ..Default::default() };
|
||||
assert!(matches!(class_of(&sm), Class::Sourcemap));
|
||||
let rate = Finding { title: "Missing Rate Limiting on /api/login".into(), ..Default::default() };
|
||||
assert!(matches!(class_of(&rate), Class::RateLimit));
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ pub mod attack_path;
|
||||
pub mod audit;
|
||||
pub mod autoconfig;
|
||||
pub mod belief;
|
||||
pub mod gates;
|
||||
pub mod browser;
|
||||
pub mod budget;
|
||||
pub mod cache;
|
||||
|
||||
@@ -1133,7 +1133,7 @@ pub async fn revalidate(findings: Vec<Finding>, pool: &ModelPool, vote_n: usize,
|
||||
pool.set_progress(tx.clone());
|
||||
let _ = tx.send(format!("re-validating {} recovered finding(s) by {}-model vote…", findings.len(), vote_n)).await;
|
||||
let deduped = dedup_findings(findings);
|
||||
let mut v = validate(deduped, pool, VOTE_SYS, vote_n, &tx).await;
|
||||
let mut v = validate(None, deduped, pool, VOTE_SYS, vote_n, &tx).await;
|
||||
v = refute_pass(v, pool, vote_n, &tx).await;
|
||||
strip_attribution(&mut v);
|
||||
let _ = tx.send(format!("re-validation done — {} finding(s) survived", v.len())).await;
|
||||
@@ -2725,7 +2725,7 @@ pub async fn run(mut cfg: RunConfig, lib: &Library, pool: &ModelPool, tx: Sender
|
||||
}
|
||||
|
||||
// ---- 4. Validate by N-model voting ---------------------------------
|
||||
let mut findings = validate_with_persist(candidates, pool, VOTE_SYS, effective_vote_n(&cfg), &tx, cfg.workdir.as_deref()).await;
|
||||
let mut findings = validate_with_persist(Some(&cfg), candidates, pool, VOTE_SYS, effective_vote_n(&cfg), &tx, cfg.workdir.as_deref()).await;
|
||||
|
||||
// ---- 4b. Authorization matrix: deterministic multi-identity sweep --
|
||||
let mx = authz_matrix_pass(&cfg, &recon, &tx).await;
|
||||
@@ -2892,7 +2892,7 @@ pub async fn run_whitebox(cfg: RunConfig, lib: &Library, pool: &ModelPool, tx: S
|
||||
}
|
||||
}
|
||||
let _ = tx.send(format!("{} candidate finding(s) (deduped) — validating", candidates.len())).await;
|
||||
let findings = validate(candidates, pool, CODE_VOTE_SYS, effective_vote_n(&cfg), &tx).await;
|
||||
let findings = validate(Some(&cfg), candidates, pool, CODE_VOTE_SYS, effective_vote_n(&cfg), &tx).await;
|
||||
let findings = refute_pass(findings, pool, effective_vote_n(&cfg), &tx).await;
|
||||
finish(cfg, lib, pool, "{}".into(), transcript, findings, selected, &mut rl, crate::grounding::GroundMode::Symbolic, context, tx).await
|
||||
}
|
||||
@@ -3109,7 +3109,7 @@ pub async fn run_greybox(cfg: RunConfig, lib: &Library, pool: &ModelPool, tx: Se
|
||||
}
|
||||
}
|
||||
let _ = tx.send(format!("{} candidate finding(s) (deduped) — validating", candidates.len())).await;
|
||||
let mut findings = validate(candidates, pool, VOTE_SYS, effective_vote_n(&cfg), &tx).await;
|
||||
let mut findings = validate(Some(&cfg), candidates, pool, VOTE_SYS, effective_vote_n(&cfg), &tx).await;
|
||||
let chained = attack_chain(pool, &cfg, &recon, &findings, &lib.chains, &tx).await;
|
||||
findings.extend(chained);
|
||||
findings = dedup_findings(findings);
|
||||
@@ -3605,7 +3605,7 @@ async fn attack_chain(pool: &ModelPool, cfg: &RunConfig, recon: &str,
|
||||
break;
|
||||
}
|
||||
// Validate before pivoting further (don't chain off false positives).
|
||||
let validated = validate(fresh, pool, VOTE_SYS, cfg.vote_n, tx).await;
|
||||
let validated = validate(Some(cfg), fresh, pool, VOTE_SYS, cfg.vote_n, tx).await;
|
||||
let _ = tx.send(format!("⛓ round {round}: +{} validated finding(s), {} loot item(s) total", validated.len(), loot.len())).await;
|
||||
if validated.is_empty() {
|
||||
break;
|
||||
@@ -4274,11 +4274,11 @@ fn heuristic_select(ranked: &[Agent], recon: &str, focus: &str, cap: usize) -> V
|
||||
out.into_iter().take(cap).collect()
|
||||
}
|
||||
|
||||
async fn validate(candidates: Vec<Finding>, pool: &ModelPool, sys: &str, vote_n: usize, tx: &Sender<String>) -> Vec<Finding> {
|
||||
validate_with_persist(candidates, pool, sys, vote_n, tx, None).await
|
||||
async fn validate(cfg: Option<&RunConfig>, candidates: Vec<Finding>, pool: &ModelPool, sys: &str, vote_n: usize, tx: &Sender<String>) -> Vec<Finding> {
|
||||
validate_with_persist(cfg, candidates, pool, sys, vote_n, tx, None).await
|
||||
}
|
||||
|
||||
async fn validate_with_persist(candidates: Vec<Finding>, pool: &ModelPool, sys: &str, vote_n: usize, tx: &Sender<String>, workdir: Option<&str>) -> Vec<Finding> {
|
||||
async fn validate_with_persist(cfg: Option<&RunConfig>, candidates: Vec<Finding>, pool: &ModelPool, sys: &str, vote_n: usize, tx: &Sender<String>, workdir: Option<&str>) -> Vec<Finding> {
|
||||
// --no-validate: operator opted out of the adversarial vote. Keep every
|
||||
// finding with the severity its agent assigned, marked `unvalidated` — the
|
||||
// panel discards nothing. (Set by the launcher when cfg.no_validate.)
|
||||
@@ -4435,9 +4435,13 @@ async fn validate_with_persist(candidates: Vec<Finding>, pool: &ModelPool, sys:
|
||||
persist_rejected(workdir, &vote_rejected);
|
||||
}
|
||||
flagged.extend(all);
|
||||
// Only deterministic/LLM-confirmed findings are reported. Candidates that
|
||||
// failed to provide a replayable request/response, or that the validators
|
||||
// could not confirm, are kept as LEADS (leads.json) — never as findings.
|
||||
// Wire-first deterministic gates: replay the request, keep the actual
|
||||
// request/response as evidence, and decide sourcemap/admin/rate/IDOR (or the
|
||||
// CWE validator) before anything is reported. Without a receipt it is a lead.
|
||||
if let Some(cfg) = cfg {
|
||||
flagged = crate::gates::enforce(cfg, flagged, tx).await;
|
||||
}
|
||||
// Only validated findings are reported. Candidates/leads stay in leads.json.
|
||||
let (validated_only, leads): (Vec<_>, Vec<_>) = flagged.into_iter().partition(|f| f.validated);
|
||||
persist_leads(workdir, &leads);
|
||||
validated_only
|
||||
@@ -6638,7 +6642,7 @@ pub async fn run_container(cfg: RunConfig, lib: &Library, pool: &ModelPool, tx:
|
||||
let transcript = transcript_of(&raw);
|
||||
let candidates = dedup_findings(raw.iter().flat_map(|(_, _, f)| f.clone()).collect());
|
||||
let _ = tx.send(format!("{} finding(s) (deduped) - validating", candidates.len())).await;
|
||||
let findings = validate(candidates, pool, VOTE_SYS, effective_vote_n(&cfg), &tx).await;
|
||||
let findings = validate(Some(&cfg), candidates, pool, VOTE_SYS, effective_vote_n(&cfg), &tx).await;
|
||||
finish(cfg, lib, pool, recon, transcript, findings, selected, &mut rl, crate::grounding::GroundMode::Empirical, String::new(), tx).await
|
||||
}
|
||||
|
||||
@@ -6843,7 +6847,7 @@ pub async fn run_mobile(cfg: RunConfig, lib: &Library, pool: &ModelPool, tx: Sen
|
||||
let transcript = transcript_of(&raw);
|
||||
let candidates = dedup_findings(raw.iter().flat_map(|(_, _, f)| f.clone()).collect());
|
||||
let _ = tx.send(format!("{} candidate finding(s) (deduped) - validating", candidates.len())).await;
|
||||
let findings = validate(candidates, pool, VOTE_SYS, effective_vote_n(&cfg), &tx).await;
|
||||
let findings = validate(Some(&cfg), candidates, pool, VOTE_SYS, effective_vote_n(&cfg), &tx).await;
|
||||
let findings = refute_pass(findings, pool, effective_vote_n(&cfg), &tx).await;
|
||||
finish(cfg, lib, pool, recon, transcript, findings, selected, &mut rl, crate::grounding::GroundMode::Empirical, String::new(), tx).await
|
||||
}
|
||||
@@ -7051,7 +7055,7 @@ pub async fn run_host(cfg: RunConfig, lib: &Library, pool: &ModelPool, tx: Sende
|
||||
}
|
||||
}
|
||||
let _ = tx.send(format!("{} candidate finding(s) (deduped) — validating", candidates.len())).await;
|
||||
let mut findings = validate(candidates, pool, VOTE_SYS, effective_vote_n(&cfg), &tx).await;
|
||||
let mut findings = validate(Some(&cfg), candidates, pool, VOTE_SYS, effective_vote_n(&cfg), &tx).await;
|
||||
let chained = attack_chain(pool, &cfg, &recon, &findings, &lib.chains, &tx).await;
|
||||
findings.extend(chained);
|
||||
findings = dedup_findings(findings);
|
||||
@@ -8008,7 +8012,7 @@ pub async fn run_ai(cfg: RunConfig, lib: &Library, pool: &ModelPool, tx: Sender<
|
||||
}
|
||||
}
|
||||
let _ = tx.send(format!("{} AI candidate(s) — validating", candidates.len())).await;
|
||||
let mut findings = validate(candidates, pool, VOTE_SYS, effective_vote_n(&cfg), &tx).await;
|
||||
let mut findings = validate(Some(&cfg), candidates, pool, VOTE_SYS, effective_vote_n(&cfg), &tx).await;
|
||||
let chained = attack_chain(pool, &cfg, &recon, &findings, &lib.chains, &tx).await;
|
||||
findings.extend(chained);
|
||||
findings = dedup_findings(findings);
|
||||
@@ -8072,7 +8076,7 @@ pub async fn run_skills_audit(cfg: RunConfig, lib: &Library, pool: &ModelPool, t
|
||||
crate::traces::record_all(cfg.workdir.as_deref(), &raw);
|
||||
let transcript = transcript_of(&raw);
|
||||
let candidates = dedup_findings(raw.iter().flat_map(|(_, _, f)| f.clone()).collect());
|
||||
let findings = validate(candidates, pool, CODE_VOTE_SYS, effective_vote_n(&cfg), &tx).await;
|
||||
let findings = validate(Some(&cfg), candidates, pool, CODE_VOTE_SYS, effective_vote_n(&cfg), &tx).await;
|
||||
finish(cfg, lib, pool, "{}".into(), transcript, findings, agents, &mut rl, crate::grounding::GroundMode::Symbolic, context, tx).await
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user