This framework is designed with a three-layer structure: "Policy → Compile → Runtime".
flowchart LR
U[User]
CDN[CDN Edge]
SEC[Edge Security Layer]
WAF[AWS WAF / CF Security]
ORI[Origin / App]
U --> CDN
CDN --> SEC
SEC -->|block| U
SEC -->|allow| WAF
WAF -->|block| U
WAF -->|allow| ORI
ORI --> CDN --> U
Target:
- CloudFront Functions
- Cloudflare Workers
Responsibilities:
- Coarse inspection of Method / Path / User-Agent
- Query normalization and removal
- Early blocking (403/400)
- Security header injection
Characteristics:
- Ultra-low latency
- Stateless
Target:
- AWS WAF
- Cloudflare WAF
Responsibilities:
- Rate limiting
- OWASP Managed Rules
- Bot / CAPTCHA
- Body inspection
Characteristics:
- Stateful
- High precision
Responsibilities:
- Authentication / Authorization
- Business logic
- Data integrity
Maintain the premise that "even if Edge fails, the App remains the last line of defense"
flowchart TB
P[Security Policy
(YAML)] --> C[Compiler]
C --> CF[CloudFront Functions]
C --> LE[Lambda@Edge]
C --> CW[Cloudflare Workers]
- Human-reviewable
- Diffs visible in PRs
- CDN-agnostic
| Concept | CloudFront Functions | Lambda@Edge | Cloudflare Workers |
|---|---|---|---|
| Entry blocking | Viewer Request | Origin Request | fetch() |
| Header injection | Viewer Response | Origin Response | Response headers |
| Advanced validation | Not supported | Supported | Supported |
| State management | Not supported | Partially | KV / DO |
- Fail Fast – Block early
- Least Privilege – Deny by default
- Defense in Depth – Edge + WAF + App
- Portable Security – CDN-independent
- Relying on Edge alone for all protection
- Overlapping WAF rules and Functions
- Tightening CSP abruptly
- Proliferation of exception rules
- Global distribution
- API + admin UI
- Multi-tenant
- OSS / template distribution
- Organize threats in threat-model.md
- Use decision-matrix.md for Edge / WAF decisions
- Keep policy and runtimes in sync: policy-runtime-sync.md
- Observability: observability.md for logging and metrics
- CI quality gate (policy lint + build + runtime + unit + drift + security-baseline):
.github/workflows/policy-lint.yml