Same origin policy is meant to protect users from intermediate contents hijacking between web server and web users. This is done by the client side, ensuring that one website/client cannot access another's credential-restricted contents.
All request must have the same Uniformed Resources Identifier (URI) defined in RFC3986. Here are the examples:
Each of them has the same:
These are not the same:
http://example.com/
- basehttp://example.com:8080/
- different port number (authority)http://www.example.com/
- different host (authority)https://example.com:80/
- different schemehttps://example.com/
- different schemehttp://example.org/
- different host (authority)http://ietf.org/
- different host (authority)As a HTML page from the origin server states to load:
<script src="https://example.com/library.js"></script>
It means the origin trusts the source and execute the javascript.
Similarly:
<form method="POST" action="https://example.com/login">
... <input type="password"> ...
</form>
It means the origin is trusted to receive sensitive data.
To manage the trust, the client needs to ensure that any inflow or outflow of data MUST have the same URI except:
By default, an origin is allowed to perform cross origin resources loading for:
If exception is set, it creates the following possible vulnerabilities:
To create exception, the server will need to specify the allowed origin header, such as:
Access-Control-Allow-Origin: www.example.com
If to receive from any site, use asterisk instead:
Access-Control-Allow-Origin: *
That's all about same origin policy.