Storefront GraphQL
Security Architecture
Native Go XcladeGraphQLArmor, AST guards, dynamic CORS, dual-actor RBAC, CSRF protection, and cache isolation
Security Architecture
Security on /graphql and /admin/graphql is enforced directly in compiled Go middleware (graph/middleware/security.go, context.go, and rbac_guard.go).
1. XcladeGraphQLArmor (AST Protection)
Before any resolver executes, ArmorExtension.InterceptOperation walks the parsed AST (including inline fragments and named fragment spreads with cycle protection) and rejects abusive queries immediately:
- Query Depth Guard: Blocks deeply nested queries exceeding
GRAPHQL_MAX_DEPTH(10on/graphql,14on/admin/graphql) withQUERY_DEPTH_EXCEEDED. - Alias Amplification Guard: Caps aliased fields at
15on/graphql(30on/admin/graphql) withALIAS_LIMIT_EXCEEDED. - Directive Flood Guard: Caps total directives at
50on/graphql(75on/admin/graphql) withDIRECTIVE_LIMIT_EXCEEDED. - Production Introspection Guard: Blocks
__schemaand__typefields in production unless the caller is an authenticated Store Admin orGRAPHQL_ALLOW_INTROSPECTION=true.
2. HTTP Guard Middleware
GuardHTTPMiddleware runs ahead of GraphQL parsing on every request:
- Distributed Redis Rate Limiting: Enforces sliding-window quotas keyed by
ActorID(when authenticated) or client IP (when anonymous). Exceeding the cap returns HTTP429withRATE_LIMIT_EXCEEDED. - Payload Size Cap: Wraps
r.Bodywithhttp.MaxBytesReaderand returns HTTP413(QUERY_TOO_LARGE) if exceeded. - Batch Operation Cap: Inspects JSON array batches and rejects arrays exceeding
GRAPHQL_MAX_BATCH(5) withBATCH_LIMIT_EXCEEDED. - CSRF Preflight Guard on
GET: In production (and always on/admin/graphql),GETrequests not acceptingtext/htmlortext/event-streammust include at least one non-simple header (X-Xclade-Request,X-GraphQL-Request,X-Publishable-Api-Key,X-Xclade-Publishable-Key, orApollo-Require-Preflight), otherwise HTTP400(CSRF_PREFLIGHT_REQUIRED) is returned.
3. Actor, Ownership & RBAC Guards
Resolvers enforce strict authorization helpers at every boundary:
| Guard | Enforcement |
|---|---|
RequireAuth | Requires a valid customer or admin token (rejects scoped/purpose tokens such as password-reset tokens). |
RequireCustomer | Restricts mutations to authenticated storefront shoppers / B2B buyers. |
RequireOwnershipOrAdmin | Ensures customers can only view/mutate their own orders, returns, and quotes. |
RequireCompanyAdminOrStoreAdmin | Restricts employee invites, spending limits, and admin cart approvals to B2B Company Admins (Employee.is_admin = true) or Store Admins. |
AdminRBACGuard & @requirePermission | Evaluates fine-grained RBAC role policies on every /admin/graphql operation. |
4. Dynamic Storefront CORS & Cache Isolation
- Dynamic CORS:
/graphqlautomatically allows configured store origins plus verified custom domains attached to the store. - Zero Cross-Tenant or PII Cache Leakage:
XcladeResponseCacherefuses to cache any request containing an authenticated actor, non-allowlisted root fields, or sensitive identifiers (cart_id,company_id,customer_id, orcart_*/comp_*/cus_*values) and forcesCache-Control: private, no-store. - Production Error Masking: Unexpected internal errors are masked to
"an unexpected internal error occurred"withINTERNAL_SERVER_ERRORin production so stack traces and SQL details are never leaked.