javascript IE10 上的 WebSocket 出现 SecurityError

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15114279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 23:33:08  来源:igfitidea点击:

WebSocket on IE10 giving a SecurityError

javascriptwebsocketinternet-explorer-10

提问by EldredB

I am currently developing a website under IE10 (on Windows 8), using WebSockets in JavaScript. It runs fine under Firefox 18 and Chrome 25, but on IE10 I get a SecurityError when I establish the connection.

我目前正在 IE10(在 Windows 8 上)下开发一个网站,在 JavaScript 中使用 WebSockets。它在 Firefox 18 和 Chrome 25 下运行良好,但在 IE10 上,当我建立连接时出现 SecurityError。

What I am doing seems pretty straghtforward :

我在做什么似乎很直接:

websocket = new WebSocket('wss://hello.dev.mydomain.net');

But IE doesn't like it :

但 IE 不喜欢它:

SCRIPT5022: SecurityError 

The script is on "https://test.dev.mydomain.net" (not the real address obviously).

该脚本位于“ https://test.dev.mydomain.net”(显然不是真实地址)。

What bothers me is that if I just double-click the file on my local computer (e.g. file://...) it just works. Even worse: if I use fiddlerto monitor HTTP traffic... it also works. Whereas there seems to be no connection at all without fiddler, as detailed in the API's specs. (See below.)

让我烦恼的是,如果我只是双击本地计算机上的文件(例如 file://...),它就可以正常工作。更糟糕的是:如果我使用fiddler来监控 HTTP 流量......它也可以工作。而在没有 fiddler 的情况下似乎根本没有任何联系,如 API 规范中所述。(见下文。)

Judging by websocket spec, the exception should also appear on Chrome/Firefox... but it does not. So I doubt it has anything related to HTTP/HTTPS. In any case, I am using a wsS socket on a httpS page... Moreover: when I replace the wss address by another valid server found on an online example, it works.

根据websocket 规范判断,Chrome/Firefox 上也应该出现异常......但它没有。所以我怀疑它与 HTTP/HTTPS 有什么关系。无论如何,我在 httpS 页面上使用 wsS 套接字......此外:当我用在线示例中找到的另一个有效服务器替换 wss 地址时,它可以工作。

I don't know if this is relevant, but the IP from test.dev.mydomain.net is 10.14.x.x where hello.dev.mydomain.net is 194.247.x.x. I don't know if it could trigger some kind of security on IE only...

我不知道这是否相关,但是 test.dev.mydomain.net 的 IP 是 10.14.xx,其中 hello.dev.mydomain.net 是 194.247.xx 我不知道它是否会触发某种安全仅在 IE 上...

One more thing: I have a certificate for *.dev.mydomain.net, IE does not seems to have problems with it. The script originally resides on a server called my.name.dev.mydomain.net, but since I am accessing it from another URL (I got a redirect since we first thought it could have been some kind of Same Origin Policy issue), I don't see how it could matter. At least I hope it does not...

还有一件事:我有 *.dev.mydomain.net 的证书,IE 似乎没有问题。该脚本最初驻留在名为 my.name.dev.mydomain.net 的服务器上,但由于我从另一个 URL 访问它(我得到了重定向,因为我们首先认为它可能是某种同源策略问题),我不明白这有什么关系。至少我希望它不会......

Any idea is welcomed.

欢迎任何想法。

EDIT: adding the sites to the trusted zone does not work either.

编辑:将站点添加到受信任区域也不起作用。

采纳答案by EldredB

Well, my question wasn't that successful, so I'll post the "workaround" I found.

好吧,我的问题没有那么成功,所以我会发布我找到的“解决方法”。

I got another address for the website, in 194.247..too. This, magically, solved it. Guess IE doesn't like mixing local and external stuff and watches the IP.

我在 194.247 中获得了该网站的另一个地址。. 也。这神奇地解决了它。猜猜 IE 不喜欢混合本地和外部内容并观看 IP。

Anyways, I hope this may come in handy to anyone who's got the same issue.

无论如何,我希望这对遇到相同问题的任何人都可以派上用场。

If you have a solution to solve the "real" issue by configuring IE, let me know :)

如果您有通过配置 IE 来解决“真正”问题的解决方案,请告诉我:)

Cheers,

干杯,

回答by Georgii Ivankin

It looks like IE throws a SecurityError if you're trying to open a websocket on a local (intranet)domain. To overcome this, you may disable IE's automatic algorithm for recognizing local sites. This can be done in Tools > Internet Options > Security > Local Intranet > Sites.

如果您尝试在本地(内联网)域上打开 websocket,则 IE 似乎会引发 SecurityError 。为了克服这个问题,您可以禁用 IE 用于识别本地站点的自动算法。这可以在Tools > Internet Options > Security > Local Intranet > Sites.

intranet detection settings

内网检测设置

Uncheck all checkboxes (or only a particular one, if you know how exactly your domain did end up in intranet ones).

取消选中所有复选框(或仅选中一个特定的复选框,如果您知道您的域最终在 Intranet 中的确切情况)。

Note that IE uses (among other things) its proxy settings to determine local sites: if your domain is listed as excluded from proxying in proxy settings, then it will probably be treated as intranet one. This is why WebSockets work if you enable Fiddler: it modifies IE proxy settings and thus the list of intranet sites changes.

请注意,IE 使用(除其他外)其代理设置来确定本地站点:如果您的域在代理设置中被列为从代理中排除,那么它可能会被视为 Intranet 站点。这就是启用 Fiddler 时 WebSockets 工作的原因:它会修改 IE 代理设置,从而更改 Intranet 站点列表。

