CORS - Cross Origin Resource Sharing

CORS stands for Cross-Origin Resource Sharing. It is a security feature implemented by web browsers that controls how web pages in one domain can request and interact with resources hosted on another domain.

Web browsers have a same-origin policy, which means that by default, web pages can only make requests to the same domain from which they were loaded. CORS relaxes this restriction and allows web pages to make cross-origin requests to access resources from different domains.

When a web page makes a cross-origin request, the browser sends an HTTP request with an "Origin" header that indicates the origin (domain) of the requesting page. The server can respond with appropriate CORS headers, such as "Access-Control-Allow-Origin," to indicate which origins are allowed to access its resources. If the server allows the request, the browser allows the response to be delivered to the requesting page. If the server does not allow the request, the browser blocks the response to prevent potential security risks.

CORS is important for security because it helps prevent malicious websites from making unauthorized requests on behalf of a user and accessing sensitive data from other domains. It is commonly used in modern web development when building applications that make cross-origin API requests.