“内容安全政策”,“框架祖先“无””不起作用

时间:2020-05-12 02:30:12

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

我有以下Java过滤器,可以对Angular应用的每个响应使用CSP。

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'

我想念什么?

1 个答案:

答案 0 :(得分:0)

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

如果您希望以其他方式进行操作,则在/myapp/login/jwt响应中应添加frame-src 'none';

Frame-ancestors告诉谁想要对iem you 进行构架,并允许孩子控制它