回答by lmiguelmh

I had this problem in Windows7/IE11 afterapplying a security patch. For Windows10/Edge is the same story.

应用安全补丁后,我在 Windows7/IE11 中遇到了这个问题。对于 Windows10/Edge 也是一样。

As this is a local websocket (ws://localhost) you have to add ws:\\localhost\to Internet Explorer configurations (Tools > Internet Options > Security > Local Intranet > Sites > Advanced).

由于这是一个本地 websocket (ws://localhost),您必须添加ws:\\localhost\到 Internet Explorer 配置(工具 > Internet 选项 > 安全 > 本地 Intranet > 站点 > 高级)。

IE11 local intranet sites configuration

IE11本地内网站点配置

In Windows 10/Microsoft Edgeyou will find this configuration in Control Panel > Internet Options.

Windows 10/Microsoft Edge 中,您将在控制面板 > Internet 选项中找到此配置。

UPDATE

更新

The address of your webapp (https://test.dev.mydomain.net) must be added to the local intranet zonetoo. Notethat in the image the webapp address should be added.

您的 web 应用程序的地址 ( https://test.dev.mydomain.net) 也必须添加到本地 Intranet 区域请注意,在图像中应添加 webapp 地址。

回答by Rudolf Dvoracek

Browsers has a websocket limitation. For example Internet Explorer has default limit of websocket connections set to 6 per host header name. the same limitation is set for WinForms WebBrowser component.

浏览器有 websocket 限制。例如,Internet Explorer 将每个主机头名称的 websocket 连接的默认限制设置为 6 个。WinForms WebBrowser 组件也有同样的限制。

The solution is to add values under key Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_WEBSOCKET_MAXCONNECTIONSPERSERVERin registry. Just add DWORD value with executable name , for example iexplore.exe (or your application executable name if you use Web browser component) and set value from range 2..128

解决方案是在注册表中的 Computer \HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_WEBSOCKET_MAXCONNECTIONSPERSERVER项下添加值。只需添加具有可执行名称的 DWORD 值,例如 iexplore.exe(或您的应用程序可执行名称,如果您使用 Web 浏览器组件)并设置范围为 2..128 的值

Second option how to solve SecurityException is to create multiple subdomains.

如何解决 SecurityException 的第二个选项是创建多个子域。

回答by Lokesh

The client hostname/IP Address should be same as server IP/Hostname thats listening to otherwise you would get the above error.

客户端主机名/IP 地址应与正在侦听的服务器 IP/主机名相同,否则您将收到上述错误。

1) Make sure whether server hostname configured to listen at IP/localhost etc andif not explicitly specify the hostname ast server

1) 确保服务器主机名是否配置为侦听 IP/localhost 等,如果没有明确指定主机名 ast 服务器

2) use the same hostname in the client. THis will solve the issue. It worked for me...

2) 在客户端使用相同的主机名。这将解决问题。它对我有用...

回答by blackening

In addition to making sure that the internet zone is not localhost (as in above answers), ensure that if https is used, then wss should be used.

除了确保互联网区域不是本地主机(如上面的答案),确保如果使用 https,则应使用 wss。

This is not an issue in other browsers, but IE is abit more finicky.

这在其他浏览器中不是问题,但 IE 有点挑剔。

enter image description here

在此处输入图片说明

回答by DoronG

I had the same issue at one of my customer's environment. It turned out that they had a proxy configuration that did not allow the connection to the WebSocket endpoint directly and did not support the WebSocket protocol. The temporary solution was to disable using the proxy and everything started working. The long term solution is to edit the proxy's configuration (.pac file) to exclude the address of the WebSocket endpoint.

我在我的一个客户环境中遇到了同样的问题。原来他们有一个代理配置,不允许直接连接到WebSocket端点,也不支持WebSocket协议。临时解决方案是禁用代理,一切都开始工作。长期解决方案是编辑代理的配置(.pac 文件)以排除 WebSocket 端点的地址。

To disable the proxy, go to: Internet Explorer Options > Connections tab > LAN settings button > un-check Automatically detect settings.

要禁用代理,请转到:Internet Explorer 选项 > 连接选项卡 > LAN 设置按钮 > 取消选中自动检测设置。

Hope this helps someone.

希望这可以帮助某人。

回答by NurAlDin

I encountered the error (although it did not say the SCRIPT5022 part, rather it just reports "ScriptError"). I got around the issue by clicking on "Trusted Sites" and then adding the machine hosting the remote websocket. Note, to add to trusted sites,

我遇到了错误(虽然它没有说 SCRIPT5022 部分,而只是报告了“ScriptError”)。我通过单击“受信任的站点”然后添加托管远程 websocket 的机器解决了这个问题。请注意,要添加到受信任的站点,

  • I had to supply the address without the "ws://" part (like just mymahcine.mydomain.com)

  • I had to uncheck the box that says "Require server verification https:// " option.

  • After I was done adding the domain, I re-checked the box "Require server verification (https://). I would recommend everyone to do the same. Unchecking the box is only a workaround to add sites that don't begin with https (rather ws:// in my case)
  • 我必须提供没有“ws://”部分的地址(就像 mymahcine.mydomain.com)

  • 我不得不取消选中“需要服务器验证 https://”选项的框。

  • 添加完域后,我重新选中了“需要服务器验证 (https://)”框。我建议每个人都这样做。取消选中该框只是添加不以https(而不是 ws:// 在我的情况下)