Expand description
Framework-agnostic application-layer API security engine.
Rust port of guard-core’s
detection engine. Work in progress: the CPU-bound detection pipeline
is the core, and the first pipeline stage has landed: the rate-limit and
dynamic-ban tower layer for Axum/tonic-shaped stacks. Handlers,
protocols, decorators, and other I/O layers are not yet ported.
Re-exports the detection engine modules:
detection_exclusions- the per-route detection exclusion resolution and the multi-surface request scan (scan_request): excluded headers/params/body fields, enabled detection categories, and the detection scan-body toggle, resolved from the global config and the route config exactly as the reference’s_resolve_*helpers docompiler- regex pattern compilation with LRU caching and ReDoS safety validationdetect- the spec 4.0.2 detection pipeline entry point (detect,detect::DetectConfig,detect::DetectVerdict)preprocessor- unicode NFKC normalization, URL/HTML decoding, null byte removal, whitespace collapsing, and attack-preserving truncationsemantic- token extraction, Shannon entropy, encoding layer detection, attack probability scoring, obfuscation detection, code injection risk analysis, and aggregate threat scoringcloud_provider- the cloud-provider blocking pipeline stage as atower::Layer(403 “Cloud provider IP not allowed”, region carve-outs, skip-state aware)geo- the geo country blocking pipeline stage as atower::Layer(403 “Forbidden”, loopback exemption, whitelist-skip only)tower- the rate-limit and dynamic IP ban pipeline stage as atower::Layer(429 throttled shape, 403 banned shapes, exempt-IP handling, the auto-ban feeds, and passive mode)request_limits- the request size and content-type pipeline stage as atower::Layer(413 size shape, 415 content-type shape, fail-secure 500 on a junk content-length)headers_auth- the required-headers and authentication pipeline stage as atower::Layer(dynamic 400 required-header shapes, fixed 401 authentication shape, route rules with a global verifier fallback)event_types/events- the referenceEVENT_*constants and theSecurityEventBushook seam over the referenceSecurityEventrecordresponses- the referencecustom_error_responsesmap and theon_blockblock hook with the reference payload and exclusion setlogging- the referencelog_activityline shapes with themuted_check_logsandlog_sensitive_*redaction knobsredact- the merged sensitive-name sets and the[REDACTED]redaction the log lines run through
§Usage
use guard_core_rs::preprocessor;
use guard_core_rs::semantic::AttackKeywords;
use guard_core_rs::semantic::AttackStructures;
use guard_core_rs::semantic::{self};
let raw = "<scr\u{200B}ipt>alert(1)</script>";
let clean = preprocessor::preprocess(raw, 10_000, true);
let kw = AttackKeywords::default();
let st = AttackStructures::default();
let result = semantic::analyze(&clean, &kw, &st);
let score = semantic::get_threat_score(&result);
assert!(score > 0.0);Modules§
- cloud_
fetch - The cloud-provider and
GeoIPfetchers: the wire half of the reference cloud lifecycle. - cloud_
provider - The cloud-provider blocking pipeline stage for tower stacks.
- compiler
- composite
- The composite telemetry seam: the
CompositeAgentHandler,OtelHandler, andLogfireHandlerports plus theTelemetryHandlersink trait they fan out over. - custom_
checks - The custom function pipeline stage for tower stacks: the reference
pipeline’s
custom_requestandcustom_validatorschecks. - decorators
- The reference decorator system (
guard_core/decorators/*.py): theSecurityDecoratorregistry and its mixin method surface, ported method for method. - detect
- Public detection entry point: the spec 4.0.2
SusPatternsManager.detectpipeline (preprocess, four scan views, semantic analysis, scoring). - detection_
exclusions - Per-request detection exclusion resolution and the multi-surface request scan.
- dynamic_
rules - The
DynamicRuleManagerport (handlers/dynamic_rule_handler.py+_dynamic_rule_snapshot.py). - emergency_
mode - The emergency-mode pipeline stage for tower stacks.
- enrichment
- The event enrichment layer: the reference
enricher.py(EventEnricher+ThreatScorer) and theENRICHMENT_KEY_*family fromevent_types.py. - event_
types - The reference
EVENT_*constants, byte-identical string values. - events
- The reference event surface: the exact
EVENT_*names and theSecurityEventfields, plus theSecurityEventBushook seam. - geo
- The geo country blocking pipeline stage for tower stacks.
- geo_
lifecycle - The
GeoIPand cloud refresh lifecycles. - headers_
auth - The required-headers and authentication pipeline stage for tower stacks.
- https_
enforcement - The HTTPS enforcement pipeline stage for tower stacks.
- live
- The stages a dynamic rule can change, rebuilt from the live config.
- logging
- The
log_activityport (guard_core/_utils/request_logging.py): the guard log lines with the reference wording, the redaction sets, the per-check log levels, and themuted_check_logsmute list. - metrics
- The reference metrics surface: the exact
METRIC_*names, theSecurityMetrictelemetry record, and theMetricsCollectorthat mirrorsguard_core/core/events/metrics.py. - mmdb
- A minimal, dependency-free
MaxMind MMDBreader. - preprocessor
- Content preprocessing ported from
guard_core/detection_engine/preprocessor.py. - process_
response - The response-side pass, ported from the reference
process_response. - redact
- The log-line redaction port: the reference’s sensitive-name defaults and
the redaction the guard log lines apply (
guard_core/_utils/request_logging.py). - referrer
- The route referrer gate: the reference pipeline’s eighth check.
- request_
limits - The request size and content-type pipeline stage for tower stacks.
- request_
logging - The request-logging pipeline stage: the reference engine’s fourth check, which never blocks.
- responses
- The reference custom-error and block-hook surfaces
(
guard_core/core/responses/factory.pyandguard_core/_utils/block_events.py). - route_
gates - The route-decorator gates for tower stacks: referrer and time window.
- semantic
- stage_
events - The stage event seam: the
on_blockpayload and theSecurityEventBusdispatch the guard stages fire on their blocks, so the observable stream matches spec 12. - sus_
patterns - The custom suspicious-pattern registry - the Rust family’s equivalent of the Python engine’s custom-pattern half.
- time_
window - The route time-window gate: the reference pipeline’s tenth check.
- tower
- The rate-limit and dynamic-ban pipeline stage for tower stacks: one
tower::Layerthat Axum, tonic, and anytower::Serviceconsumer install around their inner service. - user_
agent - The blocked user-agent pipeline stage for tower stacks.
- wiring
- The one
SecurityConfigto pipeline mapping the adapters share.