Magento
Astro CORS
A decoupled (Astro) storefront calls Magento’s GraphQL and REST APIs cross-origin — which the browser blocks unless Magento returns the right CORS headers. Astro CORS adds those headers correctly and safely: a configurable origin allow-list per API, spec-safe wildcard/credentials handling, fast preflight responses, and an optional redirect that points the backend’s leftover Luma pages at your real storefront.

Compatibility
Section titled “Compatibility”PHP
Scope
Security
What it does
Section titled “What it does”-
Allow-list your storefront origins for GraphQL and REST separately.
-
On every API response from an allowed origin, it sets
Access-Control-Allow-Origin(the exact origin, echoed back),Vary: Origin, and — when enabled and safe —Access-Control-Allow-Credentials. -
OPTIONS preflights are short-circuited at app launch: the request never runs the full router, it just gets the
Allow-Methods/Allow-Headers/Max-Ageheaders back immediately. -
(Optional) Headless redirect: browseable Luma pages on the Magento host are redirected to your storefront URL, while
/graphql, REST, the admin and/media+/staticstay put.
Configuration
Section titled “Configuration”Stores → Configuration → AgenticEcom · Headless & Astro → Astro CORS
Each API has its own policy:
| Field | What it does |
|---|---|
| Allowed Origins | Comma-separated origins (https://store.example.com), or * for any. |
| Allowed Methods | e.g. GET, POST, OPTIONS. |
| Allowed Headers | e.g. Content-Type, Authorization, Store. |
| Allow Credentials | Send Allow-Credentials: true (ignored for the * origin). |
| Max Age | Preflight cache lifetime in seconds (e.g. 86400). |
| Exposed Headers | Response headers the browser may read. |
| Field | What it does |
|---|---|
| Enable Headless Redirect | Redirect the backend’s Luma pages to your storefront. |
| Storefront URL | Absolute base URL of your decoupled storefront. |
| Redirect Type | 301 (recommended) or 302. |
| Allowed Front Names | Path segments that must keep working on the backend (e.g. sociallogin, payment return URLs). |
My preflight passes but the real request is still blocked — why?
For CORS to work, both the OPTIONS preflight and the actual GraphQL/REST response need
Access-Control-Allow-Origin. This module sets it on both — for the actual response too, not
just the preflight — so an allow-listed origin gets a usable response.
Can I allow any origin?
Yes, set Allowed Origins to *. Note that credentials are then disabled (per the CORS
spec). If your storefront sends cookies/credentials, list its exact origin instead.
Will it break the admin or media files?
No. The optional headless redirect only affects browseable storefront pages — /graphql, REST,
the admin, and /media + /static assets are explicitly never redirected, and you can
allow-list extra front names (OAuth callbacks, payment returns) that must keep working.
Is it secure?
Yes — origins are matched exactly (no substring/regex tricks), the wildcard+credentials hole is
prevented, Vary: Origin is always set, and the config is behind the AgenticEcom_AstroCors
permission. Verified clean on PHP 8.4 and 8.5.