Skip to content

My API uses Access-Control-Allow-Origin: *. Is that safe?

Short answer

Short answer: replace a wildcard with the exact trusted origins required by the browser app and avoid reflecting arbitrary Origin headers. This guide explains what to verify and what the public scan cannot prove, without logging in, changing records, or treating an inconclusive response as a pass.

Check yours now
Read-only. No writes or row contents.

What the wildcard CORS configuration check covers

CORS controls whether browsers allow scripts from another origin to read a response. It is not authentication and does not stop direct requests from command-line clients or servers.

The finding describes a public condition, not proof that someone has abused it. First preserve the relevant deployment details, then rotate exposed credentials or close the access path before investigating billing, logs, or affected records.

A wildcard origin can be acceptable for intentionally public, non-credentialed resources. It is risky when the endpoint returns user-specific data, reflects arbitrary origins, or combines broad access with credentials.

Understand the evidence before changing code

List the production and development origins that actually need browser access. Include scheme and host, account for preview domains deliberately, and avoid matching an untrusted suffix with a loose string check.

Severity reflects potential impact and reach, not certainty of exploitation. A public key can be intentionally visible; the important distinction is what the provider allows that key to do and which server-side policy still applies.

Apply the narrow, safe change

Return an allowlisted origin only after exact comparison, set Vary: Origin when the response varies, and handle preflight requests consistently. Keep authentication and authorization on the API itself.

Exact origin allowlist · ts
const allowed = new Set(["https://app.example.com"]);
const origin = request.headers.get("Origin");
if (origin && allowed.has(origin)) {
  response.headers.set("Access-Control-Allow-Origin", origin);
  response.headers.set("Vary", "Origin");
}

Prefer the smallest repair that restores the intended boundary. Keep public client configuration public, move privileged operations behind an authenticated server route, and make data rules depend on the authenticated owner or an explicit role.

Verify the production result

Test a trusted origin, an unrelated origin, and a direct unauthenticated request. Browser developer tools should show the intended CORS headers without granting data access to an untrusted site.

Use the snippet as a starting point, not a blind migration. Confirm the real table, environment, route, identity claim, and deployment platform first; a copied policy with the wrong owner field can block legitimate users or expose the wrong records.

Keep the issue from returning

Keep the origin list in reviewed configuration and test it when adding a new frontend host. Do not use CORS as a substitute for session checks, CSRF defenses, or server-side policy.

Verify the repair from the same public vantage point that exposed it. Check the deployed response, confirm the finding is gone, and test the intended signed-in user and an unrelated user through the normal application flow.

Limits and next steps

A header scan cannot tell which origins your business intends to trust. Review the endpoint's data sensitivity and credential behavior before choosing an allowlist.

Prevent recurrence with a reviewed migration, a secret scanner, and a small regression test that runs before deploy. Store only the minimum required credential, scope it to one project, and define who can rotate it.

A public scanner cannot establish whether private records were accessed or whether an account was compromised. If a real secret shipped, revoke it with the provider and review the provider's usage and audit history.

Key facts

  • CORS is enforced by browsers and is not server-side authentication.
  • Wildcard access is not automatically unsafe for public non-credentialed resources.
  • Credentialed CORS requires explicit origin handling.

Questions

Can a clean wildcard CORS configuration check prove the app is secure?
No. It is evidence about the advertised public surface only. It depends on the endpoint; public resources differ from user-specific credentialed responses.
What should I do first if the finding is real?
Use exact trusted origins and keep authentication checks on the server.
Does ProofForge change application data?
No. The scan is read-only and does not sign in, write records, or use a discovered secret. You make and review any remediation in your own project.
What should I do after the repair?
Test allowed, disallowed, and unauthenticated requests separately.

Official documentation referenced

Related

Last updated 2026-11-25 · Reviewed by ProofForge · Methodology · Markdown