google-chrome - "Secure origin"不是HTTPS吗?

标签 google-chrome security https google-chrome-devtools

有时,我在Chrome Devtools中看到以下警告:
You should consider switching your application to a secure origin, such as HTTPS.
这是怎么回事,例如HTTPS?除了HTTPS之外,是否可以为网站提供“安全来源”?

我使用https没问题(我正在使用的所有网站上都启用了https)。这个问题纯粹出于好奇。

最佳答案

简短答案:是的,localhost是安全的来源。 Chrome浏览器还有一个命令行标志,用于将指定的HTTP端点视为安全:--unsafely-treat-insecure-origin-as-secure=http://a.test,http://b.test。因此,不仅是“HTTPS”。

更长的答案:诸如blob:wss:chrome-extension:之类的其他方案也可以视为安全上下文。 about:blank是一个常见示例,可能会有所不同,因为浏览器必须记住它是如何到达那里的。指向HTTPS页面但嵌入在HTTP页面中的iframe并不安全。

要确定浏览器如何看待所有这些,请检查window.isSecureContext的值。规范在这里:https://w3c.github.io/webappsec-secure-contexts/

这个 Chrome 页面https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins提供了一些上下文并链接到上面的规范。

例如,data: URL是不安全的,但是blob: URL是安全的。

const src = "<script>document.write(isSecureContext)</scr"+"ipt>";

a.src = `data:text/html,${src}`;

b.src = URL.createObjectURL(
  new Blob([src], {type:'text/html'}));
<p>data url is insecure
<iframe id=a width=100 height=25></iframe>

<p>blob url is secure
<iframe id=b width=100 height=25></iframe>

关于google-chrome - "Secure origin"不是HTTPS吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51958643/

相关文章:

css - css中的 `::content`是什么?

javascript - Node 8.0 新符号并在 Number.prototype.toLocaleString() 的符号后添加空格

git - 如何修复 .git 暴露的 firebase 漏洞

.htaccess - 在所有流量和所有页面上强制使用 HTTPS

html - IE兼容性, margin 问题

javascript - 无法通过javascript在chrome中提交表单

php - 在 .htaccess 文件中设置 open_basedir 会完全限制 PHP 脚本目录访问吗?

ios - 带有自签名 SSL 的 RESTful 服务

Android HTTPS 连接。

post - 无法打开流 : HTTP request failed! HTTP/1.0 400 错误请求 - OAuth 2.0 POST