Browser security aims to let users browse safely, protect sensitive information, and support secure web applications with the same security properties as standalone applications.
Site A cannot compromise the session at Site B. Isolation between origins.
Applications delivered over the web should achieve the same security properties as standalone apps.
Three attacker models: Web Attacker (controls malicious site), Network Attacker (intercepts network), Malware Attacker (escapes browser, runs under OS). Malware is most lethal; Web is least.
Controls attacker.com, can obtain SSL cert. User
visits attacker's site or runs attacker's app. Does
not control the network.
Passive: wireless eavesdropper. Active: evil router, DNS poisoning. Can intercept and modify traffic.
Escapes browser isolation, runs under OS control. Browsers may contain exploitable bugs (remote code execution). Even bug-free browsers face XSS, SQLi, CSRF.
An origin is a combination of URI scheme, hostname, and port number. Same-origin policy requires that requests to access data must be from the same origin.
Origin A can access origin B's DOM if A and B have the same (protocol, domain, port).
Generally based on (scheme, domain, path). Scheme is optional for backward compatibility.
Safely execute JavaScript from remote websites. No direct file access; limited access to OS, network, browser data, and content from other origins. SOP restricts cross-origin DOM/cookie access.
Browser content comes from many sources:
<script src="...">,
<iframe src="...">,
<link rel="stylesheet" href="...">, Flash/plugins.
Third-party scripts and iframes are common attack vectors.
Frames (rigid frameset) and iframes (floating inline) delegate screen area to content from another source. Each frame has an origin; the browser isolates frames by origin.
Can Frame A execute a script that manipulates arbitrary/nontrivial DOM elements of Frame B?
Can Frame A change the origin of content for Frame B?
Can Frame A read cookies from site S?
Can Frame A write cookies for site S?
Every browsing context (frame or web worker) has an origin, is
isolated by SOP, may use postMessage for cross-origin
communication, and can make network requests via XHR or tags.
Ensures iframe has unique origin, cannot execute JavaScript (unless
allow-scripts), no form submission, disabled APIs, no
plugins. Start with no permissions, then allow specific ones.
allow-scripts - JavaScript executionallow-same-origin - retain origin (required for some
features)
allow-forms - form submissionallow-popups - open new windowsallow-top-navigation - break out of frame
allow-same-origin +
allow-scripts together can bypass sandbox isolation
- treat carefully.
Prevent and limit damage of
XSS. XSS bypasses SOP by
tricking a site into delivering malicious code. CSP restricts
resource loading to a whitelist via
Content-Security-Policy HTTP header.
javascript: URLs
eval(), new Function()| Directive | Purpose |
|---|---|
script-src |
Origins for loading scripts |
connect-src |
Origins for XHR, WebSockets, EventSource |
frame-src |
Origins for embedded frames |
img-src |
Origins for images |
style-src |
Origins for stylesheets |
default-src |
Fallback for unspecified directives |
Current origin only (not subdomains)
Allows inline JavaScript/CSS - weakens XSS protection
Allows eval(), new Function() - weakens XSS protection
Protect against modified CDN content (DNS poisoning, hostile server). Page author specifies a hash of the resource; browser verifies integrity before loading.
Run in isolated thread, loaded from separate file. Same origin as
creating frame, no DOM. Communicate via postMessage.
Helps with performance and isolation.
A session is a sequence of requests/responses from one browser to one or more sites. Session management: authorize once; all subsequent requests tied to user. Without it, users would constantly re-authenticate.
Set-Cookie: SessionToken=fduhye63sfdb
https://site.com/checkout?SessionToken=kh7y3b
<input type="hidden" name="sessionid"
value="kh7y3b">
Best: combination of all three for redundancy.
1. Delete SessionToken from client. 2. Mark session token as expired/revoked on server. Many sites do 1 but not 2 - risky, especially when falling back to HTTP after login.
Attacker sniffs a legitimate session ID and impersonates the victim. Defense: HTTPS, HttpOnly, Secure, SameSite, short expiry.
Beware of weak/predictable session IDs. Counter-based or weak MAC tokens can expose secrets - use cryptographically random tokens with sufficient entropy.
Shows the page you came from. Problem: leaks
URL/session token to third parties. Solution:
<a rel="noreferrer" href="..."> or Referer
suppression. Not sent when HTTP refers to HTTP (mixed content rules).
protocol + hostname + port. Same origin = full DOM/cookie access.
No direct file/OS access. SOP limits cross-origin access.
canScript, canNavigate, readCookie, writeCookie - isolation by origin.
Whitelist script/style/frame sources. Blocks inline scripts, eval. Mitigates XSS.
Unique origin, no scripts/forms/plugins by default. Add allow-* as needed.
Hash in integrity attribute - browser verifies CDN content before execution.
Cookies have no integrity - server is blind to attributes; network attacker can overwrite. Use HttpOnly, Secure, SameSite, and cryptographic signing (MAC) for sensitive values. Session tokens must be unpredictable; revoke on logout server-side.
code.google.com/p/browsersec - Part 1 & Part 2 wiki
Top 10: Injection, XSS, Broken Auth, IDOR, Security Misconfiguration, etc.
Content Security Policy, Same-origin policy, Secure context