CORS: Everything Software Developers Need to Know About CORS

Fungineer
8 min readSep 18, 2023

CORS: Everything Software Developers Need to Know About CORS

by Author

TL;DR

Let’s imagine you’ve opened a website called “A.com” in your web browser. This web page intends to display an image retrieved from another website called “B.com.”

The problem here is related to security. For security reasons, when a web page is running on “A.com,” the browser cannot freely fetch images from a different source, such as “B.com.” This is known as the Same-Origin Policy.

Now, CORS comes into play. The “B.com” server explicitly grants permission to the browser to allow requests from “A.com.” The server does this by setting up permissions using headers, which the browser checks.

In other words, the “B.com” server responds with CORS headers that allow requests from the “A.com” origin in the request headers. The browser verifies this permission and safely fetches the image from “B.com.” This maintains security while enabling data sharing between two different sources.

In summary, CORS is a mechanism that defines rules between browsers and servers to safely exchange data between different origins. It allows web applications to utilize data from different sources or perform secure inter-server communication.

--

--

Fungineer
Fungineer

Written by Fungineer

As a software engineer, I enjoy solving problems and crafting practical solutions. Exploring new technologies and simplifying complex tasks are my passions.

No responses yet