tor-browser

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

test_SubscriptLoaderSandboxEnvironment.js (1370B)


      1 let tgt = Cu.Sandbox(Services.scriptSecurityManager.getSystemPrincipal());
      2 
      3 Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
      4 registerCleanupFunction(() => {
      5  Services.prefs.clearUserPref("security.allow_eval_with_system_principal");
      6 });
      7 Services.scriptloader.loadSubScript("resource://test/environment_script.js", tgt);
      8 
      9 var bound = "";
     10 var tgt_bound = "";
     11 
     12 // Check global bindings
     13 try { void vu; bound += "vu,"; } catch (e) {}
     14 try { void vq; bound += "vq,"; } catch (e) {}
     15 try { void vl; bound += "vl,"; } catch (e) {}
     16 try { void gt; bound += "gt,"; } catch (e) {}
     17 try { void ed; bound += "ed,"; } catch (e) {}
     18 try { void ei; bound += "ei,"; } catch (e) {}
     19 try { void fo; bound += "fo,"; } catch (e) {}
     20 try { void fi; bound += "fi,"; } catch (e) {}
     21 try { void fd; bound += "fd,"; } catch (e) {}
     22 
     23 // Check target bindings
     24 for (var name of ["vu", "vq", "vl", "gt", "ed", "ei", "fo", "fi", "fd"])
     25    if (tgt.hasOwnProperty(name))
     26        tgt_bound += name + ",";
     27 
     28 
     29 // Expected subscript loader behavior with a Sandbox is as follows:
     30 //  - Lexicals occur on ExtensibleLexicalEnvironment of target
     31 //  - Everything else occurs on Sandbox global
     32 if (bound != "")
     33    throw new Error("Unexpected global binding set - " + bound);
     34 if (tgt_bound != "vu,vq,gt,ed,ei,fo,fi,fd,")
     35    throw new Error("Unexpected target binding set - " + tgt_bound);