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/configuration.md
1# Configuration23## Schema Validation 2.0 Setup45> ⚠️ **Classic Schema Validation deprecated.** Use Schema Validation 2.0.67**Upload schema (Dashboard):**8```9Security > API Shield > Schema Validation > Add validation10- Upload .yml/.yaml/.json (OpenAPI v3.0)11- Endpoints auto-added to Endpoint Management12- Action: Log | Block | None13- Body inspection: JSON payloads14```1516**Change validation action:**17```18Security > API Shield > Settings > Schema Validation19Per-endpoint: Filter → ellipses → Change action20Default action: Set global mitigation action21```2223**Migration from Classic:**24```251. Export existing schema (if available)262. Delete all Classic schema validation rules273. Wait 5 min for cache clear284. Re-upload via Schema Validation 2.0 interface295. Verify in Security > Events30```3132**Fallthrough rule** (catch-all unknown endpoints):33```34Security > API Shield > Settings > Fallthrough > Use Template35- Select hostnames36- Create rule with cf.api_gateway.fallthrough_triggered37- Action: Log (discover) or Block (strict)38```3940**Body inspection:** Supports `application/json`, `*/*`, `application/*`. Disable origin MIME sniffing to prevent bypasses.4142## JWT Validation4344**Setup token config:**45```46Security > API Shield > Settings > JWT Settings > Add configuration47- Name: "Auth0 JWT Config"48- Location: Header/Cookie + name (e.g., "Authorization")49- JWKS: Paste public keys from IdP50```5152**Create validation rule:**53```54Security > API Shield > API Rules > Add rule55- Hostname: api.example.com56- Deselect endpoints to ignore57- Token config: Select config58- Enforce presence: Ignore or Mark as non-compliant59- Action: Log/Block/Challenge60```6162**Rate limit by JWT claim:**63```wirefilter64lookup_json_string(http.request.jwt.claims["{config_id}"][0], "sub")65```6667**Special cases:**68- Two JWTs, different IdPs: Create 2 configs, select both, "Validate all"69- IdP migration: 2 configs + 2 rules, adjust actions per state70- Bearer prefix: API Shield handles with/without71- Nested claims: Dot notation `user.email`7273## Mutual TLS (mTLS)7475**Setup:**76```77SSL/TLS > Client Certificates > Create Certificate78- Generate CF-managed CA (all plans)79- Upload custom CA (Enterprise, max 5)80```8182**Configure mTLS rule:**83```84Security > API Shield > mTLS85- Select hostname(s)86- Choose certificate(s)87- Action: Block/Log/Challenge88```8990**Test:**91```bash92openssl req -x509 -newkey rsa:4096 -keyout client-key.pem -out client-cert.pem -days 36593curl https://api.example.com/endpoint --cert client-cert.pem --key client-key.pem94```9596## Session Identifiers9798Critical for BOLA Detection, Sequence Mitigation, and analytics. Configure header/cookie that uniquely IDs API users.99100**Examples:** JWT sub claim, session token, API key, custom user ID header101102**Configure:**103```104Security > API Shield > Settings > Session Identifiers105- Type: Header/Cookie106- Name: "X-User-ID" or "Authorization"107```108109## BOLA Detection110111Detects Broken Object Level Authorization attacks (enumeration + parameter pollution).112113**Enable:**114```115Security > API Shield > Schema Validation > [Select Schema] > BOLA Detection116- Enable detection117- Threshold: Sensitivity level (Low/Medium/High)118- Action: Log or Block119```120121**Requirements:**122- Schema Validation 2.0 enabled123- Session identifiers configured124- Minimum traffic: 1000+ requests/day per endpoint125126## Authentication Posture127128Identifies unprotected or inconsistently protected endpoints.129130**View report:**131```132Security > API Shield > Authentication Posture133- Shows endpoints lacking JWT/mTLS134- Highlights mixed authentication patterns135```136137**Remediate:**1381. Review flagged endpoints1392. Add JWT validation rules1403. Configure mTLS for sensitive endpoints1414. Monitor posture score142143## Volumetric Abuse + GraphQL144145**Volumetric Abuse Detection:**146`Security > API Shield > Settings > Volumetric Abuse Detection`147- Enable per-endpoint monitoring, set thresholds, action: Log | Challenge | Block148149**GraphQL Protection:**150`Security > API Shield > Settings > GraphQL Protection`151- Max query depth: 10, max size: 100KB, block introspection (production)152153## Terraform154155```hcl156# Session identifier157resource "cloudflare_api_shield" "main" {158zone_id = var.zone_id159auth_id_characteristics {160type = "header"161name = "Authorization"162}163}164165# Add endpoint166resource "cloudflare_api_shield_operation" "users_get" {167zone_id = var.zone_id168method = "GET"169host = "api.example.com"170endpoint = "/api/users/{id}"171}172173# JWT validation rule174resource "cloudflare_ruleset" "jwt_validation" {175zone_id = var.zone_id176name = "API JWT Validation"177kind = "zone"178phase = "http_request_firewall_custom"179180rules {181action = "block"182expression = "(http.host eq \"api.example.com\" and not is_jwt_valid(http.request.jwt.payload[\"{config_id}\"][0]))"183description = "Block invalid JWTs"184}185}186```187188## See Also189190- [api.md](api.md) - API endpoints and Workers integration191- [patterns.md](patterns.md) - Firewall rules and deployment patterns192- [gotchas.md](gotchas.md) - Troubleshooting and limits193