October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

CORS Explained: Why Websites Can’t Read Each Other’s Data

CORS lets a server authorize specific websites to read its responses in a browser. Understand same-origin restrictions, preflight checks, credentials, and error fixes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

CORS (Cross-Origin Resource Sharing) is a set of HTTP headers that lets a server tell a browser which websites may read its responses. It creates a limited exception to the browser’s same-origin restrictions; it is not a universal barrier that prevents every kind of network request.

What counts as a different origin?

An origin is the combination of a page’s scheme, host, and port. For example, https://app.example and http://app.example are different origins because their schemes differ. Different ports also mean different origins. A path difference alone does not: https://app.example/profile and https://app.example/settings share an origin.

As an Amazon Associate I earn from qualifying purchases.

The browser’s same-origin policy limits how scripts from one origin can interact with resources from another. Without that restriction, a malicious page could try to use a visitor’s browser session to read private information from a site where the visitor is signed in, then send that information elsewhere.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How does CORS decide whether JavaScript can read a response?

Suppose JavaScript on https://site-a.example calls fetch() for a resource on https://site-b.example. The browser includes an Origin header in the request. The server can respond with Access-Control-Allow-Origin naming the origin it permits, or use * for a public resource that does not require credentials. The browser checks the response headers and exposes the response to the calling script only if the CORS policy allows it. See MDN’s CORS guide and Access-Control-Allow-Origin reference.

This is primarily a control over whether browser-based script can read a cross-origin response. It does not mean browsers forbid every cross-origin request: navigation, embedding, and some forms of sending requests follow other rules. A CORS failure also does not prove the server never received a request.

When does a browser send a preflight request?

For some cross-origin requests, the browser first checks permission with an OPTIONS request. This preflight describes the method and any non-safelisted headers the script intends to use. The server responds with its CORS policy; if the policy allows the planned request, the browser proceeds with the actual request. The details are described in MDN’s preflighted requests documentation.

A preflight is a browser protocol check, not proof that a request is harmless or that a user is authenticated. It asks whether the server permits the browser to make the planned cross-origin request under CORS.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do credentials change the required headers?

When a request includes credentials such as cookies, the server cannot authorize it with Access-Control-Allow-Origin: *. It must return the specific trusted origin and explicitly allow credentials when they are needed. MDN explains the relevant rules in its credentialed requests guidance.

  • For public, non-credentialed resources, Access-Control-Allow-Origin: * can be appropriate.
  • For credentialed access, return an explicit origin from a trusted allowlist rather than blindly reflecting whatever value arrives in Origin.
  • Grant access only to the origins and resources the application needs.

CORS is not a substitute for authentication, authorization, or defenses against cross-site request forgery. Those controls answer different security questions.

What should a server return when access varies by origin?

If a server chooses its CORS response based on the incoming Origin, it should also send Vary: Origin. That tells caches that the response can differ depending on the request’s origin, reducing the risk of serving a response with the wrong CORS headers. See MDN’s CORS and caching guidance.

Avoid using Access-Control-Allow-Origin: null as a shortcut. Some opaque or sandboxed origins serialize as null, so allowing it can authorize a broader set of contexts than intended; MDN discusses this risk in its header reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why am I getting a CORS error, and how can I fix it?

Browsers deliberately give JavaScript limited details about CORS failures, so the console is usually more informative than the error reported by the script. Check the page’s origin, the requested URL, and the request and response in the browser’s Network panel.

  1. Identify the page origin: scheme, host, and port.
  2. In the browser console and Network panel, locate the failed request and inspect whether it was preceded by an OPTIONS preflight.
  3. Check that the server’s response allows the page origin and, where applicable, the requested method, headers, and credentials.
  4. If the server is not yours, ask its owner to authorize browser access or use a server-side intermediary only when your application is legitimately permitted to access the resource.

Frontend JavaScript cannot add permission headers to another server’s response. The server that serves the resource must provide the appropriate CORS response headers.

Does mode: 'no-cors' bypass CORS?

No. In fetch(), mode: 'no-cors' restricts which requests the script can make and gives it an opaque response, whose body and headers are not readable by JavaScript. It does not turn a protected cross-origin response into readable data. MDN covers this behavior in its CORS and no-cors mode documentation.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.