"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why is Access from Origin \'https://example.com\' Blocked Even Though I\'ve Allowed \'https://example.com/\'?

Why is Access from Origin \'https://example.com\' Blocked Even Though I\'ve Allowed \'https://example.com/\'?

Published on 2024-11-08
Browse:327

Why is Access from Origin \'https://example.com\' Blocked Even Though I\'ve Allowed \'https://example.com/\'?

Access from Origin 'https://example.com' Has Been Blocked Even Though I've Allowed 'https://example.com/'

When attempting to access a resource cross-origin, developers often encounter issues related to the Access-Control-Allow-Origin header. The key to resolving these issues lies in understanding the precise meaning of "origin" in the context of the CORS protocol.

The Concept of Origin in CORS

In CORS, an origin is a combination of a scheme, host (domain), and port. Importantly, it does not include a path. Therefore, the following two origins are considered distinct:

  • https://example.com
  • https://example.com/path/to/resource

The Problem: Trailing Slashes in Origins

The problem in this particular case arises from a misunderstanding of the definition of origin. Specifically, the trailing slash in the allowed origin is not permitted according to CORS protocol specifications. As a result, the origin header sent by the browser (without the trailing slash) does not match the allowed origin configured on the server.

Solution: Remove Trailing Slash from Allowed Origin

To resolve this issue, simply remove the trailing slash from the allowed origin value in your CORS configuration. In this case, the correct allowed origin would be:

  • https://googledocs-clone-sbayrak.netlify.app

With this modification, the browser's origin header will match the allowed origin, and CORS will be allowed successfully.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3