<p>I have a flex application that needs the ability to generate and execute JavaScript. When I say this, I mean I need to execute raw JavaScript that I create in my Flex application (not just an existing JavaScript method)</p>

<p>I am currently doing this by exposing the following JavaScript method:</p>

<pre><code>function doScript(js){ eval(js);}
</code></pre>

<p>I can then do something like this in Flex (note: I am doing something more substantial then an alert box in the real Flex app):</p>

<pre><code>ExternalInterface.call("doScript","alert('foo'));
</code></pre>

<p>My question is does this impose any security risk, I am assuming it's not since the Flex and JasvaScript all run client side...</p>

<p>Is there a better way to do this?</p>

[{'answer_id': 20532, 'author': 'Darren Kopp', 'author_id': 77, 'author_profile': 'https://Stackoverflow.com/users/77', 'pm_score': 0, 'selected': False, 'text': "<p>As far as I know, and I'm definately not a hacker, you are completely fine. Really, if someone wanted to, they could exploit your code anyway clientside, but i don't see how they could exploit your server side code using javascript (unless you use server side javascript)</p>\n"}, {'answer_id': 20578, 'author': 'jsight', 'author_id': 1432, 'author_profile': 'https://Stackoverflow.com/users/1432', 'pm_score': 0, 'selected': False, 'text': "<p>I don't see where this lets them do anything that they couldn't do already by calling eval.  If there's a security hole being introduced here, I don't see it.</p>\n"}, {'answer_id': 20595, 'author': 'Funkatron', 'author_id': 2310, 'author_profile': 'https://Stackoverflow.com/users/2310', 'pm_score': 1, 'selected': False, 'text': "<p>This isn't inherently dangerous, but the moment you pass any user-provided data into the function, it's ripe for a code injection exploit. That's worrisome, and something I'd avoid. I think a better approach would be to only expose the functionality you <em>need</em>, and nothing more.</p>\n"}, {'answer_id': 20645, 'author': 'Theo', 'author_id': 1109, 'author_profile': 'https://Stackoverflow.com/users/1109', 'pm_score': 4, 'selected': True, 'text': '<p>There\'s no need for the JavaScript function, the first argument to <code>ExternalInterface</code> can be any JavaScript code, it doesn\'t have to be a function name (the documentation says so, but it is wrong).</p>\n\n<p>Try this:</p>\n\n<pre><code>ExternalInterface.call("alert(\'hello\')");\n</code></pre>\n'}, {'answer_id': 63603, 'author': 'ZebZiggle', 'author_id': 2587612, 'author_profile': 'https://Stackoverflow.com/users/2587612', 'pm_score': 0, 'selected': False, 'text': '<p>Remember also that the script actions are controlled by the "AllowScriptAccess" tag in the  statement. If the web page doesn\'t want these actions, they should not permit scripts to call out. </p>\n\n<p><a href="http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_16494" rel="nofollow noreferrer">http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_16494</a></p>\n'}, {'answer_id': 40553258, 'author': 'user2629253', 'author_id': 2629253, 'author_profile': 'https://Stackoverflow.com/users/2629253', 'pm_score': -1, 'selected': False, 'text': '<pre><code>ExternalInterface.call("eval", "alert(\'hello\');");\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/20510', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1638/']