我有下面的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'我遗漏了什么?
发布于 2020-05-28 17:52:00
frame-ancestors CSP指令必须来自子级/iframe。这将是/myapp响应。
如果您想以另一种方式完成此操作,则应该在/myapp/login/jwt响应中包含frame-src 'none';
框架祖先告诉任何想要iframe的人,如果他们被允许这样做,并给孩子控制这一点的能力。
https://stackoverflow.com/questions/61742763
复制相似问题