Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross Domain Websocket connection causing a NS_ERROR_DOM_SECURITY_ERR

I am trying to connect to a websocket on server.domain.com from trial.domain.com

NS_ERROR_DOM_SECURITY_ERR in Firefox:

"[Exception... "Security error" code: "1000" nsresult: "0x805303e8 (NS_ERROR_DOM_SECURITY_ERR)" location: "https://trial.domain.com/home Line: 454"]"

when I am trying to make a WebSocket Connection:

try {
  if (window['MozWebSocket'] !== undefined) {
    socket = new MozWebSocket('ws://server.domain.com/chat');
  } else {
    socket = new WebSocket('ws://server.domain.com/chat');
  }
  trails = 0;
} catch(err){
  trials++;
}
like image 701
Sameer Segal Avatar asked Oct 08 '22 00:10

Sameer Segal


1 Answers

This happens by Browsers that is applying security policy that prevents of use any access to external domain that the page is hosted it self.
This occurs in scenarios when you are trying to get important connections from SSL area to non SSL and another domain (don't know if same domain will solve the problem) - that is your case. But there is more of possible scenarios of this.

This is browser related error, and it is browser who throw this error, and there is no problem with connection it self.

You have to host your WebSockets server under same domain as the http server. If that is not possible, there is few ways you can go:

  1. If software is for inhouse use and settings in browsers can be done for use, then you can disable cross-domain security policies:
    • Firefox, under "about:config" set s"ecurity.fileuri.strict_origin _policy" to "false".
    • Chrome, run with flag "--allow-file-access-from-files"
  2. If you have access to DNS settings of your domain, you can create sub forwarder and it will look like you are connecting to the same domain. Not sure about this option on practice, but it looks well.
like image 118
moka Avatar answered Oct 10 '22 14:10

moka