HTML5 Attack and Secure

01 January 2015

A two-day training covering HTML5 security from both development and attack perspectives, including CORS, local storage, WebSockets, iframe sandboxing, and DOM-based XSS exploitation.

The course materials were publicly released on GitHub in April 2020.

AI Generated Summary

AI Generated Content Disclaimer

Note: This summary is AI-generated and may contain inaccuracies, errors, or omissions. If you spot any issues, please contact the site owner for corrections. Errors or omissions are unintended.

HTML5 Attack and Secure was a two-day application security training, recorded on the site as held in Kochi, India, in 2015. Day 1 built the developer-side picture of HTML5: new tags and input types, local storage and application cache, the DOM, WebSockets, web workers, server-sent events, and iframe sandboxing, each backed by hands-on page writing. Day 2 flipped to the attack side, working through XHR and CORS weaknesses and finishing with DOM-based XSS exploitation. The course materials were later released publicly on GitHub in April 2020.

Summary

The session was structured build first, break second. Day 1 covered the HTML5 vocabulary: CORS, JSON, the newer tags, local storage and WebSQL, the DOM, web workers, Web APIs, WebSockets, and iframe sandboxing, with participants writing simple pages against each concept. Day 2 attacked, first XHR and CORS, then DOM exploitation. The opening slides set context: the instructor’s profile (web, mobile, and Linux server specialization, SANS GWAPT, RHCE, and CEH certifications, co-author of the OWASP Testing Guide, project lead of Android Tamer and CodeVigilant) and an audience round collecting names or nicknames, HTML5 comfort levels, and expectations for the course.

Day 1 positioned HTML5 as created by WHATWG and W3C and released as a stable W3C Recommendation on October 28, 2014, with eliminating Flash named as the limelight point. Syntax modernization ran from the collapsed DOCTYPE through figure and figcaption, semantic header, footer, and article elements, contenteditable, new input types with pattern validation and placeholder text, and the geolocation API. Storage followed: localStorage and sessionStorage holding key/value pairs with 5 to 10 MB offered per domain, and application cache manifests served as text/cache-manifest for offline browsing, caching fonts, splash images, app icons, and entry pages while never caching CSS, HTML, or JavaScript. The remaining survey covered the WebSocket handshake with its Upgrade and Sec-WebSocket headers and the ws and wss schemes, background web workers, automatically pushed server-sent events, and a frame-busting bypass where an iframe carrying the sandbox attribute frames a page protected by if(self == top) code anyway.

Day 2 opened with XMLHttpRequest: a callback-based sample request, then the verdict that XHR is not a silver bullet, since the same origin policy blocks cross-origin reads until CORS relaxes it. Origin was defined strictly by protocol, host, and port, and cross-origin interactions were sorted into writes (redirects, links, form actions), embedding (script, CSS, img, media, fonts, frames), and reads, which are not allowed without CORS. Simple requests (HEAD, GET, or POST without custom headers, a text/plain body, no cookies in request or response) skip preflight; everything else triggers an OPTIONS exchange carrying Origin and Access-Control-Request-Method with optional Access-Control-Request-Headers, answered by the Access-Control-Allow response headers and their Max-Age caching. Marking Access-Control-Allow-Origin with * was flagged as bad practice that turns the content into a public resource.

Five CORS weaknesses followed: universal allow, which lets an attacker reach intranet data through a victim’s browser; the Origin header indicating but never guaranteeing the requesting domain, so access control based on it falls to spoofing; long Access-Control-Max-Age values keeping stale preflight policies alive in the browser cache; misplaced trust, where compromising either end of a CORS exchange yields XSS against the other; and CSRF with CORS, where .withCredentials = true replays cookies so a victim viewing trusted site A triggers a non-idempotent action at site B. Preventive checks asked for single non-empty Origin and Host headers validated against an internal whitelist, sender IP caching with HTTP 403 after one non-whitelisted origin, strict IP filtering for B2B setups, and per-origin permission sets.

The DOM exploitation block defined the model as a hierarchy of nodes navigable through firstChild, childNodes, and nextSibling, then mapped sources (document.cookie, window.name, document.URL and URLUnencoded, the location variants, and the referrer) into sinks (innerHTML, outerHTML, document.write, eval, execScript, setTimeout, setInterval, script.src, iframe.src, and location.replace or assign). Regular expressions were provided for locating sources, sinks, and jQuery specific sinks, with andlabs.org, DOMSnitch, RA2, and Dominator listed as tooling. Exercises spanned an HTML4 to HTML5 conversion, a storage-backed form, and framing a frame-busting page, and the materials were later published at github.com/anantshri/html5_attack_and_secure.

Key Themes

Notable Points

Notable Quotes

“Next generation of HTML (now current generation)”

“Limelight Point: Can eliminate flash from web”

“Web Storage is more secure and faster.”

“I can never be framed”

“So XHR allows me to fetch content and get response too so what’s the problem”

“Relax same origin policy and allow third party read”

“Can be set to * to make resources public (bad practice!)”