【发布时间】:2021-08-30 17:03:26
【问题描述】:
嘿 Stackoverflow 天才。我有一个问题给我带来了一些麻烦,我希望你能帮助我。我在使用 Spring Boot Webflux 的服务器代码中定义了内容安全策略。 CSP 被发送到客户端,可以在响应标头中看到。但是,CSP 似乎并未应用于该站点。这是配置:
/* http is a ServerHttpSecurity object */
http.headers().contentSecurityPolicy("default-src 'self'; script-src 'self'; img-src 'self';" +
"media-src 'self'; object-src 'self'; connect-src 'self'; worker-src 'none'; form-action 'self';" +
"frame-src 'none'; child-src 'none'; style-src 'self'; frame-ancestors 'none';")
.and()
.frameOptions().mode(XFrameOptionsServerHttpHeadersWriter.Mode.DENY);
这就是我在响应标头中看到的:
ache-control: no-cache, no-store, max-age=0, must-revalidate
connection: close
Content-Encoding: gzip
content-security-policy: default-src 'self'; script-src 'self'; img-src 'self';media-src 'self'; object-src 'self'; connect-src 'self'; worker-src 'none'; form-action 'self';frame-src 'none'; child-src 'none'; style-src 'self'; frame-ancestors 'none';
content-type: application/json
Date: Mon, 30 Aug 2021 16:33:28 GMT
expires: 0
pragma: no-cache
referrer-policy: no-referrer
transfer-encoding: chunked
Vary: Accept-Encoding
x-content-type-options: nosniff
x-frame-options: DENY
X-Powered-By: Express
x-xss-protection: 1 ; mode=block
应用其中一些设置时,应该会阻止我的网站在 i-frame 中加载,但即使标题包含这些值,i-frame 仍然可以加载它。此外,我还可以注入不安全的脚本和样式。
我正在使用最新版本的 Chrome 进行测试。我在响应标头中看到了 CSP,但它并没有阻止这些安全风险,这一事实告诉我我遗漏了一些东西。收到响应后,我需要采取什么步骤将 CSP 应用到前端?同样,这是一个 React 前端和一个 Java/Spring Boot 后端。以防万一,前端和后端是独立的项目。
提前感谢您抽出时间来帮助我。
【问题讨论】:
标签: reactjs spring-boot spring-webflux content-security-policy