XS-Leaks: Client-Side Attacks in a Post-XSS World
Zeyu (Zayne) Zhang (Computer Science Student · University of Cambridge)
Security BSides London 2023 · Day 1 · Rookie Track
Overview
In this insightful talk from BSides London, Zeyu (Zayne) Zhang, a Computer Science student at the University of Cambridge, delves into the evolving landscape of web security, arguing that we are entering a "post-XSS world." As traditional Cross-Site Scripting (XSS) and Cross-Site Request Forgery (CSRF) vulnerabilities become increasingly difficult to exploit dueue to advancements in web frameworks and browser security standards, attackers are shifting their focus. Zhang introduces XS-Leaks, a category of client-side attacks that leverage legitimate browser APIs and behaviors to infer sensitive user information, even without the ability to execute arbitrary JavaScript or perform direct account takeovers.

Key moments
- 2:40 Introducing XS-Leaks: Abusing legitimate browser APIs
- 4:00 Leaking client-side redirects via history.length
- 6:00 Detecting server redirects using browser URL length limits
- 8:40 Overcoming SameSite protections with HTML injection
- 10:00 Surprising geolocation leak through cross-origin iframes
- 11:50 Leaking status codes using responsive images & iframes
- 13:00 Summary: The future of client-side attack surfaces
XS-Leaks: Client-Side Attacks in a Post-XSS World
Speakers: Zeyu (Zayne) Zhang, Computer Science Student, University of Cambridge
Conference: BSides London
YouTube: https://www.youtube.com/watch?v=SEVdfk0vTCM
Overview
In this insightful talk from BSides London, Zeyu (Zayne) Zhang, a Computer Science student at the University of Cambridge, delves into the evolving landscape of web security, arguing that we are entering a "post-XSS world." As traditional Cross-Site Scripting (XSS) and Cross-Site Request Forgery (CSRF) vulnerabilities become increasingly difficult to exploit dueue to advancements in web frameworks and browser security standards, attackers are shifting their focus. Zhang introduces XS-Leaks, a category of client-side attacks that leverage legitimate browser APIs and behaviors to infer sensitive user information, even without the ability to execute arbitrary JavaScript or perform direct account takeovers.
The presentation highlights that while developers and security professionals have made significant strides in mitigating classic vulnerabilities, a new class of subtle information leakage attacks is emerging. XS-Leaks exploit side channels within the browser's functionality, turning seemingly innocuous features into powerful oracles for sensitive data. Zhang demonstrates several novel techniques, including methods to detect client-side and server-side redirects, bypass SameSite cookie protections, and even extract geolocation data, all by observing browser behavior rather than direct data access. This talk is crucial for anyone involved in web security, emphasizing the need to expand defensive strategies beyond preventing JavaScript execution to encompass the broader spectrum of client-side information leakage.
Background
▶ Watch: Introducing XS-Leaks: Abusing legitimate browser APIs (2:40)
The evolution of web security has seen a dramatic shift over the past decade. Historically, XSS was rampant, often easily achievable due to insecure web frameworks that failed to sanitize untrusted user input, such as echoing raw PHP variables into HTML. Similarly, the lack of robust client-side frameworks led developers to manually manipulate Document Object Model (DOM) elements, frequently resulting in DOM XSS vulnerabilities. Reflected XSS was also a common threat, making direct JavaScript injection a relatively straightforward path to compromise.
However, the web security landscape has matured significantly. Modern web frameworks like React now prioritize security by default, automatically escaping embedded expressions before rendering, thereby preventing many common XSS vectors. Concurrently, web standards have evolved to include powerful defensive mechanisms such as Content Security Policy (CSP), which acts as a crucial last line of defense against XSS by restricting the sources from which content can be loaded. Browsers have also become more intelligent, implementing features like robust MIME type sniffing to prevent content confusion attacks. While these advancements have dramatically reduced the prevalence of traditional XSS, Zhang acknowledges that "there will always be quirks and bypasses," citing examples like injecting JavaScript URLs into href attributes or manipulating component properties in React to specify custom HTML event handlers.
Despite these lingering edge cases, the overall trend indicates that traditional XSS and CSRF are becoming "more and more obsolete." This paradigm shift necessitates a re-evaluation of attack surfaces. Instead of striving for full account takeovers or direct session data theft via JavaScript execution, the focus moves to XS-Leaks. The core premise of XS-Leaks is to "abuse legitimate browser APIs to sort of infer information about users in a meaningful way." This involves exploiting subtle differences in browser behavior—often referred to as side channels or oracles—to deduce sensitive information about a user's authenticated state, preferences, or interactions with a target application, even when direct access to cross-origin data is blocked by browser security policies.
Key Findings
▶ Watch: Detecting server redirects using browser URL length limits (6:00)
The talk presents several compelling XS-Leak techniques that demonstrate how seemingly innocuous browser functionalities can be weaponized to infer sensitive user data. Zhang's key findings highlight the pervasive nature of information leakage in modern web browsers and the limitations of current defensive paradigms that primarily focus on preventing JavaScript execution.
- Client-Side Redirect Detection using
history.length: A straightforward yet powerful technique allows attackers to detect whether a specific URL on a target site results in a client-side redirect. By opening a new window, redirecting it to the target, then back to the attacker's origin, the attacker can inspect thehistory.lengthproperty to infer the presence of an intermediate redirect. This bypasses typical cross-origin access restrictions by ensuring both windows are same-origin at the point of inspection. - Server-Side Redirect Detection via Chromium URL Length Limits: Addressing the limitation of
history.lengthfor server-side redirects and theSameSite=Laxrestrictions onfetchAPI, Zhang unveils a novel technique. This method exploits the 2MB URL length limit in Chromium browsers and the preservation of URL fragments during server-side redirects. By crafting a URL with a fragment just shy of the limit, an attacker can detect if a server-side redirect causes the URL to exceed 2MB, leading the browser to renderabout:blank, which is then treated as same-origin. - Weaponizing HTML Injection for
SameSiteLeaks: Recognizing that many XS-Leak techniques relying onfetchoriframesare hindered bySameSitecookie protections (defaulting toLax), Zhang demonstrates how existing HTML injection vulnerabilities (where XSS is blocked by CSP or sanitizers) can be leveraged to achieve "SameSite leaks" without JavaScript. iframeGeolocation Leak: A striking example shows how aniframewith theallow="geolocation"attribute can bypass user consent mechanisms. If the parent (victim) site has previously been granted geolocation permission, an attacker-controllediframecan directly access the user's location without prompting the user again, as the permission is tied to the origin of the parent frame.- Status Code Detection using Nested Objects and Responsive Images: Zhang illustrates methods to detect whether a cross-origin resource returns a 200 (success) or 404 (not found) status code, even without JavaScript. This involves nesting
objecttags and observing which object is rendered, or employing responsive images within aniframeto trigger specific callbacks based on rendering conditions. These techniques effectively create a success/failure oracle for arbitrary URL endpoints.
Collectively, these findings demonstrate that the browser's internal state and rendering behaviors are rich sources of information leakage, requiring a more nuanced approach to web application security.
Technical Deep Dive
▶ Watch: Overcoming SameSite protections with HTML injection (8:40)
The core of XS-Leaks lies in understanding and exploiting subtle browser behaviors and legitimate APIs. Zhang meticulously details several techniques, showcasing how an attacker can infer sensitive information without traditional JavaScript execution.
Client-Side Redirect Detection
This technique capitalizes on the browser's history.length property and the ability to change the origin of a newly opened window.
- Attack Setup: The attacker's website opens a new window using
window.open()targeting a specific URL on the victim's site (the "leaky endpoint"). - Observation Point: The attacker wants to detect if this leaky endpoint performs a client-side redirect. For example, a search page might redirect to the main page if no results are found, or stay on the search results page if successful.
- Cross-Origin Barrier: Initially, the new window is cross-origin to the attacker's site. Due to browser security policies, the attacker cannot directly read properties like
history.lengthfrom a cross-origin window. - Origin Bypass: The key bypass involves redirecting the newly opened window back to the attacker's own controlled site. Once this second redirect occurs, both the attacker's original window and the new window are same-origin.
- Information Leakage: At this point, the attacker can safely read the
history.lengthproperty of the new window.
- If the target endpoint did not redirect, the history would contain two entries: the initial navigation to the target, and the subsequent redirect back to the attacker. Thus,
history.lengthwould be 2. - If the target endpoint did perform a client-side redirect, the history would contain three entries: initial navigation, target's redirect, and attacker's redirect back. Thus,
history.lengthwould be 3.
This simple difference provides a powerful success/failure oracle. Zhang notes that this technique was used in a real-world scenario to leak "team members device history connections, etc. in a popular VPN service," demonstrating its practical impact.
Server-Side Redirect Detection via Chromium URL Length Limits
While history.length works for client-side redirects, it fails for server-side redirects. Previous attempts to detect server redirects using the fetch API's maximum redirect limit were hampered by SameSite=Lax cookies, which prevent authenticated requests in a cross-origin context. Zhang introduces a more sophisticated technique leveraging a Chromium-specific behavior:
- Chromium URL Limit: Chromium-based browsers impose a maximum URL length limit of 2MB.
- URL Fragment Preservation: Crucially, when a server performs a redirect (e.g., a 302 redirect), the URL fragment (the part after the
#symbol) is preserved and appended to the new URL, even if the redirect response itself doesn't explicitly specify it. - Attack Mechanism:
- The attacker constructs a URL targeting a leaky endpoint on the victim's site. This URL includes a very long URL fragment, carefully crafted so that the total length of the URL is just under the 2MB limit.
- If the victim's server does not redirect, the URL length remains under 2MB, and the browser displays the cross-origin page as usual.
- If the victim's server does perform a redirect, and the new URL (potentially with additional path segments or query parameters) combined with the preserved long fragment now exceeds the 2MB limit.
- Oracle Condition: When the URL length exceeds 2MB in Chromium, the browser renders an
about:blankpage instead of the intended content. Critically,about:blankpages are treated as same-origin with the page that initiated their loading. - Detection: Because the
about:blankpage is same-origin, the attacker can now read properties likewindow.originor detect if a JavaScript error is thrown when trying to interact with the page. This provides a clear oracle:about:blank(same-origin, redirect occurred) vs. cross-origin page (redirect did not occur). This technique allows for detection of server-side redirects, even withSameSite=Laxcookies in play, as it doesn't rely on thefetchAPI.
SameSite Leaks through HTML Injection
With SameSite cookies defaulting to Lax, many traditional XS-Leak techniques relying on cross-origin requests that carry cookies are mitigated. Zhang argues that if a site has an HTML injection vulnerability (even if XSS is blocked by CSP or sanitizers), this can be weaponized to bypass SameSite protections and leak authenticated user state without JavaScript.
iframe Geolocation Leak
This is a particularly potent example of an HTML injection vulnerability.
- Vulnerability: The attacker can inject an
iframetag into the victim's page. - Permission Bypass: The
iframeis given theallow="geolocation"attribute. - Crucial Detail: When the JavaScript inside this
iframeattempts to accessnavigator.geolocation, the browser treats the permission request as originating from the parent frame's origin (the victim site). - Exploitation: If the victim site has previously granted geolocation permission to the browser, the attacker's
iframecan instantly access the user's precise geolocation data without any new user prompt. This bypasses the user consent mechanism entirely for previously trusted origins, directly leaking sensitive user data.
Status Code Detection with Nested Objects
This technique leverages the rendering behavior of HTML <object> tags based on the HTTP status code of their data attribute.
- Vulnerability: The attacker can inject HTML, specifically nested
<object>tags. - Mechanism: An outer
<object>tag is pointed to the leaky endpoint on the victim's site. An inner<object>tag is pointed to an attacker-controlled URL.
- If the outer object's
dataURL returns a 404 Not Found status code, the browser does not render the outer object. Instead, it renders its fallback content, which in this case is the inner object. The inner object (attacker-controlled) will then trigger a request to the attacker's server. - If the outer object's
dataURL returns a 200 OK status code, the browser renders the outer object, and the inner object (fallback) is not rendered. The attacker's server receives no request from the inner object.
- Oracle: By checking whether a callback (request) is received on their server, the attacker can determine if the target URL returned a 404 or a 200, effectively creating a status code oracle.
- CSP Challenge: Zhang acknowledges that CSP might block external objects, leading to the next technique.
Status Code Detection with Responsive Images
To circumvent CSP restrictions on objects, Zhang proposes an ingenious variant using responsive images within an iframe. This technique is still predicated on an existing HTML injection vulnerability.
- Setup: The attacker injects an
<object>tag pointing to the target URL, similar to the previous method. However, as its fallback content, it contains aniframe. iframeProperties: Thisiframeis given a specific width (e.g.,width="1000"pixels). Inside theiframe, an<img>tag uses thesrcsetattribute with media queries:srcset="attacker_callback_1.png 1000w, attacker_callback_2.png 1w".- Rendering Logic:
- If the outer object's
dataURL returns a 404 Not Found, the outer object is not rendered. Consequently, its fallback content, theiframe, is rendered. Because theiframehas a width of 1000 pixels, the browser's responsive image logic matches the1000wcondition insrcset, causingattacker_callback_1.pngto be requested by the browser. - If the outer object's
dataURL returns a 200 OK, the outer object is rendered. Its fallback content, theiframe, is not rendered. Therefore,attacker_callback_2.pngis requested (or no image from the iframe at all, depending on exact browser behavior and if the1wcondition is a fallback for non-rendering). The key is the difference in which callback is received.
- Brute-Forcing: This status code oracle can then be used to brute-force characters in search queries or other parameters, allowing an attacker to reconstruct sensitive information character by character or determine the existence of specific resources. For example, if a search API returns 200 for valid results and 404 for invalid, an attacker could test
"password=" + char + "*"to guess password prefixes.
These sophisticated techniques underscore that even without direct JavaScript execution, the rich and complex interactions within a web browser offer numerous avenues for subtle information leakage.
Demo / Proof of Concept
▶ Watch: Leaking status codes using responsive images & iframes (11:50)
While the talk did not feature a live, interactive demonstration, Zeyu Zhang provided clear conceptual Proof of Concept (PoC) code snippets and detailed explanations for each XS-Leak technique presented. Crucially, he mentioned that the client-side redirect detection technique using history.length was derived from a "full POC" that enabled the leakage of sensitive data—including "team members device history connections, etc."—from a popular VPN service. This real-world applicability underscores the practical impact of these vulnerabilities.
For each technical deep dive, Zhang walked through the exact HTML or JavaScript constructs required to initiate the attack, such as the window.open() calls for redirect detection, the structure of the long URL fragment for the Chromium URL limit exploit, the iframe with allow="geolocation" for the location leak, and the nested <object> and responsive <img> tags for status code detection. Although not a live demonstration, the clarity and specificity of these examples served as effective demonstrations of how these attacks function at a technical level. The speaker's emphasis on the real-world utility of the redirect detection further validated the severity of these seemingly subtle leaks.
Defensive Implications
▶ Watch: Summary: The future of client-side attack surfaces (13:00)
The rise of XS-Leaks necessitates a fundamental shift in defensive strategies for web applications. Traditional security measures focused on preventing XSS and CSRF, while still vital, are no longer sufficient to protect against these new classes of client-side information leakage. Defenders must adopt a more holistic and privacy-centric approach:
- Beyond XSS and CSP: Recognize that robust CSPs and diligent input sanitization, while effective against JavaScript injection, do not inherently protect against XS-Leaks. These attacks exploit legitimate browser APIs and behaviors, not code injection.
- Audit Redirects Carefully: Developers should be highly cautious about how their applications handle redirects, both client-side and server-side.
- Avoid unnecessary redirects, especially for sensitive operations.
- Ensure that redirect URLs do not inadvertently leak information through their structure or by triggering specific browser behaviors.
- Review the impact of URL fragments during redirects, as their preservation can be exploited.
- Strict
SameSitePolicies: WhileSameSite=Laxis the default, consider implementingSameSite=Strictfor highly sensitive cookies where cross-site requests are not expected, reducing the attack surface forSameSiteleaks. However, this often comes with usability trade-offs. iframeSandboxing and Permissions: When embeddingiframes, always apply the strictest possiblesandboxattributes to restrict their capabilities. Carefully review and minimize theallowattributes (e.g.,allow="geolocation") to prevent unintended permission inheritance or abuse. The principle of least privilege should be applied rigorously toiframepermissions.- Robust HTML Injection Mitigation: If HTML injection vulnerabilities exist, even without direct XSS, they must be treated with extreme severity. Attackers can weaponize injected HTML to create side channels, as demonstrated by the nested objects and responsive image techniques. All user-controlled input rendered as HTML must be thoroughly sanitized, not just for script tags but for any element or attribute that could alter rendering or trigger network requests.
- Information Minimization in APIs: Design APIs to return only the absolute minimum necessary information. Avoid endpoints that return different status codes (e.g., 200 vs. 404) or different content based on sensitive user state (e.g., "user exists" vs. "user does not exist") if these differences can be observed externally via side channels. Generic error messages are often preferable to specific ones that could serve as an oracle.
- Resource Loading and Error Handling: Pay close attention to how the browser loads resources and handles errors (e.g., 404s). Subtle differences in rendering or network requests can be exploited. Implement mechanisms to prevent external observation of these differences where sensitive information could be inferred.
- Client-Side State Management: Be aware of how client-side state (like
history.lengthor browser-granted permissions) can be manipulated or observed across origins under specific conditions. - Cross-Origin Isolation: Explore advanced browser features like
Cross-Origin-Opener-Policy (COOP)andCross-Origin-Embedder-Policy (COEP)to achieve cross-origin isolation, which can further restrict how documents interact and prevent certain types of XS-Leaks.
Ultimately, defending against XS-Leaks requires a proactive mindset, anticipating how legitimate browser functionalities can be twisted into privacy-violating side channels. Security audits should extend beyond traditional vulnerability classes to include a thorough analysis of potential information leakage vectors.
Key Takeaways
- Evolving Threat Landscape: Traditional XSS and CSRF are becoming less prevalent due to improved web frameworks and browser security, but XS-Leaks represent a new frontier of client-side attacks.
- Legitimate APIs as Attack Vectors: XS-Leaks exploit seemingly legitimate browser APIs and behaviors (e.g.,
history.length, URL length limits,iframepermissions, rendering logic) as side channels to infer sensitive user information. - Bypassing SameSite: HTML injection vulnerabilities can be weaponized to bypass
SameSitecookie protections, enabling "SameSite leaks" even when direct JavaScript execution is blocked by CSP or sanitizers. - Redirects as Oracles: Both client-side and server-side redirects can be detected through clever observation of browser state (e.g.,
history.length) or rendering behavior (e.g.,about:blankdue to URL length limits), acting as powerful success/failure oracles. - Subtle Information Leakage: Even without direct JavaScript execution, attackers can detect sensitive information like user geolocation (via
iframeallow="geolocation"if previously granted) or API status codes (via nested objects and responsive images) by observing rendering outcomes or network requests. - Shift in Defense Strategy: Defenders must move beyond solely preventing JavaScript execution and adopt a comprehensive approach that includes auditing redirect logic, strictly sandboxing
iframes, minimizing information disclosure in APIs, and enhancing HTML injection mitigations to account for subtle side-channel attacks.
About the Speaker(s)
Zeyu (Zayne) Zhang is a Computer Science student at the University of Cambridge. He is an active participant in Capture The Flag (CTF) competitions, playing with Water Pedor, part of Blue Water, and has competed at events like Defcon. Previously, Zayne worked as a security engineer at TikTok. Currently, he is freelancing with Electrovote and Cure53, a penetration testing company. In his (rare) free time, he is building Veos Labs, a security training company. His work focuses on understanding and mitigating advanced client-side web vulnerabilities.
Reviews
Dr. Zero (Offensive Security Researcher) — STRONG ACCEPT
Zhang brings real browser-internal heat here, proving that mitigating XSS doesn't mean your data is safe. The talk skips the high-level theory and drops highly specific, actionable primitives for cross-origin state inference, notably a brilliant abuse of Chromium's 2MB URL limit.
Heather Calloway (CISO) — SOLID
Web security has successfully mitigated a lot of traditional XSS, but attackers are moving to side-channel inferences called XS-Leaks. This research outlines how seemingly benign browser behaviors can be weaponized to bypass modern protections like SameSite cookies and CSP. It is a deep-dive for your application security team rather than a board-level briefing, but it highlights why our vulnerability management programs can't declare victory just because we use React.