Web Technology Basics
Under the browser's same-origin policy, which of the following URLs is considered to have the same origin as https://www.example.com/app/index.html?
- Ahttps://www.example.com/data/list.json
- Bhttp://www.example.com/app/data.json
- Chttps://api.example.com/app/data.json
Show answer and explanation
Answer: A. https://www.example.com/data/list.json
An origin is determined by the combination of three things, the scheme, the host name and the port number, and two URLs have the same origin only when all three match. The path does not matter, so /data/list.json has the same origin. Under the same-origin policy, a page's JavaScript in principle cannot read the contents of responses received from other origins. This prevents a malicious page's script from reading information from other sites where the user is logged in.
- A. Correct. The scheme, host name and port number (443) are the same; only the path differs.
- B. The scheme differs (http), and the default port number also becomes 80, so it is a different origin.
- C. The host name differs (api.example.com), so it is a different origin even though it is under the same domain.