tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

popup-from-initial-empty-sandboxed-document.window.js (1777B)


      1 // META: timeout=long
      2 // META: script=/common/utils.js
      3 // META: script=/common/dispatcher/dispatcher.js
      4 
      5 // Regression test for: https://crbug.com/1256822.
      6 //
      7 // From a sandboxed iframe allowing popups, scripts, and same-origin. Open a
      8 // popup using the WindowProxy of a new iframe that is still on the initial
      9 // empty document. Check that the sandbox flags are properly inherited.
     10 
     11 // Return true if the execution context is sandboxed.
     12 const isSandboxed = () => {
     13  try {
     14    // Setting document.domain in sandboxed document throw errors.
     15    document.domain = document.domain;
     16    return false;
     17  } catch (error) {
     18    return true;
     19  }
     20 }
     21 
     22 promise_test(async test => {
     23  // 1. Create a sandboxed iframe, allowing popups, same-origin and scripts.
     24  const iframe_token = token();
     25  const iframe_document = new RemoteContext(iframe_token);
     26  const iframe_url = remoteExecutorUrl(iframe_token);
     27  const iframe = document.createElement("iframe");
     28  iframe.sandbox = "allow-same-origin allow-scripts allow-popups";
     29  iframe.src = iframe_url;
     30  document.body.appendChild(iframe);
     31  assert_true(await iframe_document.execute_script(isSandboxed),
     32    "iframe is sandboxed");
     33 
     34  // 2. From the sandboxed iframe, create an empty iframe, and open a popup
     35  //    using it's WindowProxy. The popup must inherit sandbox flags.
     36  const popup_token = token();
     37  const popup_document = new RemoteContext(popup_token);
     38  const popup_url = remoteExecutorUrl(popup_token);
     39  iframe_document.execute_script((popup_url) => {
     40    let iframe = document.createElement("iframe");
     41    iframe.name = "iframe_name";
     42    document.body.appendChild(iframe);
     43    iframe_name.open(popup_url);
     44  }, [popup_url.href]);
     45  assert_true(await popup_document.execute_script(isSandboxed), "popup is sandboxed");
     46 });