Bael-4684-Prevent Cross-Site Scripting (XSS) in a Spring application-(new) (#10480)
* #bael-4684: add main source code * #bael-4684: add test * #bael-4684: add required dependencies
This commit is contained in:
committed by
GitHub
parent
1c773ba6f2
commit
7d5be17ce2
@@ -0,0 +1,25 @@
|
||||
package com.baeldung.xss;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
|
||||
@Configuration
|
||||
public class SecurityConf extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void configure(WebSecurity web) {
|
||||
// Ignoring here is only for this example. Normally people would apply their own authentication/authorization policies
|
||||
web.ignoring().antMatchers("/**");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.headers()
|
||||
.xssProtection()
|
||||
.and()
|
||||
.contentSecurityPolicy("script-src 'self'");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user