Expand description
Per-request detection exclusion resolution and the multi-surface request scan.
The Rust port of guard_core/_utils/detection_config.py (via the Go
port’s detectionexclusions.go / headerexclusions.go and the pipeline
detectThreat). Every route surface overrides the global config when the route carries a
non-None value (the Python sentinel is None), and the header
exclusion set is additive - the hardcoded defaults merge with the config
set and the route set (_resolve_excluded_headers), while the param,
body-field, and enabled-category sets replace (_resolve_excluded_params
and friends). Matching is case-insensitive: the resolved sets are
lowercased at resolution time.
An excluded surface is not skipped outright in every case: excluded
headers whose values are known to false-positive a category (the ssrf
category for address-carrying proxy headers and for address-chain
values) still scan with every other enabled category, so an attack
payload smuggled into an excluded header still detects
(_excluded_header_skip_categories).
§Example
use guard_core_engine::detection_exclusions::{
resolve, DetectionExclusionConfig, RouteDetectionExclusions,
};
use std::collections::HashSet;
// The global config excludes two params; the route replaces the set.
let global = DetectionExclusionConfig {
excluded_detection_params: vec!["debug".to_owned(), "Trace".to_owned()],
..DetectionExclusionConfig::default()
};
let route = RouteDetectionExclusions {
excluded_detection_params: Some(vec!["session".to_owned()]),
..RouteDetectionExclusions::default()
};
let resolved = resolve(Some(&global), Some(&route));
assert!(resolved.excluded_params.contains("session"));
assert!(
!resolved.excluded_params.contains("debug") && !resolved.excluded_params.contains("trace"),
"a non-None route set replaces the global one"
);
// The sets are lowercased at resolution time: the global config's
// mixed-case "Trace" entry resolves to "trace" when no route replaces it.
let inherited = resolve(Some(&global), None);
assert!(inherited.excluded_params.contains("trace"));
// The header set always merges the hardcoded proxy defaults.
assert!(resolved.excluded_headers.contains("x-forwarded-for"));
// Unset route surfaces keep the global resolution; unset everywhere
// means every category scans and the body surface scans.
assert!(resolved.enabled_categories.is_none());
assert!(resolved.scan_body);Structs§
- Detection
Exclusion Config - The global config’s detection-exclusion surface.
- Request
Scan Verdict - The multi-surface verdict (
detectThreat’s return shape). - Request
Surfaces - The request surfaces one scan pass covers (the
detectThreatinput shape). Headers and query params are(name, value)pairs; body values are thecrate::body_scanextraction’s output. - Resolved
Exclusions - The resolved exclusion sets for one request (
routeDetectionExclusionsin the Go port). - Route
Detection Exclusions - The route decorator’s detection-exclusion surface.
Constants§
- DEFAULT_
EXCLUDED_ HEADERS - The hardcoded header exclusion defaults (
_DEFAULT_EXCLUDED_HEADERS).
Functions§
- check_
applies - The check-set liveness semantics (
SuspiciousActivityCheck.applies_to). - detection_
enabled - The route toggle’s request-time semantics.
- excluded_
header_ skip_ categories - The categories an excluded header skips for one value
(
_excluded_header_skip_categories). - resolve
_resolve_*: every route surface overrides the global config when the route carries a non-Nonevalue, except the header set which merges defaults + config + route.- scan_
request - The multi-surface scan (
detectThreat). - strip_
forwarded_ entry_ port - Remove the port from a forwarded-list entry
(
_strip_forwarded_entry_port). - value_
looks_ like_ address_ chain - Address-chain detection (
_value_looks_like_address_chain).