我有以下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'
我想念什么?
答案 0 :(得分:0)
frame-ancestors CSP指令必须来自child / iframe。
那就是/myapp
响应。
如果您希望以其他方式进行操作,则在/myapp/login/jwt
响应中应添加frame-src 'none';
Frame-ancestors告诉谁想要对iem you 进行构架,并允许孩子控制它