|
2 | 2 |
|
3 | 3 | import static org.springframework.security.config.http.SessionCreationPolicy.STATELESS; |
4 | 4 |
|
| 5 | +import java.nio.charset.StandardCharsets; |
| 6 | +import java.util.regex.Pattern; |
| 7 | + |
| 8 | +import org.springframework.context.annotation.Bean; |
5 | 9 | import org.springframework.context.annotation.Configuration; |
6 | 10 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; |
7 | 11 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
8 | 12 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
| 13 | +import org.springframework.security.web.firewall.HttpFirewall; |
| 14 | +import org.springframework.security.web.firewall.StrictHttpFirewall; |
9 | 15 | import org.tdl.vireo.auth.service.VireoUserDetailsService; |
10 | 16 | import org.tdl.vireo.model.Role; |
11 | 17 | import org.tdl.vireo.model.User; |
|
18 | 24 | @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) |
19 | 25 | public class AppWebSecurityConfig extends AuthWebSecurityConfig<User, UserRepo, VireoUserDetailsService> { |
20 | 26 |
|
| 27 | + @Bean |
| 28 | + public HttpFirewall httpFirewall() { |
| 29 | + StrictHttpFirewall firewall = new StrictHttpFirewall(); |
| 30 | + Pattern allowed = Pattern.compile("[\\p{IsAssigned}&&[^\\p{IsControl}]]*"); |
| 31 | + firewall.setAllowedHeaderValues(header -> { |
| 32 | + String parsed = new String(header.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); |
| 33 | + return allowed.matcher(parsed).matches(); |
| 34 | + }); |
| 35 | + return firewall; |
| 36 | + } |
| 37 | + |
21 | 38 | @Override |
22 | 39 | protected void configure(HttpSecurity http) throws Exception { |
23 | 40 | // @formatter:off |
|
0 commit comments