blocked by cors policy about CORS-RFC1918,或者local

2021-11-03 14:35:17

报错信息 has been blocked by CORS policy: The request client is not a secure context

the resource is in more-private address space `private`

之前用的好好的,突然就出错了。

我一猜就是google浏览器升级引起的问题,加深了安全机制。

但是我不知道怎么操作。

浪费了半天,终于找到解决办法了。

一开始的时间事再解决替换的js在chrome控制台监控网络的时候提示 

Failed to load response data: No content available beacase thie request was redirected

一直在上面费工夫解决问题了

其实操作正确与否,都会是这样的提示,记得看console里面的报错。解决了问题。


参考连接 blocked by cors policy about CORS-RFC1918

参考地址2 https://wicg.github.io/private-network-access/



問題描述

has been blocked by cors policy 

the request client is not a secure context 

and resource is in more-private address space private

1

2

3

解決方案

升級服務器端

Update 2021: A few months after I posted this question, 

the flag I referenced in my original answer was removed, 

and instead of disabling a security feature 

I was forced to solve the problem more satisfactorily.


Private Network Access (formerly CORS-RFC1918) is 

a specification that forbids requests 

from less private network resources to more private network resources. 

Like HTTP to HTTPS, or a remote host to localhost.


The ultimate solution was to add a self-signed certificate, 

and Access-Control-* headers, 

which enabled requests from my remote dev server 

to my localhost webpack-dev-server for assets.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

conf.https = {

  key: readFileSync('./.ssl/cert.key'),

  cert: readFileSync('./.ssl/cert.crt'),

  cacert: readFileSync('./.ssl/ca.crt'),

}


conf.headers = {

  'Access-Control-Allow-Private-Network': true,

  'Access-Control-Allow-Origin': '*',

}

1

2

3

4

5

6

7

8

9

10

屏蔽客戶端設置

chrome://flags/#block-insecure-private-network-requests



CORS-RFC1918

Private Network Access (formerly known as CORS-RFC1918) 

restricts the ability of websites to send requests to servers on private networks. 

It allows such requests only from secure contexts. 

The specification also extends the Cross-Origin Resource Sharing (CORS) protocol 

so that websites now have to explicitly request a grant from servers on private networks 

before being allowed to send arbitrary requests.

1

2

3

4

5

6



其它的解決方案

Private Network Access 【https://wicg.github.io/private-network-access/】,通過在MegaCorp 設置上做代理和控制。僅供參考,沒有驗證,希望有能力的同行來補充。


[^1] Chrome CORS error on request to localhost dev server from remote site

[^2] Chrome 安全策略 - 私有網絡控制(CORS-RFC1918)

[^3] Private Network Access update: Introducing a deprecation trial

————————————————

版权声明:本文为CSDN博主「MyFreeIT」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/MyFreeIT/article/details/120437772


  • 2021-04-15 10:10:00

    Puppeteer 系列踩坑日志—3—开启支持插件

    在使用puppeteer自动化的过程中,会发现其实开启的chrome往往自动禁用了插件功能,如果我们想在自动化测试的过程中,再去使用一些常用的插件提升效率(偷懒)的话,就行不通了,其实解决办法还是有的,我们今天就来讲解这个问题。

  • 2021-04-15 10:11:17

    Puppeteer拦截修改返回值

    page.setRequestInterception(true)拦截器的使用方法和场景 现附上Puppeteer的Api的链接https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md

  • 2021-04-15 10:32:18

    怎么给 headless chrome添加cookies

    In puppeter you have access to the session cookies through page.cookies(). So once you log in, you could get every cookie and save it in a json file:

  • 2021-04-15 10:51:21

    如何通过Devtools协议拦截和修改Chrome响应数据

    在日常研究中,我们经常碰到大量JavaScript代码,我们首先要深入分析才能了解这些代码的功能及具体逻辑。这些代码代码可能会被恶意注入到页面中,可能是客户送过来需要我们帮忙分析的脚本,也可能是我们的安全团队在网页上找到的引用了我们服务的某些资源。这些脚本通常代码量不大、经过混淆处理,并且我们总是需要经过多层修改才能继续深入分析。

  • 2021-04-19 10:54:39

    block和delegate的区别

    代理 可读性高 大部分可以属性 block 写的代码少 一般作为参数 通知 占用资源

  • 2021-04-19 11:00:23

    浅谈block和delegate的使用

    委托是协议的一种,顾名思义,就是委托他人帮自己去做事。委托是给一个对象提供机会对另一个对象中的变化做出反应或者影响另一个对象的行为。其基本思想是:两个对象协同解决问题,并且打算在广泛的情形中重用。委托指向另一个对象(即它的委托)的引用,并在关键时刻给委托发消息。消息可能只是通知委托发生了某件事情,给委托提供机会执行额外的处理,或者消息可能要求委托提供一些关键的信息以控制所发生的事情。委托的作用主要有两个,一个是传值,一个是传事件。

  • 2021-04-19 11:36:44

    iOS 组件实现方案

    什么才是好架构,为什么要组件,组件设计的优点