在Chrome中禁用同一来源政策

JavaScript

JimEva

2020-03-09

有什么方法可以禁用Google Chrome浏览器的同源策略

第255篇《在Chrome中禁用同一来源政策》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

26个回答
前端凯 2020.03.09

On a Windows PC, use an older version of Chrome and the command will work for all you guys. I downgraded my Chrome to 26 version and it worked.

小小神奇 2020.03.09

Try going to this page and disabling the domain security policy for your website domain.

chrome://net-internals/#hsts
逆天猿理查德 2020.03.09

For OSX, run the following command from the terminal:

open -na Google\ Chrome --args --disable-web-security --user-data-dir=$HOME/profile-folder-name

This will start a new instance of Google Chrome with a warning on top.

路易EvaSam 2020.03.09

this is an ever moving target.... today I needed to add another flag to get it to work: --disable-site-isolation-trials

OS X: open /Applications/Google\ Chrome.app --args --user-data-dir="/var/tmp/Chrome_dev_2" --disable-web-security --disable-site-isolation-trials

Sam神奇A 2020.03.09

On Linux- Ubuntu, to run simultaneously a normal session and an unsafe session run the following command:

google-chrome  --user-data-dir=/tmp --disable-web-security
Tom蛋蛋 2020.03.09

There is a Chrome extension called CORS Toggle.

Click here to access it and add it to Chrome.

After adding it, toggle it to the on position to allow cross-domain requests.

阿飞小卤蛋 2020.03.09

for mac users:

open -a "Google Chrome" --args --disable-web-security --user-data-dir

and before Chrome 48, you could just use:

open -a "Google Chrome" --args --disable-web-security
阿飞A飞云 2020.03.09

在Windows 10上,以下操作将起作用。

<<path>>\chrome.exe --allow-file-access-from-files --allow-file-access --allow-cross-origin-auth-prompt
斯丁小宇宙 2020.03.09

您可以简单地使用此Chrome扩展名Allow-Control-Allow-Origin

只需单击扩展图标即可根据需要打开或关闭启用跨资源共享

小宇宙神乐GO 2020.03.09
chromium-browser --disable-web-security --user-data-dir=~/ChromeUserData/
JinJin乐逆天 2020.03.09

仅适用于MAC用户

open -n -a /Applications/Google\ Chrome.app --args --user-data-dir="/tmp/someFolderName" --disable-web-security
斯丁理查德 2020.03.09

不要这样! 您正在打开帐户进行攻击完成此操作后,任何第三方网站都可以开始向其他网站(您已登录的网站)发出请求。

而是运行本地服务器。就像打开外壳/终端/命令行并键入一样简单

cd path/to/files
python -m SimpleHTTPServer

然后将浏览器指向

http://localhost:8000

如果发现它太慢,请考虑此解决方案

更新资料

人们对这个答案持否定态度,应该在这里继续投票,对这个答案也持否定态度不知道为什么我的答案如此之低,而这里的答案是投票最高的答案。

正在向攻击敞开大门。现在,您通过npm远程或本地包含在站点中的每个第三方脚本都可以上载数据或窃取凭据。您正在做不需要做的事情。建议的解决方案并不难,只需30秒,就不会让您遭受公开攻击。当更好的事情如此简单时,为什么选择让自己变得脆弱?

告诉人们禁用安全性就像告诉您的朋友不要打开前门和/或门垫下的钥匙一样。当然,赔率可能会很低,但是如果确实被盗,如果没有被迫入境的证明,他们可能会很难获得保险。同样,如果禁用安全性,则只不过是在禁用 安全性当您可以简单地在不禁用安全性的情况下解决问题时,这样做是不负责任的。如果您不能因为禁用安全而被某些公司解雇,我会感到惊讶。

猴子Near 2020.03.09
路易Gil 2020.03.09

如果您在Linux上使用Google Chrome,则可以使用以下命令。

google-chrome  --disable-web-security
十三梅 2020.03.09

