13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Security<br />

Dynamically g<strong>en</strong>erated code, such as that which is made wh<strong>en</strong> calling the eval() function, would pose a security risk<br />

if allowed within the application sandbox. For example, an application may inadvert<strong>en</strong>tly execute a string loaded from<br />

a network domain, and that string may contain malicious code. For example, this could be code to delete or alter files<br />

on the user’s computer. Or it could be code that reports back the cont<strong>en</strong>ts of a local file to an untrusted network<br />

domain.<br />

Ways to g<strong>en</strong>erate dynamic code are the following:<br />

Calling the eval() function.<br />

Using innerHTML properties or DOM functions to insert script tags that load a script outside of the application<br />

directory.<br />

Using innerHTML properties or DOM functions to insert script tags that have inline code (rather than loading a<br />

script via the src attribute).<br />

Setting the src attribute for a script tags to load a JavaScript file that is outside of the application directory.<br />

Using the javascript URL scheme (as in href="javascript:alert('Test')").<br />

Using the setInterval() or setTimout()function where the first parameter (defining the function to run<br />

asynchronously) is a string (to be evaluated) rather than a function name (as in setTimeout('x = 4', 1000)).<br />

Calling docum<strong>en</strong>t.write() or docum<strong>en</strong>t.writeln().<br />

Code in the application security sandbox can only use these methods while cont<strong>en</strong>t is loading.<br />

These restrictions do not prev<strong>en</strong>t using eval() with JSON object literals. This lets your application cont<strong>en</strong>t work with<br />

the JSON JavaScript library. However, you are restricted from using overloaded JSON code (with ev<strong>en</strong>t handlers).<br />

For other Ajax frameworks and JavaScript code libraries, check to see if the code in the framework or library works<br />

within these restrictions on dynamically g<strong>en</strong>erated code. If they do not, include any cont<strong>en</strong>t that uses the framework<br />

or library in a non-application security sandbox. For details, see “Restrictions for JavaScript inside AIR” on page 1035<br />

and “Scripting betwe<strong>en</strong> application and non-application cont<strong>en</strong>t” on page 1079. Adobe maintains a list of Ajax<br />

frameworks known to support the application security sandbox, at<br />

http://www.adobe.com/products/air/develop/ajax/features/.<br />

Unlike cont<strong>en</strong>t in the application security sandbox, JavaScript cont<strong>en</strong>t in a non-application security sandbox can call<br />

the eval() function to execute dynamically g<strong>en</strong>erated code at any time.<br />

Restrictions on access to AIR APIs (for non-application sandboxes)<br />

Adobe AIR 1.0 and later<br />

JavaScript code in a non-application sandbox does not have access to the window.runtime object, and as such this<br />

code cannot execute AIR APIs. If cont<strong>en</strong>t in a non-application security sandbox calls the following code, the<br />

application throws a TypeError exception:<br />

try {<br />

window.runtime.flash.system.NativeApplication.nativeApplication.exit();<br />

}<br />

catch (e)<br />

{<br />

alert(e);<br />

}<br />

The exception type is TypeError (undefined value), because cont<strong>en</strong>t in the non-application sandbox does not<br />

recognize the window.runtime object, so it is se<strong>en</strong> as an undefined value.<br />

Last updated 6/6/2012<br />

1073

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!