Skip to content

Synapse WAF Architecture

Synapse is a WAF and reverse proxy built in pure Rust on Cloudflare Pingora. Detection runs inside the proxy — no FFI boundary, no separate processes.

Architecture Comparison

Synapse WAF (Current)

Legacy Architecture

Key difference: 3 components + FFI overhead vs. a single Rust binary with in-process detection.

Request Processing Pipeline

Pingora Integration

Synapse uses Pingora's hook system to intercept requests at different stages:

HookPhasePurpose
early_request_filterPre-TLSRate limiting per client IP
request_filterAfter headersWAF detection (main filter)
request_body_filterAfter bodyDLP body inspection
upstream_peerRoutingRound-robin backend selection
upstream_request_filterPre-upstreamAdd X-Synapse-* headers
loggingPost-responseAccess logs with timing

Shared State Architecture

All worker threads share a single learning state via Arc<RwLock<Synapse>> — a global shared brain.

ComponentBeforeAfter
State storagethread_local! (isolated)Arc<RwLock> (shared globally)
LearningEach thread learns independentlyAll threads contribute to shared knowledge
PersistenceOnly one thread's view savedComplete system state saved
ObservabilityPartial view via Admin APIFull system view via /debug/profiles

All internal stores (StateStore, EntityStore, ProfileStore) use parking_lot::RwLock for high-performance concurrent access. Validated at 200 concurrent VUs with zero lock contention.

Performance optimizations:

  • Lazy rule loading — rules parsed once at startup via once_cell::Lazy
  • Zero-copy headers — header references passed directly to the engine
  • DashMap — lock-free concurrent HashMap for entity/fingerprint tracking
  • LTO — fat link-time optimization in release builds
  • Candidate caching — ~1 μs cache hits for repeated request patterns (95% hit rate)

Module Inventory

ModulePurpose
waf/Core WAF rule engine — 237 rules (SQLi, XSS, path traversal, command injection)
entity/IP/fingerprint tracking with cumulative risk scoring
actor/Behavioral actor fingerprinting and device identification
session/Session tracking, hijack detection
dlp/Data Loss Prevention — credit cards, SSN, IBAN, API keys (22 pattern types)
correlation/Campaign detection across requests and actors
intelligence/Signal intelligence aggregation and management
profiler/Endpoint schema learning and behavioral anomaly detection
crawler/Bot detection, DNS verification, bad bot blocking
geo/GeoIP lookup, impossible travel detection
fingerprint/JA4 TLS fingerprinting
shadow/Shadow traffic mirroring for safe rule testing
tarpit/Progressive delays against malicious actors
telemetry/Signal reporting to Horizon hub
tunnel/Secure WebSocket tunnel client
horizon/Horizon integration and configuration sync
interrogator/CAPTCHA, JS challenge, cookie verification
persistence/State persistence across restarts
trap/Honeypot endpoint detection
ratelimit/Per-IP and per-site rate limiting
tls/TLS termination with SNI support
vhost/Virtual host routing and per-site configuration

Performance Characteristics

OperationLatency
Rate limit check61 ns
ACL evaluation (100 rules)156 ns
Trap matching33 ns
Actor is-blocked check45 ns
Session validation304 ns
Clean GET detection~10 μs
Attack detection (avg)~25 μs
Full pipeline WAF + DLP (4 KB)~247 μs

Comparison

ImplementationDetection LatencyComponentsMemory
Synapse (Pingora)~10–25 μs1 binaryRust only
libsynapse (NAPI)~62–73 μs3 (nginx + Node + NAPI)Node.js + V8 heap
ModSecurity100–500 μsnginx + moduleModerate
AWS WAF50–200 μsCloud serviceN/A

Licensed under AGPL-3.0 · atlascrew.dev