PART 2 · PRODUCTION SYSTEMS · S4

S4 · GraphQL Security, Cost Analysis & AuthZ Propagation

Defeat single-request DoS amplification before execution with O(n) static AST depth, alias, and @cost/@listSize guards, while propagating cryptographically signed zero-trust identity over mTLS across federated subgraphs.

Act I · Security & Cost Physics

Pre-Execution AST Budgets & Zero-Trust Subgraph Perimeters

Act 1 of 5
Static AST Cost Cap
1,000 pts

@cost weights multiplied by @listSize fan-out evaluated pre-execution before touching any subgraph.

O(n) AST Guard
Depth ≤ 8 · Aliases ≤ 15

Single-pass AST validation kills circular fragment depth bombs and 100-alias amplification floods at 0% subgraph CPU.

Zero-Trust Perimeter
mTLS + HMAC Sig

Mutual TLS client certificates plus signed X-Router-Sig headers defeat forged X-Auth-* direct subgraph bypasses.

p99 Guard Overhead
< 0.4 ms

Cached RS256 JWKS verification and compiled @requiresScopes directive checks add sub-millisecond router latency.

Defense-in-Depth Mental Model: Traditional HTTP rate limits fail on GraphQL because 1 HTTP POST can hide 100 aliases or a depth-11 nested loop. Enforcing Safelist → AST Limits → Static Cost → @requiresScopes → mTLS+HMAC stops every attack class before downstream databases ever see a query. 0% Subgraph CPU on Rejected Queries
Act II · Wire & Policy Contracts

Subgraph AuthZ & Cost SDL + Router Zero-Trust Policy

Act 2 of 5
Subgraph AuthZ & Cost SDL (billing.graphql)
Router Security & Zero-Trust Policy (router.yaml)
Act III · Interactive 6-Node Security & AuthZ Pipeline Simulator

Static Cost Guard, @requiresScopes & Zero-Trust mTLS Chaos Lab

200 ALLOWED · ZERO-TRUST
Query Profile:
Caller JWT:
Perimeter:
Static AST Cost 62 / 1,000 pts 6.2% of pre-execution budget
Depth & Aliases Depth 3/8 · Aliases 0/15 O(n) AST limits satisfied
Security Verdict 200 ALLOWED Guard overhead: 0.31 ms
Subgraph CPU Load 4% (Nominal) Protected by pre-exec guards
Security & AuthZ Pipeline · Edge Safelist & AST Guard
PHASE 1 · AST GUARD
Router: JWT & AST Guard RS256 JWKS + O(n) Depth/Alias Validator
AST Cost & @requiresScopes Evaluator 62 / 1,000 pts
Pre-Execution Cost Budget 6.2%
Zero-Trust Wire Envelope Inspector HTTP/2 + mTLS
Chaos Switchboard
0 Active
Live Security Audit Console
Act IV · Auto-Synced Zero-Dependency TypeScript Blueprints

AST Cost Analyzer, @requiresScopes Guard & Zero-Trust HMAC Signer

Live-Injected Simulator State
Act V · Production Stack Mapping, Tradeoffs & Production SLOs

Zero-Trust Ecosystem, Security Tradeoffs & Reliability Targets

Act 5 of 5
Production Stack Mapping
6 Security & AuthZ Primitives
Security Primitive Production Standard Operational Role
Router Policy & Header Signing Apollo Router Rhai / Coprocessor Validates RS256 JWKS, injects X-Auth-Subject/X-Auth-Scopes, and attaches HMAC X-Router-Sig.
Static Complexity & Cost Engine GraphQL Cost Spec (@cost / @listSize) Computes worst-case pre-execution query cost from schema weights and slicing arguments before fan-out.
Fine-Grained ABAC / Policy Engine OPA (Open Policy Agent) / AWS Cedar Evaluates resource-ownership and @policy(policies: [["pii_clearance"]]) rules in sub-millisecond sidecars.
Subgraph Zero-Trust Identity SPIFFE / SPIRE / Istio mTLS Issues short-lived workload certs (spiffe://gleee.in/ns/prod/sa/router) blocking direct subgraph bypasses.
Arbitrary Query Elimination Persisted Query Safelist (PQ) Allows only build-time registered SHA-256 operation IDs in production, shrinking DoS attack surface to zero.
Edge Perimeter & Volumetric Guard Envoy / Cloudflare Edge WAF Enforces IP/tenant token-bucket rate limits, payload size caps, and disables GraphQL introspection at the edge.
Tradeoff 01 DoS Mitigation

Static AST Cost vs. Execution Timeouts

Static AST Cost (@cost/@listSize)

Rejects expensive queries in < 0.4 ms before any subgraph or database connection is touched—0% downstream CPU waste.

Execution Timeouts Only

Zero schema annotation effort, but malicious queries still burn DB locks and CPU for 5–10s until the timeout fires.

Verdict Always pair Static AST Cost caps (primary shield) with per-subgraph timeouts (secondary safety net).
Tradeoff 02 AuthZ Placement

Router @requiresScopes vs. Subgraph ABAC

Router RBAC + Subgraph ABAC

Router blocks missing JWT scopes (read:billing) at the edge in 0.3 ms; Subgraph enforces row-level ownership (invoice.ownerId === sub).

Subgraph-Only AuthZ

Centralizes ownership checks in one place, but forces unnecessary network fan-out to subgraphs for blatantly unauthorized callers.

Verdict Enforce coarse RBAC/scopes at the Router and row-level ABAC inside each subgraph using verified zero-trust headers.
Tradeoff 03 Query Surface

Persisted Safelist vs. Open Public GraphQL

Persisted Safelist (require_id)

Only CI-audited, cost-approved operation hashes execute in prod—completely neutralizing ad-hoc alias and depth bombs.

Open Public GraphQL

Required for external developer APIs (like GitHub/Shopify), but demands strict depth, alias, cost, and per-token cost-bucket throttling.

Verdict Enforce Safelist-Only on all first-party web/mobile clients; expose open GraphQL only on dedicated partner endpoints with strict cost budgets.
Tradeoff 04 AuthZ Failure Mode

Null Field Redaction vs. Fail-Fast 403

Null Field Redaction

Preserves public profile fields while setting unauthorized nullable fields (billing: null) + UNAUTHORIZED_FIELD_OR_TYPE error.

Fail-Fast 403 Reject

Aborts the entire HTTP request immediately before execution—cleanest for security audits and prevents partial timing side-channels.

Verdict Use Null Field Redaction for mixed public/private UI queries and Fail-Fast 403 for sensitive admin or mutation endpoints.
Production Security SLOs
Zero-Trust Enforcement Targets
Unauthorized Field Leaks 0.00% Router @requiresScopes + ABAC
p99 Guard Latency < 0.5 ms Cached JWKS + O(n) AST pass
mTLS Subgraph Coverage 100% SPIFFE certs + X-Router-Sig
Pre-Exec DoS Rejection 100% 0% subgraph CPU on bombs