Spring mvc 如何使用spring安全性防止xss和xframe攻击
我希望防止我的网站受到xss和xframe攻击 但是我的英语还不够好,不知道该设置什么 请指导我,我还应该设置什么 我只是在Spring mvc 如何使用spring安全性防止xss和xframe攻击,spring-mvc,spring-security,Spring Mvc,Spring Security,我希望防止我的网站受到xss和xframe攻击 但是我的英语还不够好,不知道该设置什么 请指导我,我还应该设置什么 我只是在src/com/test/web/security 这是我的密码: package com.test.web.security; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration;
src/com/test/web/security
这是我的密码:
package com.test.web.security;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableWebSecurity
@Configuration
@ComponentScan
public class WebSecurityConfig extends
WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
// ...
.headers();
}
}
如果您只是指定与上面相同的代码,Spring Security应该自动添加所有相关的安全头。根据文件: 如果您使用的是SpringSecurity的Java配置,那么 默认情况下会添加默认的安全标头 此外: 一旦您指定了任何应该包含的标题,那么 这些标题将包括 请参阅本节中的详细信息和代码示例:
请使用以下代码作为示例
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/api/**").hasAnyRole("ADMIN","USER").and().httpBasic().and().headers().disable();
//.and().formLogin();
}
但是我使用owasp zap进行攻击,根据上面的评论,它仍然存在这些问题,Spring Security不会防御所有攻击。不过,它将添加HTTP头来防御xframe、XSRF和其他一些攻击向量。查看文档了解更多详细信息。我有相同的警告-使用Spring引导默认值,我仍然得到相同的OWASP ZAP警告。你能弄清楚你的安全性吗?Spring安全头将阻止IFRAME劫持和反射的XSS攻击,但不是普通的XSS攻击。XSS依赖于应用程序获取用户的输入并直接将其包含在页面的HTML中。如果用户在输入中提供了恶意JavaScript,则会执行该JavaScript,从而劫持当前用户的权限。XSS保护要求过滤恶意内容并始终转义用户提供的输入。对于第一种情况,请使用HDIV之类的库。第二,使用您使用的任何呈现机制的内置特性—JSP、Facelets等。