=== Web security policies === Previous parts were mostly concerned with the server. Let's take a look at the browser. What exactly does a browser do? - HTTP, SSL, FTP, HTML, CSS, Javascript, plugins (flash, silverlight, ...) etc. Browser does lots of things, and there are many different browsers. The web has no coherent design, it all came incrementally: Race to add new features, strive to be tolernant with sloppy websites -> bad for security. What are the securiy goals in this context? What is the threat model? Threat model: Adversary controls his/her website Adversary can cause victim to visit his website (links, ads) Cannot intercept/inject packets (we'll cover HTTPS later) Server and browser don't have bugs (but website may well have!) Goal: Isolate different websites from each other. Attacker shouldn't be able to interfere with other websites. Why is this difficult? We want to allow interaction between websites: Links, frames (embedding), mashups Many pages might be running at the same time in the browser. Javascript can access other frames, open new windows, make requests, navigate etc. Why do we run javascript in the browser then? Make websites more reactive, saves round-trip, allow more complex behaviour. So what happens when the browser loads a page? Resolve hostname (DNS) Send request to server Render the response (Rendering Engines: webkit, gecko, blink) Start executing javascript (happens already while rendering) How does Javascript work? Embedded ( Dangerous even if user wouldn't enter the url. Some script running on attackers site can redirect you to that url and run code in foo.bar.com's origin! Persistent attack: Gets written to db/file and run every time page is loaded (eg. myspace worm) Defenses: Browser XSS defenses: Check if fragments of input are in page output. Only works for reflection, incomplete. CSRF: http://buysomething.com?item_id=1253412&ship_to=attacker Can send this GET request from any origin! Same goes for POST Defenses: Include a token in forms, check for valid token on submit (store in session or cookie) Attacker must not be able to obtain/forge token Session fixation: Cause the user to log into attackers session. Attacker can see what user did (i.e. send emails) Make sure you don't share domain with untrusted third parties (ie. all of mit.edu) Also possible if login page has no CSRF protecton (page logs attacker in, sets cookie) SQL injection: $query = "SELECT * FROM users WHERE username=" + $_GET['username'] http://foo.bar.com/?username=' or 1 or ''=' Defense: Always properly escape data (SQL libraries provide functions like mysql_real_escape_string) Django: use ORM, developer doesn't actually write queries Clickjacking: Invisible frame on top of visible frame Defense: Don't allow embedding as frame (X-Frame-Options: deny) For pages that have to be embedded: ask for user confirmation on non-embeddable page Directory traversal: open("/var/www/foobar/"+filename) http://foo.bar.com/../../etc/passwd Defense: Properly encode === HTTPS === Essentially HTTP on top of SSL Send data over encrypted channel to ensure confidentiality Uses public key cryptography to establish secure session (SSL handshake) Exchange a symmetric key (for speed) after establishing secure connection with asymmetric crypto Encryption provides data secrecy, use message authentication integrity. Message authentication code (MAC) with symmetric keys can provide integrity. Look up HMAC if you're interested in more details. Can use public-key crypto to sign and verify, almost the opposite: Use secret key to generate signature (compute D_SK) Use public key to check signature (compute E_PK) How do we establish a secure connection? Must know that we're talking to the right server If computers already know eachothers public keys: No problem, just connect If computers don't know eachoters public keys (usually the case for HTTPS): Use "Certificate Authorities" that sign server's public key Browsers have a list of certificate authorities that they trust What can go wrong? Crypto: Some attacks, but nothing earth shattering. Crypto is usually not the weakest part Authenticating the server: Adversary can obtain certificate in someone else's name Security depends on weakest of over 100 CAs (lists shipped with browser, BIG problem) CA compromises happen What if a certificate is compromised? Certificate revocation lists (soft-fail, thus susceptible to DNS) Mixed content (HTTP and HTTPS) Adversary can tamper with HTTP responses. If scripts or plugin content are included in same origin over HTTP, they have full access. Cookie confidentiality: HTTPS cookies can be sent over HTTP unless marked with "secure" flag Users not checking "lock icon", clicking away warnings Yeah, it's that simple... Login form on HTTP page: Even if login form target is HTTPS, attacker can just inject code into HTTP login page and collect credentials when they're entered. Possible solutions: ForceHTTPS: (stored bit in a cookie) Prohibit mixed content Prohibit user from overriding certificate errors Mark all HTTPS cookies as secure Difficulties: Bootstrapping: use DNSSEC embed in url incldue in certificate Potential privacy leak Use for denial of service attack