HTTPS之外的"安全起源"?

Ske*_*ets 6 security https google-chrome google-chrome-devtools

有时我会在Chrome Devtools中看到此警告:

You should consider switching your application to a secure origin, such as HTTPS.

这个"如HTTPS"有什么用?是否有"安全的起源" 不是HTTPS,你可以成为一个网站用?

我使用https没有问题(我已经在我正在处理的所有网站上启用了它).这个问题纯粹是出于好奇.

Jos*_*Lee 8

简短回答:是的,localhost是一个安全的来源。Chrome 也有一个命令行标志来将指定的 HTTP 端点视为安全:--unsafely-treat-insecure-origin-as-secure=http://a.test,http://b.test. 所以它不仅仅是“HTTPS”。

更长的答案:其他方案,例如blob:, wss:, 和chrome-extension:也可以被视为安全上下文。about:blank是一个可以变化的常见示例,因为浏览器必须记住它是如何到达那里的。和iframe指向HTTPS页面,而是嵌入HTTP页面,会很不安全。

要确定浏览器对这一切的看法,请检查 的值window.isSecureContext。规范在这里:https : //w3c.github.io/webappsec-secure-contexts/

这个 Chromium 页面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'}));
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)