Home > syntax error > eval in sandbox syntax error

Eval In Sandbox Syntax Error

Contents

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site eval syntax error at line 1 (' unexpected About Us Learn more about Stack Overflow the company Business Learn more about

Eval Syntax Error Python

hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join javascript eval syntax error the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Is It Possible to what is javascript sandbox Sandbox JavaScript Running In the Browser? up vote 104 down vote favorite 57 I'm wondering if it's possible to sandbox JavaScript running in the browser to prevent access to features that are normally available to JavaScript code running in an HTML page. For example, let's say I want to provide a JavaScript API for end users to let them define event handlers to be run

Javascript Sandbox Browser

when "interesting events" happen, but I don't want those users to access the properties and functions of the window object. Am I able to do this? In the simplest case, let's say I want to prevent users calling alert. A couple of approaches I can think of are: Redefine window.alert globally. I don't think this would be a valid approach because other code running in the page (i.e. stuff not authored by users in their event handlers) might want to use alert. Send the event handler code to the server to process. I'm not sure that sending the code to the server to process is the right approach because the event handlers need to run in the context of the page. Perhaps a solution where the server processes the user defined function and then generates a callback to be executed on the client would work? Even if that approach works are there better ways to solve this problem? javascript browser sandbox share|improve this question asked Oct 12 '08 at 6:17 Walter Rumsby 4,46633036 add a comment| 15 Answers 15 active oldest votes up vote 44 down vote Google Caja is a source-to-source translator

for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of eval php this site About Us Learn more about Stack Overflow the company Business Learn eval js more about hiring developers or posting ads with us Code Review Questions Tags Users Badges Unanswered Ask Question _

Eval Jquery

Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask http://stackoverflow.com/questions/195149/is-it-possible-to-sandbox-javascript-running-in-the-browser a question Anybody can answer The best answers are voted up and rise to the top Sandbox or safely execute eval up vote 17 down vote favorite 1 In a large project of mine, I've run into a situation where a client might need to run evaluated JavaScript code. I know, it makes me cringe too. One option is to manually parse it, http://codereview.stackexchange.com/questions/49253/sandbox-or-safely-execute-eval but for future flexibility, I would like to evaluate the code safely. Everything I've seen and researched says, NO. Ah, the nay-sayers. This is my attempt to sandbox the eval: jsFiddle Can you shoot holes in it and try and break it? I should wrap it in a try so it doesn't throw ugly errors, but beyond that, tell me where I have gone awry. /*************************************** * Senica Gonzalez (senica@gmail.com) * This is an attempt to sandbox an eval * in javascript using an iframe. * Test it and let me know if you * can break it. ***************************************/ window.addEventListener("message", function(event){ $('#result').text(event.data.eval); console.log(event.data.scope1); console.log(event.data.scope2); }, false); test = 'do I exist in the window?'; var input = $('[name=toeval]'); input.on('change', function(){ var val = $(this).val(); var code = btoa('\ <\/head>\ \ <' + 'script>\ var party_size = 10;\ window.parent.postMessage({\ eval: eval('+val+'),\ }, "*");\ <\/script' + '>\ <\/body>\ <\/html>'); var frame = $(''); var sandbox = $('#sandbox'); sandbox.html(frame); }); I have been unsuccessful at accessing the parent document variables, or being able to do anything obnoxious other than to my self within the sandbox. javascript security sandbox share|

iframe and the results are very encouraging. Sandbox.eval() I'm currently developing a templating system in JavaScript and ran into a problem with scope. The problem is that my template scripts have access to all of the global (window) object's properties and methods. I don't http://dean.edwards.name/weblog/2006/11/sandbox/ want this. I want my template scripts to run in a separate, closed environment. Template scripts shouldn't be able to address anything in the browser window. This could potentially lead to disaster. Basically, I want the following code to work: sandbox.eval("alert('Hello!')"); // => Hello! try { var goodbye = "Goodbye!"; sandbox.eval("alert(goodbye)"); // => ERROR! } catch (error) { alert("ERROR!"); } The second eval should fail because goodbye is defined in syntax error the global scope but not in the templating environment. A standard eval would work as the code is evaluated in the same scope that goodbye is defined. So I hacked around with an iframe and eval for a couple of hours and came up with this: // create an