Cross-Origin Resource Sharing (CORS) Flashcards
Why was there a need to securely interact with JavaScript, HTML and DOM API entities within the scope of the browser?
DOM and JavaScript makes it possible to reach all properties of an HTML document.
The richness of HTML introduced additional resources, such as other documents or media items, with their own cookies, DOM, JavaScript namespace, and other rich elements.
What did Netscape introduce in 1995?
The concept of same-origin policy.
What is the same-origin policy?
The policy originally designed to protect access to the DOM, but has since been broadened to protect sensitive parts of the global JavaScript object.
In web terms, what is the origin?
A set of common characteristics of a web resource URI, formed of three elements:
* scheme (protocol)
* hostname (domain/subdomain)
* port
Give an example of an origin.
http:// www.example.com: 8080/
scheme hostname port
All resources identified by ‘schema:hostname/anything:port’ have the same origin. [T/F]
T
What kinds of attacks could happen without Same-origin policy?
A bad site may trick a user to login with bank details and use a JavaScript call to access the DOM elements of the user’s bank loaded in iframe, such as balance.
e.g.
frames.bank_frame.document.getElementById(“balance”).value
This accesses the iframe element ‘bank_frame’ then the HTML element ‘balance’ in its DOM and get its value.
This could be extended to transfer the user’s money.
This is a cross-site request.
What could happen without Same-origin Policy?
Cross-site requests can be executed without a user’s consent or knowledge.
What does the Same Origin Policy specify?
When a browser connects to an origin (e.g. http://example1.org), it will not be able to connect to resources from a different origin (http://example2.org). JavaScript AJAX code to remote websites of a different origin are not allowed.
Marked-up images/links in the HTML content are allowed.
Same Origin Policy is a defense mechanism that operates in and is enforced by the ________.
Browser.
Same Origin Policy is a Browser-based defense mechanism. [T/F]
T
Same Origin Policy permits ________ contained in a first web page to access data in a second web page if both
web pages have the same _______.
scripts
origin
Same Origin Policy was introduced by _______ Navigator in 1995.
Netscape
Why is Same Origin policy good for security most of the time?
Because most of the time a script running in the browser only needs to access resources on the same origin (e.g. API calls to the same backend that served the JavaScript code in the first place).
So the fact that JavaScript cannot normally access resources on other origins is good for security.
Give an example of a legitimate scenario where cross-origin access is desirable/necessary.
When an API is to be shared by multiple domains.