Skip to content

Configure exact CORS origin policies for browser clients

Allow your production domains and preview deployments to call endpoints cleanly while blocking unauthorized third-party sites.

Copy the prompt and paste it into the AI assistant you already use.

Steps to configure safe browser CORS policies

  1. 01

    Avoid bare wildcard origins

    Specify exact https origins instead of Access-Control-Allow-Origin: * on authenticated routes.

  2. 02

    Support staging preview subdomains

    Add scoped wildcard patterns restricted strictly to your team's verified preview domain suffix.

  3. 03

    Expose quota headers to JS

    List custom rate-limit or trace headers in Access-Control-Expose-Headers so Fetch can read them.

  4. 04

    Remember CORS is not auth

    Always pair CORS browser policies with JWT validation or rate-limited public shields.

Common questions

Why shouldn't I just turn on wildcard CORS to fix browser errors?

Wildcards let arbitrary third-party web pages attempt cross-origin calls against your endpoints. Exact origin lists tighten browser boundaries.

Do I need to configure OPTIONS preflight handlers manually?

No. APIkit handles CORS preflight OPTIONS responses automatically at the edge based on your origin rules.

Can our frontend JavaScript read rate-limit and trace ID headers?

Yes. Adding custom headers to Access-Control-Expose-Headers makes them accessible inside browser fetch responses.