Security Sandbox Violation, can't connect to Server via Socket - actionscript-3

Before I start I should state I have read it all, I was following this, this and this (and more...) and still I cannot connect to our running server via Socket over the internet.
Here is what I try to in AS3:
var host :String = "192.168.2.11";
Security.allowDomain(host);
Security.allowInsecureDomain(host);
Security.loadPolicyFile("xmlsocket://" + host + ":" + "843");
// TTS server socket
_socket = new Socket();
_socket.addEventListener(Event.CLOSE, handleClose);
_socket.addEventListener(IOErrorEvent.IO_ERROR, handleError);
_socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleSecError);
_socket.addEventListener(ProgressEvent.SOCKET_DATA, handleIncomingData);
_socket.addEventListener(Event.CONNECT, handleConnect);
_socket.connect(host, 1337);
As you can see, the host is a local address, but that shouldn't matter as long as I am in this local network. And I am, since this does work from my IDE (FD4).
Also, the swf is on the same server as the application it tries to connect to, but on another port.
The policy file the server sends (we have tried both from port 843 and 1337) is the following:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" to-ports="*" />
</cross-domain-policy>
We can see from the log output of the server that this is really sent to the connecting socket. A null byte is of course sent after the xml data. And after that, the server closes the connection. However, it seems that Flash somehow does not like it, as "Error #2048" still appears after ~3 seconds.
We're really out of ideas here...

We managed to get it to work by including another tag:
<site-control permitted-cross-domain-policies="master-only"/>
It seems that this tag is necessary in order to get it to work. We could not get it to work without that tag, no matter which port we tried.
So the complete xml now looks like this in our case (it is of course easy to modify to fit any case):
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*" to-ports="*"/>
</cross-domain-policy>
It really is a shame that this line is not included in Adobe's own example (!!). I mean, it IS included in the example files, but not in the article. I don't want to know how many people were stuck at this stage because of that...

Related

AS3 Security error #2048 socket connection

I'm working in a company which creates a huge strategy game with ActionScript3.
I'm one of the developers here and have some issues with Socket Connections.
Socket works perfect when I use it in internal flash player or in firefox debug, it shows socket error #2048 when I'm trying to open the project with Google Chrome.
Here is the code which I use at first before trying to make a Socket Connection.
Security.allowDomain("*");
Security.allowInsecureDomain("*");
Security.loadPolicyFile("mydomain.com/crossdomain.xml");
And here is the content of crossdomain.xml file.
<cross-domain-policy>
<cross-domain-policy>
<allow-access-from domain="*"/>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*" to-ports="100-60000" secure="false"/>
</cross-domain-policy>
Then the connect function works to make a Socket Connection with server.
instance.host = host;
instance.port = port;
socket = new Socket(host, port); //Initializing the socket
Is there any problems with Server or the problem caused by Chrome?
If you had the same issue and found something useful please answer to this question.
I'm searching a solution for a few days, but nothing works.
If you are trying to launch this swf file from localhost, which is the usual case when debugging, you can add your swf's path to flash player's trusted locations.
This procedure is written here.
Also try with this simpler cross domain file.
<cross-domain-policy>
<allow-access-from domain="*"/>
</cross-domain-policy>

Flash Socket connection from SWF hosted by a browser

