Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/api-shield/patterns.md
1# Patterns & Use Cases23## Protect API with Schema + JWT45```bash6# 1. Upload OpenAPI schema7POST /zones/{zone_id}/api_gateway/user_schemas89# 2. Configure JWT validation10POST /zones/{zone_id}/api_gateway/token_validation11{12"name": "Auth0",13"location": {"header": "Authorization"},14"jwks": "{...}"15}1617# 3. Create JWT rule18POST /zones/{zone_id}/api_gateway/jwt_validation_rules1920# 4. Set schema validation action21PUT /zones/{zone_id}/api_gateway/settings/schema_validation22{"validation_default_mitigation_action": "block"}23```2425## Progressive Rollout2627```281. Log mode: Observe false positives29- Schema: Action = Log30- JWT: Action = Log31322. Block subset: Protect critical endpoints33- Change specific endpoint actions to Block34- Monitor firewall events35363. Full enforcement: Block all violations37- Change default action to Block38- Handle fallthrough with custom rule39```4041## BOLA Detection4243### Enumeration Detection44Detects sequential resource access (e.g., `/users/1`, `/users/2`, `/users/3`).4546```javascript47// Block BOLA enumeration attempts48(cf.api_gateway.cf-risk-bola-enumeration and http.host eq "api.example.com")49// Action: Block or Challenge50```5152### Parameter Pollution53Detects duplicate/excessive parameters in requests.5455```javascript56// Block parameter pollution57(cf.api_gateway.cf-risk-bola-pollution and http.host eq "api.example.com")58// Action: Block59```6061### Combined BOLA Protection62```javascript63// Comprehensive BOLA rule64(cf.api_gateway.cf-risk-bola-enumeration or cf.api_gateway.cf-risk-bola-pollution)65and http.host eq "api.example.com"66// Action: Block67```6869## Authentication Posture7071### Detect Missing Auth72```javascript73// Log endpoints lacking authentication74(cf.api_gateway.cf-risk-missing-auth and http.host eq "api.example.com")75// Action: Log (for audit)76```7778### Detect Mixed Auth79```javascript80// Alert on inconsistent auth patterns81(cf.api_gateway.cf-risk-mixed-auth and http.host eq "api.example.com")82// Action: Log (review required)83```8485## Fallthrough Detection (Shadow APIs)8687```javascript88// WAF Custom Rule89(cf.api_gateway.fallthrough_triggered and http.host eq "api.example.com")90// Action: Log (discover unknown) or Block (strict)91```9293## Rate Limiting by User9495```javascript96// Rate Limiting Rule (modern syntax)97(http.host eq "api.example.com" and98is_jwt_valid(http.request.jwt.payload["{config_id}"][0]))99100// Rate: 100 req/60s101// Counting expression: lookup_json_string(http.request.jwt.payload["{config_id}"][0], "sub")102```103104## Volumetric Abuse Response105106```javascript107// Detect abnormal traffic spikes108(cf.api_gateway.volumetric_abuse_detected and http.host eq "api.example.com")109// Action: Challenge or Rate Limit110111// Combined with rate limiting112(cf.api_gateway.volumetric_abuse_detected or113cf.threat_score gt 50) and http.host eq "api.example.com"114// Action: JS Challenge115```116117## GraphQL Protection118119```javascript120// Block oversized queries121(http.request.uri.path eq "/graphql" and122cf.api_gateway.graphql_query_size gt 100000)123// Action: Block124125// Block deep nested queries126(http.request.uri.path eq "/graphql" and127cf.api_gateway.graphql_query_depth gt 10)128// Action: Block129```130131## Architecture Patterns132133**Public API:** Discovery + Schema Validation 2.0 + JWT + Rate Limiting + Bot Management134**Partner API:** mTLS + Schema Validation + Sequence Mitigation135**Internal API:** Discovery + Schema Learning + Auth Posture136137## OWASP API Security Top 10 Mapping (2026)138139| OWASP Issue | API Shield Solutions |140|-------------|---------------------|141| API1:2023 Broken Object Level Authorization | **BOLA Detection** (enumeration + pollution), Sequence mitigation, Schema, JWT, Rate Limiting |142| API2:2023 Broken Authentication | **Auth Posture**, mTLS, JWT validation, Bot Management |143| API3:2023 Broken Object Property Auth | Schema validation, JWT validation |144| API4:2023 Unrestricted Resource Access | Rate Limiting, **Volumetric Abuse Detection**, **GraphQL Protection**, Bot Management |145| API5:2023 Broken Function Level Auth | Schema validation, JWT validation, Auth Posture |146| API6:2023 Unrestricted Business Flows | Sequence mitigation, Bot Management |147| API7:2023 SSRF | Schema validation, WAF managed rules |148| API8:2023 Security Misconfiguration | **Schema Validation 2.0**, Auth Posture, WAF rules |149| API9:2023 Improper Inventory Management | **API Discovery**, Schema learning, Auth Posture |150| API10:2023 Unsafe API Consumption | JWT validation, Schema validation, WAF managed |151152## Monitoring153154**Security Events:** `Security > Events` → Filter: Action = block, Service = API Shield155**Firewall Analytics:** `Analytics > Security` → Filter by `cf.api_gateway.*` fields156**Logpush fields:** APIGatewayAuthIDPresent, APIGatewayRequestViolatesSchema, APIGatewayFallthroughDetected, JWTValidationResult157158## Availability (2026)159160| Feature | Availability | Notes |161|---------|-------------|-------|162| mTLS (CF-managed CA) | All plans | Self-service |163| Endpoint Management | All plans | Limited operations |164| Schema Validation 2.0 | All plans | Limited operations |165| API Discovery | Enterprise | 10K+ ops |166| JWT Validation | Enterprise add-on | Full validation |167| BOLA Detection | Enterprise add-on | Requires session IDs |168| Auth Posture | Enterprise add-on | Security audit |169| Volumetric Abuse Detection | Enterprise add-on | Traffic analysis |170| GraphQL Protection | Enterprise add-on | Query limits |171| Sequence Mitigation | Enterprise (beta) | Contact team |172| Full Suite | Enterprise add-on | All features |173174**Enterprise limits:** 10K operations (contact for higher). Preview access available for non-contract evaluation.175176## See Also177178- [configuration.md](configuration.md) - Setup all features before creating rules179- [api.md](api.md) - Firewall field reference and API endpoints180- [gotchas.md](gotchas.md) - Common issues and limits181