Prompt
I need a way to detect shadow APIs and block attacks in production
Latest observation
To detect shadow APIs and block attacks in production, you need two layers working together:
- Discovery: find APIs you didn’t know were exposed
- Protection: inspect and control traffic to stop abuse in real time
Here’s a practical approach.
1) Detect shadow APIs
A. Build an API inventory from traffic
Monitor all inbound and internal traffic to identify endpoints actually being used.
Look for:
- Unknown paths not in your API gateway / OpenAPI specs
- Deprecated endpoints still receiving traffic
- Internal services exposed externally
- Unauthenticated endpoints
- Hidden versions like
/v1beta,/test,/debug,/admin
Useful sources:
- API gateway logs
- Reverse proxy logs
- WAF logs
- Service mesh telemetry
- Cloud load balancer access logs
- CDN logs
- DNS logs
- eBPF / network flow logs
B. Compare observed traffic to known specs
Continuously diff:
- Observed endpoints vs OpenAPI/Swagger specs
- Observed methods vs allowed methods
- Observed schemas vs expected payloads
- Client identities vs approved consumers
Anything outside the spec is suspicious and may indicate:
- Shadow API
- Forgotten environment
- Misconfiguration
- Attack reconnaissance
C. Scan your external surface
Run scheduled discovery against your public ranges and domains:
- Port scanning for exposed app ports
- HTTP path fuzzing for common API routes
- Certificate/domain enumeration
- Subdomain discovery
- Cloud asset inventory checks
D. Detect API-specific anomalies
Alert on:
- Unusual spikes in 404/401/403
- Enumeration patterns
- High-rate requests across many IDs
- Access to admin or debug routes
- Odd user agents or missing auth headers
- Requests from unfamiliar geographies / ASNs
- Breaks from normal sequence of API calls
2) Block attacks in production
A. Put an API gateway or edge proxy in front
Use it to enforce:
- Authentication
- Authorization
- Rate limiting
- Schema validation
- IP allow/deny rules
- JWT validation
- mTLS for service-to-service traffic
Good controls:
- Reject unknown paths unless explicitly allowed
- Block unsupported methods
- Enforce content types
- Enforce request size limits
- Require auth on all sensitive endpoints
B. Add WAF/API protection rules
Create rules for common API attacks:
- SQL injection
- SSRF
- XSS in JSON fields
- Path traversal
- Mass assignment attempts
- Parameter pollution
- Broken object-level authorization probes
- Brute force and credential stuffing
C. Use behavioral detection
Block or challenge requests that show:
- Rapid ID enumeration
- Sequential object access patterns
- Abnormal request frequency
- Bot-like behavior
- Invalid token reuse
- Failed auth bursts
- High error rates from one client
D. Enforce least privilege
Reduce blast radius by:
- Per-route authorization
- Per-client scopes
- Tenant isolation
- Object-level access checks
- Separate admin APIs from public APIs
- Network segmentation for internal APIs
E. Fail closed for unknown APIs
If an endpoint isn’t in your allowlist or API registry:
- Return 404/403
- Log it
- Alert security
- Optionally block at edge for repeated attempts
3) Recommended architecture
A strong production setup looks like this:
Internet / Clients
→ CDN / DDoS protection
→ WAF / API security layer
→ API Gateway / Reverse proxy
→ Application services
→ Central logging + SIEM + SOAR
And for discovery:
- Traffic analysis + spec diffing
- Cloud asset inventory
- Periodic attack surface scanning
- Runtime anomaly detection
4) Immediate action plan
If you need something fast:
In the next 24 hours
- Export all public endpoints from gateway/proxy logs
- Compare against OpenAPI specs
- Block unknown admin/debug paths
- Add rate limits to auth and object-access endpoints
- Turn on alerting for 401/403/404 spikes
- Review external-facing DNS and cloud load balancers
In the next 1–2 weeks
- Deploy API gateway enforcement
- Add schema validation
- Add token-based auth and scope checks
- Build an endpoint inventory pipeline
- Add anomaly detection rules
- Separate public and internal APIs
Longer term
- Maintain a live API catalog
- Integrate service discovery with CI/CD
- Auto-diff spec vs runtime traffic
- Add continuous exposure monitoring
- Run regular red-team/API security tests
5) Tools you can use
Examples of categories:
- API gateways: Kong, Apigee, AWS API Gateway, Azure API Management, NGINX
- WAF / edge security: Cloudflare, Akamai, Fastly, AWS WAF
- Runtime visibility: Datadog, Dynatrace, New Relic, eBPF-based tooling
- SIEM: Splunk, Sentinel, Chronicle
- Attack surface discovery: cloud inventory tools, external scanners, ASM platforms
- API security platforms: tools that specialize in API discovery, schema drift, and abuse detection
6) What to block first
Prioritize blocking:
- Unauthenticated sensitive endpoints
- Admin/debug/test routes
- Unknown endpoints with repeated hits
- Brute-force login/API key attempts
- Object enumeration behavior
- Requests violating schema or method expectations
If you want, I can help you design a concrete detection and blocking workflow for your environment, for example:
- AWS
- Kubernetes
- Nginx/Kong
- Cloudflare
- Splunk/Sentinel
- OpenAPI-based API inventory