Kuboid
Open Luck·Kuboid.in
Black Hat2024
Open in YouTube ↗

The Hole in Sandbox: Escape Modern Web-Based App Sandbox From Site-Isolation Perspective

Black Hat1,665 views36:27over 1 year ago

This talk demonstrates techniques for escaping the sandbox of modern web-based applications by leveraging vulnerabilities in privileged JavaScript interfaces and IPC mechanisms. The research focuses on Chromium-based applications, including desktop apps using CEF and mobile browsers, to achieve remote code execution. The presenters show how to bypass site isolation and same-origin policy protections to inject arbitrary JavaScript and gain control over the underlying system. The session includes practical demonstrations of these exploits on Android and Windows platforms.

Escaping the Chromium Sandbox: Exploiting Privileged JavaScript Interfaces

TLDR: Modern web-based applications often rely on Chromium-based components like CEF or WebView to render content, but these components frequently expose privileged JavaScript interfaces that can be abused. By chaining renderer-level remote code execution with these interfaces, researchers can bypass site isolation and same-origin policy protections to achieve full sandbox escapes. This research highlights the critical need for developers to treat these bridges as high-risk attack surfaces rather than simple convenience features.

Web-based applications are everywhere. From desktop clients built on the Chromium Embedded Framework (CEF) to mobile browsers and app stores, the industry has standardized on Chromium to ensure consistent rendering across platforms. While this simplifies development, it also creates a massive, unified attack surface. If you are a researcher or pentester, you know that the sandbox is the primary barrier between a compromised renderer process and the host system. When that sandbox is bypassed, the game changes from a simple XSS to full system compromise.

The research presented at Black Hat 2024 by Bohan Liu and Haibin Shi from Tencent Security Xuanwu Lab exposes exactly how these sandboxes are being defeated. The core of the problem lies in the bridge between the web content and the host system. To make these apps functional, developers implement custom JavaScript interfaces that allow the web content to interact with native OS features. When these interfaces are poorly scoped or lack rigorous input validation, they become the primary vector for an escape.

The Mechanics of the Escape

At the heart of this research is the realization that a renderer-level remote code execution (RCE) is often just the first step. Once an attacker has code execution inside the renderer process, they are still constrained by the sandbox. However, the sandbox is not a monolithic wall. It relies on Inter-Process Communication (IPC) to request resources from the browser process.

The researchers demonstrated that by sending malicious IPC calls with crafted parameters, an attacker can trick the browser process into performing actions it shouldn't. This is particularly effective when the application exposes privileged APIs—such as those for installing apps or executing system commands—directly to the JavaScript environment.

Consider a scenario where an application uses a custom JavaScript interface to handle deep links. If the interface does not properly validate the input, an attacker can use path traversal to write files to arbitrary locations on the host system. By combining this with a way to execute those files, the attacker moves from the renderer to the host OS. The researchers showed that on Android, this can be achieved by abusing Intent handling, where a malicious web page triggers an intent that launches a privileged activity, effectively bypassing the intended security boundaries.

Technical Deep Dive: Hooking the Compiler

One of the most impressive techniques shown in the talk involves hooking the JavaScript compilation process itself. By targeting the CompileScript internal method within the V8 engine, an attacker can inject malicious code into the execution flow of a legitimate, privileged script.

When the browser attempts to compile a script, it generates a V8 string object. By hooking this process, the attacker can intercept the compilation and replace the legitimate source code with a payload. This is a surgical strike. Because the injection happens at the compilation stage, it bypasses many traditional runtime security checks. The researchers used this to demonstrate a full sandbox escape on Android, where they successfully injected code into a privileged context, allowing them to execute arbitrary commands on the device.

For those interested in the underlying mechanics of how Chromium handles these processes, the official Chromium documentation on Site Isolation provides the necessary context on why these boundaries exist and how they are intended to function.

Real-World Impact for Pentesters

If you are performing a security assessment on a desktop application that uses CEF or an Android app that relies on WebView, you should immediately map out every exposed JavaScript interface. Look for methods that accept file paths, URLs, or package names as arguments. These are your primary targets.

During an engagement, use tools like Frida to hook these interfaces and observe the arguments being passed. If you can control the input to a method that performs file I/O or process execution, you have a high-probability path to a sandbox escape. The OWASP Injection Prevention Cheat Sheet remains the gold standard for understanding how to sanitize these inputs, but in the context of native bridges, you must also consider the context of the IPC calls being made.

The researchers also highlighted that even when site isolation is enabled, it is often implemented partially. In many Android applications, multiple WebView instances share the same renderer process, meaning there is no true isolation between them. This is a critical finding for anyone testing multi-tenant or complex mobile applications.

Defensive Considerations

Defending against these attacks requires a shift in mindset. Developers must stop assuming that the JavaScript interface is only accessible by "trusted" code. Every interface should be treated as an untrusted input source.

  1. Strict Scoping: Only expose the absolute minimum set of APIs required for the application to function.
  2. Input Validation: Never pass raw strings from JavaScript to native code. Use strict allow-lists for any parameters that influence file paths or system commands.
  3. Immutable Code: Where possible, use signed or immutable code for privileged operations to prevent the kind of compilation-time injection described in this research.
  4. Patching: Keep your Chromium or WebView dependencies updated. Many of these escapes rely on known vulnerabilities that have been patched in newer versions of the underlying engine. For reference, tracking CVE-2016-9651 and similar historical issues provides a clear picture of how these vulnerabilities evolve over time.

The research from the Tencent team is a stark reminder that the sandbox is only as strong as the weakest bridge you build to it. As we continue to wrap native functionality in web-based interfaces, we are essentially building a highway for attackers to bypass the very security controls we rely on. Stop looking for the "perfect" sandbox and start looking for the holes in the bridges you've built.

Talk Type
research presentation
Difficulty
advanced
Category
web security
Has Demo Has Code Tool Released


Black Hat Asia 2024

44 talks · 2024
Browse conference →
Premium Security Audit

We break your app before they do.

Professional penetration testing and vulnerability assessments by the Kuboid Secure Layer team. Securing your infrastructure at every layer.

Get in Touch
Official Security Partner
kuboid.in