对于Selenium Webdriver,在这种情况下,您可以让Selenium用适当的参数(或“开关”)启动Chrome。

 @driver = Selenium::WebDriver.for(:Chrome, { 
       :detach => false,
       :switches => ["--disable-web-security"]
    })
樱Harry 2020.03.09

您可以使用称为“ Allow-Control-Allow-Origin:*”的chrome插件...它使它变得非常简单,并且运行良好。 在这里检查:*

Chrome扩展

阳光Itachi村村 2020.03.09

I find the best way to do this is duplicate a Chrome or Chrome Canary shortcut on your windows desktop. Rename this shortcut to "NO CORS" then edit the properties of that shortcut.

in the target add --disable-web-security --user-data-dir="D:/Chrome" to the end of the target path.

your target should look something like this:

Update: New Flags added.

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir="D:/Chrome"

在此处输入图片说明

乐米亚 2020.03.09

使用当前最新的chrome版本(79.0.3945.130(正式版本)(64位)),使其在我的测试中起作用的唯一方法是使用以下标志启动chrome(将D:\ temp更改为您喜欢的方式) 。此解决方案将chrome作为测试的沙箱启动,并且不会影响主要的chrome配置文件:

--disable-site-isolation-trials --disable-web-security --user-data-dir =“ D:\ temp”

在Windows中,单击开始按钮,然后复制并粘贴以下内容:

chrome.exe  --disable-site-isolation-trials --disable-web-security --user-data-dir="D:\temp"
JinJin小卤蛋 2020.03.09

在Mac终端上尝试此命令-

open -n -a "Google Chrome" --args --user-data-dir=/tmp/temp_chrome_user_data_dir http://localhost:8100/ --disable-web-security 

它会打开另一个具有禁用安全性的chrome实例,并且不再存在CORS问题。另外,您不再需要关闭其他Chrome实例。将localhost URL更改为您的URL。

Jim西门 2020.03.09

对于Windows ...在桌面上创建Chrome快捷方式。
右键单击>属性>快捷方式
编辑“目标”路径:

"C:\Program Files\Google\Chrome\Application\chrome.exe" --args --disable-web-security

(将“ C:.... \ chrome.exe”更改为您的Chrome所在的位置)。

etvoilà:)

逆天Gil 2020.03.09

对于Windows用户:

我认为这里接受的解决方案的问题是,如果您已经打开Chrome并尝试运行它,它将无法正常工作。

但是,在研究此问题时,我遇到了有关“超级用户”的帖子,是否可以同时运行带有和不带有Web安全性的Chrome?

基本上,通过运行以下命令(或使用该命令创建快捷方式并通过该命令打开Chrome)

chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security

您可以在保持其他“安全”浏览器实例打开并正常运行的同时,打开一个新的“不安全” Chrome实例。 重要提示C:/Chrome dev session每次打开窗口时都删除/清除文件夹,因为第二次--disable-web-security将不起作用。因此,您无法保存所做的更改,然后使用再次打开它作为第二个不安全的Chrome实例--disable-web-security

StafanDavaid 2020.03.09

编辑3:似乎该扩展名不再存在...这些天通常为了避开CORS,我用单独的目录设置了另一个版本的Chrome,或者我将Firefox与https://addons.mozilla.org/zh-CN/ firefox / addon / cors-everywhere /代替。

编辑2:我不能再使它始终如一地工作。

编辑:我刚好在另一天尝试使用另一个项目,它停止工作。卸载并重新安装扩展后,已对其进行了修复(以重置默认值)。

原始答案:

我不想重新启动Chrome并禁用我的网络安全性(因为我在开发时正在浏览),却偶然发现了该Chrome扩展程序。

Chrome网上应用店Allow-Control-Allow-Origin:*
(https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=zh-CN)

基本上,这是一个小拨动开关,用于启用和禁用Allow-Access-Origin-Control检查。对于我的工作非常适合我。

Me无敌 2020.03.09

