Editor’s note: Mike Shema is director of engineering at Qualys, a provider of cloud security and compliance solutions. Mike is also author of the recently published book “Hacking Web Apps: Detecting and Preventing Web Application Security Problems.” Contact him here.
HTML5 reinvigorates a technology that’s been driving web content for more than 20 years. Notably, modern browsers can still render the majority of decades-old sites still lingering from the web’s early days, but modern sites expect browsers to be a significantly more powerful platform than their predecessors. Facebook tried to push these computing boundaries even further with a pure HTML5 mobile app, but discovered there are certain limitations that come with a billion or so users. Some problems are nice to have.
The new standard also pushes security boundaries. Sites won’t immediately benefit just by adding a <!doctype html> declaration to their pages. Instead, they can improve security by adopting features that control how the browser shares or interprets content from different sources. Other features allow the browser to store more data, a great improvement over cookies, but careless use of these features has consequences for security and privacy.
Browser security largely rests on the Same Origin Policy (SOP) to strictly separate content based on its source. It’s intended to keep sites from interfering with each other. However, it hasn’t made much of an impact on browser attacks like HTML injection (aka cross-site scripting), cross-site request forgery (CSRF), clickjacking, or malware. SOP even hampers legitimate kinds of site architectures, leading devs to create inelegant, less secure workarounds.
Cross-Origin Resource Sharing (CORS) presents a way to lift this barrier that, for example, helps sites use different domains for APIs, user-generated content, or security-sensitive actions in order to create a more flexible separation of duties. And it does this without forcing an all-or-nothing decision on trust.
Flexibility is the key point here. CORS relies on server-side response headers to inform the browser which other sites may have read access to its content, meaning a site could peek into another’s HTML or view the JSON data inside a response. A web app must explicitly bequeath this trust; just because a browser requests it doesn’t mean it will receive permission to weaken the SOP.
CORS influences read access within the browser — it’s a browser security boundary, not a server-side one. Be wary about giving away trust to all origins. This makes sense for an API, but not for pages that you expect to protect from CSRF attacks. CORS has the means to define the duration of a trust declaration, and what methods or headers a browser may include when crossing origins. Keep these values to the minimum required for the site to work, rather than opening up all things to all browsers.
iFrame sandboxes take a different approach to controlling how a browser should trust content. They still apply to security inside the browser (as opposed to the server), but the focus has shifted from sharing content to restricting what that content may do.
The sandbox attribute may hold several possible values (i.e. allow-scripts, allow-forms, allow-same-origin, allow-top-navigation, allow-popups). The values are mostly self-explanatory and imply what the iFrame’s default behavior will be if they’re omitted. A sandboxed iFrame will not:
iFrames already served as a sort of quarantine for pages before HTML5. With the sandbox, browsers can better mitigate the impact of potentially malicious content. It’s a great fallback measure when a server-side security filter fails. It doesn’t mean you no longer have to inspect data for potential attacks; it means users with HTML5-aware browsers might be less impacted when you miss something.
New decades bring new buzzwords, and “Big Data” promises to fight its way to popularity. Modern web sites deal with Big Data — terabytes of information about their users — and push more types of computing to the cloud, only to be accessed solely by the browser.
HTML5 inverts some of this trend by offering up APIs like Local Storage and IndexedDB that let web apps store large amounts of data in the browser; they’re cookies on steroids, with the same security and privacy concerns. Here security needs to focus equally on access to (via the SOP) and values of data being stored.
Anything stored in the browser is just one cross-site scripting attack away from being stolen. And there’s nothing to stop a virus or malware from pulling the Local Storage files off a compromised system. This means Local Storage is a great place for caching content or saving non-sensitive user data. But it’s a terrible place for storing passwords, credit card numbers or anything else that should be safely encrypted or tucked away under the security of a server-side data store.
Browser-based storage increases the flexibility of apps to collect and manipulate data by shifting some processing burden from servers to the browser. But it doesn’t shift the burden of security. It adds a whole new requirement for it — one that involves the value of data rather than just its access.
There’s nothing inherent to CORS that determines whether shared content is safe content. A vulnerability in one site could leak a cross-site scripting attack into another. Sandboxed iFrames help the browser mitigate attacks from potentially malicious content. They add a level of granularity that’s missing from the SOP, but only for browsers that support it. Browser storage provides megabytes of space for an app to place users’ data. Yet a dev that places a plain text password into browser storage is violating long-standing security practices.
Browsers are taking incremental steps toward a more secure web ecosystem. We’ll forever be plagued by cross-site scripting, but emerging standards like Content Security Policy (think of it as a combination of CORS and iFrame sandboxes) might severely dampen it. The CORS-related headers mitigate some kinds of CSRF attacks. Application can set the X-Frame-Options header to get rid of an entire class of attack – clickjacking. Yet for all cases, the browser must support the feature.
The browser is a hostile place. Keep this in mind when you start adopting HTML5. Its features may help you keep data safer within the browser, but they need your help to keep data safe once it travels through the wild realms of servers and databases.
SaaS for vulnerability management, policy compliance, PCI compliance, web application scanning, and malware detection. The Leading Provider of Information Security and Compliance Cloud Solutions The QualysGuard Cloud Platform and integrated suite of solutions helps businesses simplify security operations and lower the cost of compliance by delivering critical security intelligence on demand and automating the full spectrum of auditing, compliance and protection for IT systems and web applications. The QualysGuard® service is used today by more than 6,000 customers in over 100 countries,...