xcladeDocs
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 (10 on /graphql, 14 on /admin/graphql) with QUERY_DEPTH_EXCEEDED.
  • Alias Amplification Guard: Caps aliased fields at 15 on /graphql (30 on /admin/graphql) with ALIAS_LIMIT_EXCEEDED.
  • Directive Flood Guard: Caps total directives at 50 on /graphql (75 on /admin/graphql) with DIRECTIVE_LIMIT_EXCEEDED.
  • Production Introspection Guard: Blocks __schema and __type fields in production unless the caller is an authenticated Store Admin or GRAPHQL_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 HTTP 429 with RATE_LIMIT_EXCEEDED.
  • Payload Size Cap: Wraps r.Body with http.MaxBytesReader and returns HTTP 413 (QUERY_TOO_LARGE) if exceeded.
  • Batch Operation Cap: Inspects JSON array batches and rejects arrays exceeding GRAPHQL_MAX_BATCH (5) with BATCH_LIMIT_EXCEEDED.
  • CSRF Preflight Guard on GET: In production (and always on /admin/graphql), GET requests not accepting text/html or text/event-stream must include at least one non-simple header (X-Xclade-Request, X-GraphQL-Request, X-Publishable-Api-Key, X-Xclade-Publishable-Key, or Apollo-Require-Preflight), otherwise HTTP 400 (CSRF_PREFLIGHT_REQUIRED) is returned.

3. Actor, Ownership & RBAC Guards

Resolvers enforce strict authorization helpers at every boundary:

GuardEnforcement
RequireAuthRequires a valid customer or admin token (rejects scoped/purpose tokens such as password-reset tokens).
RequireCustomerRestricts mutations to authenticated storefront shoppers / B2B buyers.
RequireOwnershipOrAdminEnsures customers can only view/mutate their own orders, returns, and quotes.
RequireCompanyAdminOrStoreAdminRestricts employee invites, spending limits, and admin cart approvals to B2B Company Admins (Employee.is_admin = true) or Store Admins.
AdminRBACGuard & @requirePermissionEvaluates fine-grained RBAC role policies on every /admin/graphql operation.

4. Dynamic Storefront CORS & Cache Isolation

  • Dynamic CORS: /graphql automatically allows configured store origins plus verified custom domains attached to the store.
  • Zero Cross-Tenant or PII Cache Leakage: XcladeResponseCache refuses to cache any request containing an authenticated actor, non-allowlisted root fields, or sensitive identifiers (cart_id, company_id, customer_id, or cart_* / comp_* / cus_* values) and forces Cache-Control: private, no-store.
  • Production Error Masking: Unexpected internal errors are masked to "an unexpected internal error occurred" with INTERNAL_SERVER_ERROR in production so stack traces and SQL details are never leaked.

On this page