"Content-Security-Policy","frame-ancestors 'none'"不工作。

问题描述 投票:0回答:1

我有下面的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'");
    ...

我使用这个片段来测试我的应用程序。

    <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个回答
0
投票

Frame-ancestors CSP指令必须来自于childiframe.That将是一个新的框架。/myapp 响应。

如果你想换一种方式,在? /myapp/login/jwt 回复中应包括 frame-src 'none'; 而是

Frame-ancestors告诉谁都想用iframe。 如果允许他们这样做,并让孩子有能力控制这个。

© www.soinside.com 2019 - 2024. All rights reserved.