【问题标题】:"Secure origin" other than HTTPS?HTTPS 以外的“安全来源”?
【发布时间】:2018-08-22 01:14:54
【问题描述】:

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

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

这个“比如 HTTPS”是怎么回事?除了 HTTPS 之外,还有其他“安全来源” 可以为网站提供服务吗?

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

【问题讨论】:

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


    【解决方案1】:

    简短回答:是的,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/

    这个铬页面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>

    【讨论】:

    • 很高兴了解 --unsafely-treat-insecure-origin-as-secure 标志,我可能需要在某些时候在本地环境中进行测试。非常翔实的答案,谢谢。 :D
    • --unsafely-treat-insecure-origin-as-secure 没有效果,除非 --user-data-dir 也提供了
    • @rwm 我可以在没有 --user-data-dir 的情况下使用它:
    【解决方案2】:

    通过执行以下操作,我成功绕过了 Chrome 使用 https 连接的要求。它与已接受答案中链接中的说明略有不同:

    Windows 10:

    • 在任务栏中,右键单击“Chrome”图标 > 右键单击​​“Google Chrome” > 选择“属性”
    • 在“Target:”字段中,在 final 之后添加标志 引号,像这样:

      "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --unsafely-treat-insecure-origin-as-secure=http://yourDomain.com

    (我不需要添加其他答案中指示的其他标志。)

    附加标签:Google Geolocation API 绕过 https

    【讨论】:

      猜你喜欢
      • 2012-07-13
      • 1970-01-01
      • 2015-09-30
      • 2011-04-06
      • 1970-01-01
      • 2019-04-02
      • 2015-12-04
      • 1970-01-01
      • 2017-07-27
      相关资源
      最近更新 更多