Expand description
Tower HTTP adapter for the portable path denylist in towershield_core.
ShieldLayer compiles a RuleSet once and wraps any Tower
Service. On each request ShieldService
builds an towershield_core::InspectionPath from uri.path(), evaluates
the compiled rules, and either forwards the request unchanged or returns
a generic empty blocked response without polling the inner service.
§Domain map
| Concept | Types |
|---|---|
| Layer configuration | ShieldBuilder, BlockedResponse, OnBlock |
| Middleware | ShieldLayer, ShieldService |
| Rule authoring (re-exported) | Rule, RuleSet, PathMatcher, DEFAULT_RULES |
| Decision surface (re-exported) | ShieldDecision, ShieldMatch, CompiledRuleSet |
Rule compilation errors surface as towershield_core::ruleset::CompileError
from ShieldBuilder::try_build. Prefer that at process startup when
rules come from external config; ShieldBuilder::build panics on failure.
§Placement (critical for Axum)
Wrap the complete axum::Router with Layer::layer so the shield runs
before route matching. router.layer(ShieldLayer::…) runs after
matching, so unmatched scanner probes never hit the denylist.
use tower::Layer;
use towershield::ShieldLayer;
// let app = ShieldLayer::default().layer(router);§Middleware ordering
Keep the shield outermost (applied last → runs first):
ShieldLayer ← reject probes before the rest of the stack
TracingLayer
RequestBodyLimitLayer
AuthLayer
Routerlet app = ServiceBuilder::new()
.layer(ShieldLayer::default())
.service(router);Core rule types are re-exported so application crates can depend only on
towershield for common configuration. Offline Cloudflare export lives in
the separate towershield-cloudflare crate and does not run on the request path.
§Features
| Feature | Effect |
|---|---|
tracing (default) | Emit a debug log line on each block |
regex (default) | Regex matchers and the broader built-in rule tier |
rayon | Forwarded to towershield-core for parallel rule compile |
Structs§
- Blocked
Response - Client-facing response shape for blocked scanner probes.
- Compiled
Rule Set - Startup-compiled rules ready for per-request evaluation.
- Rule
- One declarative path rule: identity, disposition, matcher, and flags.
- RuleId
- Stable, opaque rule identifier suitable for metrics and export reports.
- Rule
Schema Version - Schema version embedded in serialised rule files.
- RuleSet
- Versioned, ordered collection of declarative
Rulevalues. - Shield
Builder - Fluent configuration for a
ShieldLayerbefore rule compilation. - Shield
Layer - Tower
Layerthat evaluates the path denylist before the inner service. - Shield
Match - Identity of the deny rule that produced a
ShieldDecision::Block. - Shield
Service - Tower
Servicethat evaluates path rules, then either blocks or forwards.
Enums§
- Case
Sensitivity - Per-rule case-handling policy applied during compile and evaluate.
- Match
Kind - Discriminant of a
PathMatcherwithout the pattern payload. - Path
Matcher - How a rule compares against the decoded inspection path.
- Rule
Disposition - Whether a matching path is blocked or explicitly permitted.
- Rule
Group - Logical category for filtering, metrics labels, and export organisation.
- Shield
Decision - Outcome of evaluating an inspection path against a
CompiledRuleSet.
Statics§
- DEFAULT_
RULES - Process-wide handle for the built-in scanner-probe denylist.
Type Aliases§
- OnBlock
- Observability hook invoked after a path is blocked, before the response is returned.