I am attempting to use TCP Socket from Flash ActionScript. I am using a standard example provided by Adobe. Here is the code:
// Load policy file from remote server.
Security.loadPolicyFile("http://" + serverURL + "/crossdomain.xml");
// Attempt to connect to remote socket server.
try {
msg("Trying to connect to " + serverURL + ":" + portNumber + "\n");
socket.connect(serverURL, portNumber);
} catch (error:Error) {
/*
Unable to connect to remote server, display error
message and close connection.
*/
msg(error.message + "\n");
socket.close();
}
My crossdomain.xml file located on port 80:
<cross-domain-policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.adobe.com/xml/schemas/PolicyFileSocket.xsd">
<allow-access-from domain="*" to-ports="*"/>
</cross-domain-policy>
When I load application, I see in my inspector that it accesses the policy file successfully. However Event.CONNECT is never called. I have tried opening various different ports on various domains including same domain with no luck. Tried different policy files.
What am I missing?
If the allowscriptaccess is false you won't be able to bypass that so what you are missing is the adobe policy server.
http://vvowproject.googlecode.com/svn-history/r41/trunk/server/flashpolicyd.py
On the server open port 843 then use this command
sudo ./flashpolicyd.py --file=crossdomain.xml --port=843
here is the crossdomain.xml
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="SOAPAction"/>
</cross-domain-policy>
This will definitely work, i tried it myself with your example.
This is what I know from using TCP/IP Sockets and XML. I've set up a Ruby server with a Flash client successfully, but want to know more about chat servers. I hope some of this is helpful.
You need a Daemon with Flash AS3. Here's the documentation.
http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000318.html
alt text http://www.ashcraftband.com/myspace/videodnd/daemonLil.jpg
To create a socket connection, you must create a server-side application to wait for the socket connection request and send a response to the SWF file. This type of server-side application can be written in a programming language such as Java, Python, or Perl. To use the XMLSocket class, the server computer must run a daemon that understands the protocol used by the XMLSocket class. The protocol is described in the following list:
• XML messages are sent over a full-duplex TCP/IP stream socket connection.
• Each XML message is a complete XML document, terminated by a zero (0) byte.
• An unlimited number of XML messages can be sent and received over a single XMLSocket connection.
Understanding the security changes in Flash Player 10
http://www.adobe.com/devnet/flashplayer/articles/fplayer10_security_changes_02.html
XML SECURITY POLICY
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="SOAPAction"/>
</cross-domain-policy>
FLASH CLIENT
Remember to set Publish Settings to Access Network Only.
SERVER
Open a separate port for security policy, and keep it running in the background.

Error message appear in a old running flash application during AMFPHP call

My app was working fine until today. The probleme is that each request to amfphp return an error message like :
Client.Error.Message Send
Fail to send
In fact, this message is the fault function I put in the caller.
<s:CallResponder id="tracefilm"/>
<trace:Trace id="traceFilm" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" result="traceMaked(event)" showBusyCursor="true"/>
Because I don't know how to find where the problem is... I'll try to view what happens thanks to firebug plugin of FF during execution time.
The solution is simple. I've just fixed this issue in a old streaming app (100% flash).
If you encountered the problem in a old app, you propably don't have the crossdomain.xml file in the root directory of the web server. See Adobe explanation for more details.
I found the solution thanks to firebug. In fact, during Flash loading, the browser tried to access to a file called crossdomain.xml. Of course, the server response was 404 for my part...
You just have to create crossdomain.xml in the server, and to add this piece of code inside :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
Now your application, like mine will works again.

Channel.Security.Error in Flex application

I have a Flex application running on several domains (HTTP). The application communicates with the server using, among other things, WSDL service that resides on HTTPS.
For reasons unknown (to me), sometimes I see a log entry that tells me something like this:
[FaultEvent fault=[RPC Fault faultString="Sikkerhetsfeil ved tilgang til URL-adresse" faultCode="Channel.Security.Error" faultDetail="Mål: DefaultHTTP"] messageId="D2B72EF4-65FD-4A36-6117-D4DC95E63E01" type="fault" bubbles=false cancelable=true eventPhase=2]
I managed to deduce from looking this error up on that it has something to do with SOAP calls.
I tried applying some extra entries to the crossdomain.xml based on this info, but it didn't really help.
The current content of the crossdomain.xml is as follows:
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*" secure="false"/>
<allow-http-request-headers-from domain="*" headers="*" secure="false"/>
</cross-domain-policy>
The most maddening thing is that this error only occurs very sporadically, and is not consistent in any immediately recognizable way.
Anyone? A clue as to why could this be happening?

Error Handling issues

Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation:
I don't get this error on my local host but I do when I upload it to my server. How
do I properly fix this in Flash CS4?
Check where you are pointing to for any external assets or data. More than likely you need a crossdomain.xml file that will say that it is okay for your server to access the data. To be clear, you need the crossdomain file where the assets are that you are pulling.
More information here: http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html
An example of a wide open crossdomain.xml file:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
You can specify a domain where the * is and list multiple allow-access-from nodes. You can also specify all subdomains on a domain by saying *.mydomain.com
To be clear, you do not want to go to production with the wide open example I have given, but it is something you can use to test out and make sure this is your problem. Once you verify this then you can restrict it to the appropriate levels.
Basically though you just create a file called crossdomain.xml and put this xml in it.
Make sure it is placed at the root of the server that the data or assets are being pulled from.