【问题标题】:FF throwing Strict-Transport-Security for my tomcat HTTPSFF 为我的 tomcat HTTPS 抛出 Strict-Transport-Security
【发布时间】:2016-03-17 18:36:54
【问题描述】:

我在 Tomcat 上有一个 webapp。我有一个用于测试 SSL 的自签名证书。我所做的每个调用(get、ajax、css 和 javascript 导入)Firefox 都会抛出:

Strict-Transport-Security: The connection to the site is untrustworthy, so the specified header was ignored.

现在我已经为我的网站添加了 FF 例外,并且我的浏览器左上角有一个绿色的锁符号。我知道 HSTS 是什么,但我很确定我没有以任何方式设置它。在控制台中,我在响应标头中看到了这一点:

Strict-Transport-Security:"max-age=31536000 ; includeSubDomains"

那么,为什么 FF 说我的网站不可信,该标头是如何出现在我的响应中的,以及如何让这个错误消失?

更新 我已将我的自签名证书安装到我的 jdk cacerts 文件中。我可以使用 HttpsURLConnection 连接到站点,并且 request.isSecure() 返回 true,并且 request.getScheme() 返回 https,但 request.getProtocol() 返回 HTTP/1.1

【问题讨论】:

  • 哪个tomcat版本?你是否取消了tomcat附带的安全过滤器的注释?
  • 8.0.30 我取消了对 httpHeaderSecurity 过滤器和映射的注释,但这并没有什么区别。
  • 你是直接连接到tomcat还是通过反向代理(如apache或nginx...)?
  • 直接。这是我笔记本电脑上的开发服务器。
  • @mmaceachran 你找到解决方案了吗?我也面临同样的问题。

标签: java tomcat ssl protocols


【解决方案1】:

在我的应用程序中,我想使用 https 运行 tomcat,因此我遵循了此链接中提到的步骤:HTTPS in Tomcat

注意它说要修改 web.xml,我只是从 web.xml 中删除了以下内容:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>securedapp</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

Firefox 中的警告消失了。

在您的情况下,您可能还需要添加以下配置:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>unchecked</web-resource-name>
        <url-pattern>/static/*</url-pattern>
        <url-pattern>/webjars/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
</security-constraint>
<security-constraint>   
    <web-resource-collection>
        <web-resource-name>securedapp</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

在上述所有不需要安全约束的 url 配置中,您需要将它们添加到 &lt;transport-gurantee&gt;NONE&lt;/transport-guarantee&gt; 中的 &lt;url-pattern&gt;。希望它对我有所帮助。这是一个有用的链接:https://dzone.com/articles/understanding-web-security

【讨论】:

  • 我无法读取 tomcat xml,你能说一下这对服务器响应有什么影响,以便我可以将此答案移植到我的特定实现中吗?我正在使用 nginx,如果这有助于回答我的问题——我该如何使用这个答案?
猜你喜欢
  • 2019-03-07
  • 2016-07-12
  • 1970-01-01
  • 2016-12-22
  • 2021-11-07
  • 2015-04-06
  • 1970-01-01
  • 2014-02-23
  • 2018-04-05
相关资源
最近更新 更多