Application Security Flashcards
6.858
What are five typical attack surfaces in modern browsers?
- JavaScript execution
- The Document Object Model (DOM)
- XMLHttpRequests (AJAX)
- Web Sockets
- Multimedia ( tags, etc.)
6.858, 8. Web Security Model
Why is an example of a parsing context attack in a browser?
When executing JavaScript, if code uses input from an untrusteed source that gets stored in a string, for example
var x = “untrusted”
One example of an attack would for the untrusted user input to include a quotation mark, meaning the JavaScript parser will prematurely terminate the string, causing a parsing context switch to the JS execution environment, meaning the user can inject code by inserting statements following the string, e.g.
”; alert(‘got you’)
6.858, 8. Web Security Model
How does composition in modern systems lead to an increase in attack surface for modern web systems?
As modern, complex systems utilise a number of different languages and technologies, data travels through many different contexts, each with their own potential attack vectors and individual security concerns. This means that more area exists for exploits at various layers in the system (e.g. SQL, JavaScript, CSS, HTML, .NET all in the same application)
6.858, 8. Web Security Model
What are five key concerns that have increased in importance in modern web security?
- Composition: Multiple languages and frameworks form one app
- Incoherence: Complex/inconsistent specifications for standards like HTML, JPEG, etc. leading to difference in actual browser behaviour versus expected
- Same-Origin Policy: Content from typical commercial websites comes from a multitude of sources, each with their own scripts, dependencies and attack surfaces and potential interactions
- DNS Rebinding: Impersonating a victim’s domain to execute code with the same-origin authority as the victim’s origin
- Clickjacking: Attacks targeting the way frames are rendered in a certain browser context
6.858, 8. Web Security Model
What is the same-origin policy in browser security?
In essence, the goal of the same-origin policy is that content from different websites should not be able to tamper with content from other websites, unless there is an explicitly-defined reason content from these two websites can interact.
Each resource is assigned an origin, and by default, resources can only access resources from that same origin.
6.858, 8. Web Security Model
What is the general definition of an origin when referring to the same-origin policy in browsers?
Scheme + Host + Port
e. g. http://foo.com:1234 or https://foo.com
6. 858, 8. Web Security Model
What are some typical resources associated with an origin in a browser?
- Cookies
- DOM storage (browser key-value store)
- JavaScript namespace (isolates functions, objects, etc.)
- Document Object Model (DOM) tree
- Visual display area on the page
6.858, 8. Web Security Model
What are the four main ideas behind the same-origin policy
- Each origin has its own set of resources
- Each frame in a page has its own origin (e.g. like Unix process)
- Scripts execute within the authority of the origin
- Passive content has no authority
6.858, 8. Web Security Model
What is a MIME sniffing attack?
- As the same-origin policy determines that passive content, such as an image, has no authority
- Browsers can be lax with security around passive content, so an attacker could inject HTML into something it misattributes as an image by changing special bytes in the file header that the browser uses to interpret the MIME type of a file
- This can lead to things that are really scripts being considered images, leading to coercion into something it outputs to the page
6. 858, 8. Web Security Model
How does a browser handle the origin of the window object in the DOM?
The window is a top level element in the DOM below the document itself, and the window inherits one of two origins:
- The origin of the of the document
- A suffix of the origin of the document, e.g the window for ads.facebook.com can be set to facebook.com using the document.domain DOM property, but not account.facebook.com or google.com
6.858, 8. Web Security Model
What is one method in which two frames can communicate messages across origins in a browser context?
The window.postMessage() function in JavaScript can be used to pass values between origins, provided both origins opt into communicating via this method.
When can two frames in a browser context interact?
- Both frames explicitly set the document.domain property to the same value
- Neither of the two frames explicitly set the document.domain property, but the windows inherit the same origin from the browser URL
6.858, 8. Web Security Model
What is an example of a frame origin policy exploit that could lead to an attack within a domain and how does the same-origin policy combat it?
A compromised subdomain, e.g. ads.facebook.com that is the origin of a frame within facebook.com could try setting its own document.domain property to facebook.com, thus allowing it to interfere with the context of facebook.com.
The same-origin policy prevents this if facebook.com does not set its own document.domain property explicitly. If only the frame sets the property and facebook.com’s window object does not explicitly set it and inherits its origin from the browser context, then the same origin-policy prevents these two frames from communicating.
6.858, 8. Web Security Model
Where do DOM nodes obtain their origin?
DOM nodes inherit the origin from the frame within which they exist.
6.858, 8. Web Security Model
What are three elements of a cookie with respect to the same-origin policy?
- The domain, which can be a suffix of the window’s origin
- A path, which is a suffix of the hostname, e.g. / or /abc
- A secure flag, to distinguish https cookies that should not be accessible by http content
If a cookie is set at a path /, this indicates all pages should be able to access it, whereas the server setting the path at /abc would mean only /abc or /abc/* are able to access that cookie.
6.858, 8. Web Security Model
What are two methods in which a cookie can be set?
- JavaScript can set cookies using the document.cookie property
- The server can set cookies using the HTTP Cookie response header
6.858, 8. Web Security Model
How are XHR calls isolated within a certain context by a same-origin policy?
An XHR request originating from an origin set by the containing window or frame can only target a URI within that same origin, unless the destination server implements Cross-Origin Resource Sharing (CORS) [using the Access-Control-Allow-Origin response header]
6.858, 8. Web Security Model
How are access to images and CSS from other origins protected in a same-origin policy?
Frames can embed passive content from any origin, but they cannot directly inspect the data within the resources that are embedded from another origin.
[Note: this protection does not work effectively as malicious code can infer details about these objects as black boxes]
6.858, 8. Web Security Model
How does the single-origin policy handle JavaScript from remote origins, and what is the fundamental flaw with this approach?
JavaScript embedded from remote sources can be executed by a frame, but the embedding frame cannot directly access the source code contained within the script.
However, as functions are first-class objects in JavaScript, malicious code can simply call toString() on any function object and retrieve its source code. That, and you can just request resource like that directly.
6.858, 8. Web Security Model
What is an example of a Cross-Site Request Forgery (CSRF) attack?
Say a bank, bank.com, has a cookie for authenticated user data that it sends along with every request. A malicious frame embedded on bank.com can set its origin to bank.com, hence make XHRs to the bank’s server within the same browser context, so the authenticated user cookie will be sent along with these malicious requests, thus authenticating the attacker as the victim.
6.858, 8. Web Security Model