Skip to content

Production CORS allowlist for API origins #49

Description

@Cbiux

Summary

Harden CORS configuration on the ZCore API for production — replace permissive cors() with an explicit allowlist of dapp and partner origins.


Problem

Server/src/app.ts uses:

app.use(cors());

This allows any origin to call the API from browsers — acceptable for local dev, risky in production. Malicious sites could trigger authenticated requests if combined with weak session models.


Proposed implementation

const ALLOWED_ORIGINS = (process.env.CORS_ORIGINS ?? 'http://localhost:3001')
  .split(',')
  .map((o) => o.trim());

app.use(cors({
  origin: (origin, callback) => {
    if (!origin || ALLOWED_ORIGINS.includes(origin)) {
      callback(null, true);
    } else {
      callback(new Error('Not allowed by CORS'));
    }
  },
  credentials: true,
}));

Production defaults (document, set in Vercel):

CORS_ORIGINS=https://dapp-zcore.vercel.app,https://zcore-xi.vercel.app

Preflight: Ensure OPTIONS works for auth endpoints


Acceptance criteria

  • Production rejects unknown origins
  • Local dev allows localhost:3001
  • CORS_ORIGINS documented in Server/.env.example and Docs/vercel-deploy.md
  • Server-to-server calls (no Origin header) still work
  • Unit test for origin validation helper

Related


Out of scope

  • CORS for Swagger UI (same origin as API — OK)
  • Vercel Firewall rules

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSPart of the GrantFox OSS programMaybe RewardedThis issue may receive a reward or bountyOfficial CampaignPart of an official ZCore campaignenhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions