← back to demos

~/api-shield-demo

// Discovery · Schema Validation · Sensitive Data Detection — one fake e-commerce API

// API Shield runs at Cloudflare's edge before this Worker ever sees the request

One API. Three layers of protection. Zero origin code changes.

01 · DiscoveryFind shadow APIs you didn't know were exposed.
02 · Schema ValidationReject requests that don't match your OpenAPI spec.
03 · Sensitive DataStop PII / secrets leaking out of responses.
pillar 01
Endpoint Discovery

Cloudflare watches every request and learns your API surface automatically. Endpoints you forgot, internal tools that leaked to production, old versions still answering — all surfaced in Endpoint Management within minutes.

// fake e-commerce API on apishield.nobledemos.com4 documented · 4 shadow

Endpoint
In OpenAPI spec?
What API Shield does
Try it
GET /api/v1/products
documented
listed in Endpoint Management
GET /api/v1/products/sku_001
documented
listed (path-templated)
POST /api/v1/orders
documented
listed
GET /api/v1/users/me
documented
listed
GET /api/v1/internal/debug
shadow
flagged: internal endpoint exposed
GET /api/v1/admin/users/dump
shadow
flagged: admin path · returns PII
GET /api/v0/legacy/checkout
shadow
flagged: old version still live
GET /api/v1/_health/full
shadow
flagged: verbose health · leaks infra

// Every endpoint above returns 200 OK from the Worker — Discovery's job is to tell you they exist, not block them. Pillars 02 and 03 add the enforcement.

▸ How to verify in the dashboard

Run a few curls above (or just refresh this page a couple of times — every link counts as traffic). Then open Security › API Shield › Endpoint Management in the Cloudflare dashboard for nobledemos.com.

Within ~5 minutes, every endpoint you hit appears in the list. Endpoints not in your uploaded OpenAPI schema are tagged as shadow and surfaced for review. You can then save them to the schema, label them internal, or block them outright with a Custom Rule.

Note: Discovery uses ML to template paths like /products/sku_001/products/{id} automatically.

pillar 02
Schema Validation

The OpenAPI spec you already maintain becomes an edge-enforced firewall. Cloudflare blocks any request whose body, headers, or query don't match — missing fields, wrong types, extra fields (mass-assignment), out-of-range values — before they reach your origin. Zero code changes.

// rule active: POST /api/v1/orders · validated against CreateOrderRequest · action block

Scenario
Payload
What CF does
Try it
Valid order
{"productId":"sku_001","qty":2}
201 createdpasses — reaches Worker
Missing required field
{"qty":2}
blockmissing productId
Wrong type
{"productId":"sku_001","qty":"two"}
blockqty must be integer
Mass-assignment
{"productId":"sku_001","qty":2,"isAdmin":true}
blockextra field — OWASP API #6
Out-of-range value
{"productId":"sku_001","qty":9999}
blockqty > 100
Bad pattern
{"productId":"<script>","qty":2}
blockproductId regex fail

// Blocks return Cloudflare's API Shield error response (HTTP 403). The Worker never sees these requests — schema mismatches are enforced at the edge.

▸ How to set this up in the dashboard

1. Upload the schema: Security › API Shield › Schema Validation › Add validation. Use the file apps/api-shield/openapi.yaml from this repo.

2. When prompted, set the default action to Block (or Log first if you want to dry-run). Apply to operation POST /api/v1/orders.

3. Save. Run the curls above — invalid bodies return 403, valid ones return 201 from the Worker.

// Validation includes path params, query strings, headers, and request body. additionalProperties: false on the schema is what makes mass-assignment attacks fail.

pillar 03
Sensitive Data Detection

Even with discovery and validation in place, the worst leaks happen on the way out — a misconfigured endpoint that returns full credit cards, an internal tool that leaks an AWS key. Cloudflare scans response bodies at the edge and flags (or blocks) them before they reach the client.

// SDD active on apishield.nobledemos.com · detectors: Financial · PII (US) · Secrets

Endpoint
What it leaks
What CF detects
Try it
GET /api/v1/users/me/wallet
2× test cards · SSN
flaggedVisa · Mastercard · US SSN
GET /api/v1/integrations/keys
AWS keys · JWT · GitHub PAT
flagged3× secret patterns
GET /api/v1/users/me
name · email only
cleanno SDD match

// All values returned are publicly-known test fixtures (Stripe test cards, IRS demo SSN, AWS docs example keys) — no real PII / secrets.

▸ How to set this up in the dashboard

1. Open Security › Sensitive Data on nobledemos.com. Cloudflare ships a Managed Ruleset called Cloudflare Sensitive Data Detection with detectors for credit cards, US/EU PII, and common secret patterns.

2. Enable the ruleset and set the action — Log first to see what fires, then flip to Block once you've reviewed the matches.

3. Optional: in Security › API Shield › Endpoint Management, the two leaky endpoints will be tagged "contains sensitive data" after a few requests — making it obvious which APIs need attention.

// SDD inspects response bodies; the Worker still emits the raw payload, but Cloudflare rewrites it (or blocks the response) at the edge based on your action setting.