views:

296

answers:

3

Hello,

is it possible to make a Flex-application to only run from my domain? So a user can't copy the .swf and start it locally.

+4  A: 

In a lot of cases this won't work because of the security model associated with the crossdomain.xml.

http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html

Say for example, I have a flex app that has a service call and login to my backend database (perhaps PHP and mysql). Unless I explicitly enable it in crossdomain.xml policy file the app will not be able to communicate with my server unless the swf file is directly loaded from my domain. If the app was local it would look to my server like localhost was trying to access my backend through the flex app. So by default this would not work unless an explicit rule was put in place in the crossdomain.xml to allow access from localhost. Likewise someone cannot simply put the swf on a different server and try to access from my server unless I add that remote server to the crossdomain.xml policy.

So back to your question. Obviously, this crossdomain.xml stuff doesn't really apply if your flex app is really simple and does not try to make service calls to a server. For example, if you have simple game that just loads and plays without additional server calls inside the flex game.

If you wanted to protect your app you could have a basic "phone home" process during the startup sequence that makes a very simple server call to your website. It doesn't have to be anything super complicated, just require a round trip service call in the start up of your app. Perhaps check for a simple key or string stored in a variable on the PHP side, and don't let the flex app run unless that key is valid. You could hardcode the expected key inside the actionscript. Or perhaps have a basic logger that tracks how many times the app is launched and store the count in a database or something. The main thing is do not let the app completely launch until this request to the server has returned a valid result.

If you have this in place then the crossdomain.xml policies will kick in and if someone downloads your swf it shouldn't work because it will try to make a call from localhost to your server. Or if they steal your app and host it on their site it shouldn't work either.

Gordon Potter
A: 

Do check out flash.System.Capabilities.playerType on LiveDocs as well.

Tahir Ahmed
+2  A: 

The simplest solution il probably to check the value of

Application.application.loaderInfo.url

on application startup (for example in the applicationComplete event) and match it with your web site domain.

Cosma Colanicchia