Skip to content
XSS Write-up Advanced

Yet Another Google Caja bypasses hat-trick

Google Caja, a sandbox for untrusted JavaScript, failed to account for newer ECMAScript features such as async functions, async generators and dynamic import, each of which exposed a constructor or import mechanism that ran code outside the sandbox. An attacker could therefore execute arbitrary JavaScript in the context of a site that embedded Caja, escaping the intended isolation.

Michał Bentkowski Follow

Published on blog.bentkowski.info

The original lives on blog.bentkowski.info

We do not hold its text, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely Caja's parser and rewriter did not recognise newer ECMAScript constructs (async function, async generator and dynamic import), so their constructors or import calls were not replaced with sandboxed versions.

Impact

An attacker could run arbitrary JavaScript outside the Caja sandbox on any site that relied on Caja to contain untrusted code, potentially reaching the embedding origin's data.

What the attacker needed

A site that embeds Caja to sandbox untrusted code; attacker can supply JavaScript that Caja processes

The fix

Caja was fixed by always parsing and rewriting the input JavaScript with SES and Caja so that only a correctly understood subset of the language is accepted.

How it was found

  1. Open the Caja Playground and enter code that uses the async function constructor to run a test alert.
  2. Cajole the code and observe that the alert is not prefixed with the sandbox message, showing the sandbox was bypassed.
  3. Repeat with the async generator constructor and with a dynamic import of a data URL, each time seeing the unprefixed alert.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Caja is a tool that lets a website run code from strangers safely, by rewriting it so it cannot touch the page's private data. The researcher found that newer JavaScript syntax was not handled by Caja's rewriting, so a short piece of code could still reach the browser's real functions. That let the stranger's code run as if it were the website's own code.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More by Michał Bentkowski

View all

15 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.