6.033 2011 Lecture 23: Browser security how does a web browser work? (incomplete, slightly out-of-date w/ HTML5..) user enters a URL or clicks on a link. browser looks up server's IP via DNS. browser connects, sends HTTP request. server responds with data and headers (e.g., document type, ..) browser parses data (assuming it's HTML), loads any sub-objects. images, frames, etc. want to identify users. browsers support "cookies": a set of key-value pairs for each web site. e.g., from last lecture, cookies can store session authentication data. cookie often set by server, in response to the user supplying password. browser includes all cookies when sending an HTTP request. want more dynamic things in the browser. browser executes Javascript code specified in the page. now nickolai views eve's profile. right-click to inspect image element. ] bad design: privileges implicitly granted to all code (authentication step). principle: be explicit (e.g., server explicitly lists all Javascript code). how to fix? server must be very careful about sending back any HTML.. quite difficult in practice, especially with complex user-editable pages. another variation: how do web servers / browsers determine if a page is HTML? in theory, HTTP includes a Content-Type header (text/html for HTML). in practice, some servers send back incorrect Content-Type headers. as a result, many browsers try to guess the content type. e.g., look for tag. special XML tag in any server page specifies the security policy for code. web sites unaware of Flash's special tag vulnerable to XSS-like attack. similar problem with other plugins (e.g., Silverlight). principle: economy of mechanism. browser bugs: buffer overflows. bug in Javascript interpreter can allow malicious JS code to escape browser. better design: Chromium, runs a separate interpreter process for each window. each interpreter process runs without access to user's local files, etc. (need some OS support to do this.) principle: least privilege. [ skipped material below in lecture ] assumption 4: same-origin policy captures the desired security goals. Javascript code can inspect DOM for pages from the same origin, including attributes of text like color. visited links might look different (different color, size, etc). result: malicious page can tell what sites you've visited. fix: complex rules for accessing color of a link, setting properties, etc. e.g., visited links cannot be different font size now. otherwise, adversary can detect a larger/smaller overall page size! [ http://blog.mozilla.com/security/2010/03/31/plugging-the-css-history-leak/ ] cookies: adversary can ask browser to send HTTP request to another server. browser loads the specified URL, using cookies for URL's origin. naive server gets request with user's cookie, performs operation. browser tricked into issuing request on user's behalf, server performs it. attack is typically called cross-site request forgery (CSRF). [ demo: in nickolai's browser, load http://attacker.demo/attack.html, then go back to http://zoobar.demo/zoobar/; where did zoobars go? view source of attacker's page.. ] problem: cookies aren't enough to authenticate that request came from user. hard to prevent cookies from being sent, for usability reasons. e.g., users want to use cookies when clicking on links. typical solution: change server to require more than just a cookie. include a secret per-user token in each link generated by server. e.g., http://zoobar.demo/zoobar/transfer.php?...&token=(secret) verify cookie and token for each request. if adversary cannot obtain or guess token, cannot trick browser/server. SOP stops adversary from reading another origin's DOM/page to get token.