【问题标题】:"Content-Security-Policy", "frame-ancestors 'none'" not working“Content-Security-Policy”、“frame-ancestors 'none'”不起作用
【发布时间】:2023-03-19 17:46:01
【问题描述】:

我有以下 java 过滤器来让 CSP 对我的 Angular 应用程序的每个响应进行处理。

public class FrameOptionsFilter implements Filter {

@Override
public void doFilter(ServletRequest request, ServletResponse servletResponse, final FilterChain filterChain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) servletResponse;
    response.setHeader("Content-Security-Policy", "frame-ancestors 'none'");
    ...

我使用这个 sn-p 来测试我的应用程序:

    <html>
     <head>
     <title>Clickjacking Test</title>
      </head>
       <body>
        <p>Website is vulnerable to clickjacking!</p>
        <iframe src="http://localhost:4200/myapp/" width="600" height="600"></iframe>
        </body>
    </html>

登录屏幕加载,一旦我登录,我仍然可以访问应用程序!

来自服务器的响应:

Request URL: https://localhost:4200/myapp/login/jwt
HTTP/1.1 200 OK
X-Powered-By: Servlet/3.1
Content-Security-Policy: frame-ancestors 'none'

我错过了什么?

【问题讨论】:

    标签: iframe content-security-policy x-frame-options


    【解决方案1】:

    frame-ancestors CSP 指令必须来自 child/iframe。 那将是/myapp 响应。

    如果您想以其他方式执行此操作,请在 /myapp/login/jwt 回复中包含 frame-src 'none'; 代替

    Frame-ancestors 告诉谁想要 iframe如果他们被允许这样做,并让孩子有能力控制它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-15
      • 2015-09-09
      • 2013-05-03
      • 2019-09-05
      • 2023-03-20
      • 2018-08-23
      • 2021-12-20
      相关资源
      最近更新 更多