对于使用Chrome版本60.0.3112.78(解决方案经过测试并正常工作的日期)且至少直到今天的2019年1月19日(版本71.0.3578.98)的Windows用户并不需要关闭任何Chrome实例。

  1. 在桌面上创建快捷方式
  2. Right-click on the shortcut and click Properties
  3. Edit the Target property
  4. Set it to "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir="C:/ChromeDevSession"
  5. Start chrome and ignore the message that says --disable-web-security is not supported!

BEWARE NOT TO USE THIS PARTICULAR BROWSER INSTANCE FOR BROWSING BECAUSE YOU CAN BE HACKED WITH IT!

Mandy小卤蛋凯 2020.03.09

对于Windows

  1. 打开开始菜单
  2. 输入windows+ R或打开“运行”
  3. 执行以下命令:

    chrome.exe --user-data-dir="C://Chrome dev session" --disable-web-security
    

对于Mac

  1. 前往终端
  2. 执行以下命令:

    open /Applications/Google\ Chrome.app --args --user-data-dir="/var/tmp/Chrome dev session" --disable-web-security
    

新的停用了网络安全功能的Chrome浏览器应打开,并显示以下消息:

在此处输入图片说明

逆天L 2020.03.09

似乎以上解决方案均未真正起作用。-禁用网络安全是近年来铬版本不再支持。

Allow-Control-Allow-Origin:*-chrome扩展程序部分解决了该问题。仅当您的请求使用GET方法且没有自定义HTTP标头时,它才有效。否则,Chrome将发送OPTIONS HTTP请求作为飞行前请求。如果服务器不支持CORS,它将以404 HTTP状态代码响应。插件无法修改响应HTTP状态代码。因此chrome将拒绝此请求。chrome插件无法根据当前chrome扩展API修改响应HTTP状态代码。而且,您也无法对XHR发起的请求进行重定向。

不确定Chrome为什么使开发人员的生活如此艰难。它阻止了所有可能的方式来禁用XSS安全检查,即使是出于开发目的,这也是完全不必要的。

经过几天的努力和研究,一种解决方案对我来说是完美的:使用corsproxy您在此处有两个选择:1.使用[ https://cors-anywhere.herokuapp.com/] 2.在本地框中安装corsproxy:npm install -g corsproxy

[2018年6月23日更新]最近我正在开发SPA应用程序,需要再次使用corsproxy。但是似乎github上的corsproxy都不能满足我的要求。

  • 出于安全原因,需要它在防火墙内运行。所以我不能使用https://cors-anywhere.herokuapp.com/
  • 它必须支持https,因为chrome会阻止https页面中的非https ajax请求。
  • 我需要在nodejs上运行。我不想维护其他语言堆栈。

因此,我决定使用nodejs开发自己的corsproxy版本。实际上非常简单。我已将其作为要点在github上发布。这是源代码要点:https : //gist.github.com/jianwu/8e76eaec95d9b1300c59596fbfc21b10

  • 它在纯Node.js代码中,没有任何其他依赖
  • 您可以在http和https模式下运行(通过在命令行中传递https端口号),要运行https,您需要生成cert和key并将它们放在webroot目录中。
  • 它还用作静态文件服务器
  • 它还支持飞行前OPTION请求。

要启动CORSProxy服务器(http端口8080):节点static_server.js 8080

访问代理: http:// host:8080 / http://www.somesite.com

JinJin米亚 2020.03.09

是的 对于OSX,打开终端并运行:

$ open -a Google\ Chrome --args --disable-web-security --user-data-dir

--OSX上的Chrome 49+需要--user-data-dir

对于Linux运行:

$ google-chrome --disable-web-security

另外,如果您尝试出于开发目的(例如AJAX或JSON)访问本地文件,也可以使用此标志。

-–allow-file-access-from-files

对于Windows,请进入命令提示符并进入Chrome.exe所在的文件夹,然后键入

chrome.exe --disable-web-security

那应该禁用相同的原始策略,并允许您访问本地文件。

更新:对于Chrome 22+,您将看到一条错误消息,内容为:

您正在使用不受支持的命令行标志:--disable-web-security。稳定性和安全性将受到损害。

但是,您可以在开发时忽略该消息。

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android