Search completed in 1.23 seconds.
10 results for "components.utils.evalinsandbox":
Components.utils.evalInSandbox
nSandbox(text, sandbox). You can import functions or objects into the sandbox simply by assigning them to the sandbox object. For example: function double(n) { return n * 2; } // create new sandbox instance var mySandbox = new Components.utils.Sandbox("http://www.example.com/"); mySandbox.y = 5; // insert property 'y' with value 5 into global scope. ...
... value 5 into global scope. mySandbox.double = double; var result =
Components.utils.evalInSandbox("x = y + 2; double(x) + 3", mySandbox); console.log(result); // 17 console.log(mySandbox.x); // 7 Operations on objects you insert into this sandbox global scope do not carry privileges into the sandbox: mySandbox.foo = Components; // this will give a "Permission Denied" error
Components.utils.evalInSandbox("foo.classes", mySandbox); Optional Arguments You can optionally specify the JS version, filename, and line number of the code being evaluated. For instance: var x =
Components.utils.evalInSandbox( "let x = 1;", sandbox, "1.8", // "latest" is recognized as a special case "http://foo.com/mycode.js", 25 ); The above will execute code using JavaScript 1.8. Any exceptions raised by the...
Appendix D: Loading Scripts - Archive of obsolete content
the encoding of the overlay, and will execute as JavaScript version 1.8, based on the version specified in the script tag. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE overlay> <overlay id="script-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <script type="application/javascript;version=1.8" src="overlay.js"/> </overlay> evalInSandbox The
Components.utils.evalInSandbox method may be used to load arbitrary code into Components.utils.Sandbox objects. JavaScript files or URLs may be loaded in this manner by first retrieving their contents into memory using an XMLHttpRequest. This is the method used by Jetpack's securable module system to load nearly all executable code. Advantages Namespacing: Since scripts executed via evalInSandbox run in a defined namespace...
... the Sandbox let sandbox = Components.utils.Sandbox(context, { // Make properties of the context object available via the // script's global scope sandboxPrototype: context, // Wrap objects retrieved from the sandbox in XPCNativeWrappers. // This is the default action. ...
...// The following may be used instead at the top-level: // // let context = this if (Components.utils.getGlobalForObject) // Gecko 2.x var context = Components.utils.getGlobalForObject({}); else // Gecko 1.x context = {}.__parent__; loadScript("script.js", context); T...
Xray vision
Because code running in ...
... ' value: "Smith"' + '});' + 'Object.defineProperty(me, "middleName", {' + ' enumerable: true,' + ' configurable: true,' + ' get: function() { return "wait, is this really a getter?"; }' + '});'; var sandbox = Components.utils.Sandbox("https://example.org/");
Components.utils.evalInSandbox(sandboxScript, sandbox); // 1) trying to access properties in the prototype that have been redefined // (non-own properties) will show the original 'native' version // note that functions are not included in the output console.log("1) Property redefined in the prototype:"); console.log(sandbox.me.toSource()); // -> "({firstName:"Joe", address:{street:"Main Street"}, lastName:"Smith"})" // 2) tr...
Downloading JSON and JavaScript in extensions - Archive of obsolete content
loaded and injected into the extension. This usually happens because the extension is trying to keep some of its code fresh and dynamic, and the developers don't want to create a new version of the extension for each script change. In this case, JavaScript sandboxing should be used to isolate the downloaded JavaScript from the rest of the extension, and host application. Sandboxing is done using
Components.utils.evalInSandbox(). The JavaScript code is added to the sandbox along with any "safe" objects the JavaScript needs to interact. Sandboxing is not without its dangers and developers should read the sandboxing page carefully to make sure untrusted code is not leaked out of the sandbox. ...
Security best practices in extensions - Archive of obsolete content
e document holder, known as the docshell. frame.docShell.allowImages = false; frame.docShell.allowJavascript = false; frame.docShell.allowPlugins = false; There are more examples listed in the document listed above in this section. In certain circumstances you may want to run code in your extension, but you would like to give it restricted privileges. One of the best ways to do this is to use
Components.utils.evalInSandbox(). Note that objects passed into the sandbox are restricted, but objects that come back out from it are not. Refer to the document to find out how to avoid such pitfalls. For more information, refer to the evalInSandbox section. The sidebar: a use case The sidebar in Firefox is designed to hold both chrome (privileged) content and Web (nonprivileged) content, the latter being in the form of Web...
Index
and create a structured clone of it in a less-privileged scope. It returns a reference to the clone: 33 Components.utils.createObjectIn Add-ons, Developing Mozilla, Extensions, JavaScript, Reference, Reference(2), XPCOM:Language Bindings, XPConnect Components.utils.createObjectIn creates a new JavaScript object in the scope of the specified object's compartment. 34
Components.utils.evalInSandbox Add-ons, Developing Mozilla, Extensions, JavaScript, XPCOM:Language Bindings, XPConnect The evalInSandbox() function enables you to evaluate JavaScript code inside a sandbox you've previously created using the Components.utils.Sandbox constructor. 35 Components.utils.evalInWindow This function enables code running in a more-privileged JavaScript context to evaluate...
Components.utils.Sandbox
Use wantGlobalProperties instead. wantXrays A Boolean value indicating whether the sandbox wants Xray vision with respect to same-origin objects outside the sandbox. Default: true. "Xray vision" is exactly the s...
Language bindings
defined at js/xpconnect/idl/xpccomponents.idl.Components.utils.cloneIntoThis function provides a safe way to take an object defined in a privileged scope and create a structured clone of it in a less-privileged scope. It returns a reference to the clone:Components.utils.createObjectInComponents.utils.createObjectIn creates a new JavaScript object in the scope of the specified object's compartment.
Components.utils.evalInSandboxThe evalInSandbox() function enables you to evaluate JavaScript code inside a sandbox you've previously created using the Components.utils.Sandbox constructor.Components.utils.evalInWindowThis function enables code running in a more-privileged JavaScript context to evaluate a string in a less-privileged JavaScript context. The result is structured cloned back to the original context, unless it is ...
eval() - JavaScript
ate strings that will be later parsed as JSON. Pass data instead of code For example, an extension designed to scrape contents of web-pages could have the scraping rules defined in XPath instead of JavaScript code. Run code with limited privileges If you must run the code, consider running it with reduced privileges. This advice applies mainly to extensions and XUL applications, which can use
Components.utils.evalInSandbox for this. Examples Using eval In the following code, both of the statements containing eval() return 42. The first evaluates the string "x + y + 1"; the second evaluates the string "42". var x = 2; var y = 39; var z = '42'; eval('x + y + 1'); // returns 42 eval(z); // returns 42 Using eval to evaluate a string of JavaScript statements The following example uses eval() to evaluate...