【发布时间】:2018-03-19 06:41:54
【问题描述】:
我正在尝试使用 Scala 代码在 Play 框架类型安全服务器中实现 HSTS。
我已使用以下行更新了 application.config 文件:
play.filters.enabled += "play.filters.headers.SecurityHeadersFilter"
play.filters.headers.frameOptions = "DENY"
play.filters.https.strictTransportSecurity="max-age=31536000;includeSubDomains; preload"
所以,当我在邮递员中执行 URL 时添加这个:https://www.mywebsite.com,我希望在标题栏中看到:
content-length: 85
content-type: text/html; charset=utf-8
request-time: 2
x-frame-options: DENY
strict-transport-security: max-age=15552000; preload
这些内容长度、类型和时间已经到来,但是这些严格的传输参数并没有反映在 postman 中的 headers 响应中,因为配置文件中的代码更改。
除了上面这行代码,我什至还在 app.config 中添加了这行代码:
https {
strictTransportSecurity = "max-age=31536000; includeSubDomains"
redirectStatusCode = 308
}
但这些更改对响应标头也没有影响。
简而言之,我期望的是,如果我在 git bash 中为我的网站使用 curl,我会看到与我在 Facebook 中看到的相似:
curl --head https://www.facebook.com
x-frame-options: DENY
strict-transport-security: max-age=15552000; preload
x-content-type-options: nosniff
当我输入 https://www.mywebsite.com 时,我的 URL 的方式相同,我需要查看:
strict-transport-security: max-age=15552000; preload
在标题响应列中,但我没有看到这个。
谁能指出我在哪里出错了。我是 HSTS 和 Scala 以及安全任务的新手。
我尝试在 App.config 文件中添加
play.filters.enabled += "play.filters.https.RedirectHttpsFilter"
play.filters.https.redirectEnabled = true
play.filters.enabled += "play.filters.headers.SecurityHeadersFilter"
play.http.forwarded.trustedProxies=["0.0.0.0/0", "::/0"]
play.filters.https.strictTransportSecurity = "max-age=31536000;
includeSubDomains; preload"
play.filters.https.redirectStatusCode = 301
但没有进入标题响应。我还应该在哪里更改 playframework 中的代码以将其显示在标题中。
【问题讨论】:
-
@users 谁能帮我解决这个问题
-
您的问题需要改进。您的代码块格式错误,包括可能在或可能不在实际配置中的换行符,包括不相关的信息(整个位置部分),包括两个不同的 Strict-Transport-Security 标头(一个带有分号 - 一个没有)然后说你只看到一些未格式化的邮递员输出,而没有说明你做了什么来得到它,然后是类似的不相关的、未格式化的 curl 输出。您的 add_header 的基本语法看起来不错,但我不知道您的设置,为什么这与 Scala 或 AWS 有关,或者为什么您认为这不起作用,所以无能为力。
-
@BarryPollard,感谢您的 cmets。!!!现在我已经编辑了我面临的问题,你能帮我看看吗?
标签: scala amazon-web-services ssl nginx hsts