Skip to content

Commit 6ee85f0

Browse files
committed
allow utf8 through spring security firewall
1 parent 9fe8730 commit 6ee85f0

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎src/main/java/org/tdl/vireo/config/AppWebSecurityConfig.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22

33
import static org.springframework.security.config.http.SessionCreationPolicy.STATELESS;
44

5+
import java.nio.charset.StandardCharsets;
6+
import java.util.regex.Pattern;
7+
8+
import org.springframework.context.annotation.Bean;
59
import org.springframework.context.annotation.Configuration;
610
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
711
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
812
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;
915
import org.tdl.vireo.auth.service.VireoUserDetailsService;
1016
import org.tdl.vireo.model.Role;
1117
import org.tdl.vireo.model.User;
@@ -18,6 +24,17 @@
1824
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
1925
public class AppWebSecurityConfig extends AuthWebSecurityConfig<User, UserRepo, VireoUserDetailsService> {
2026

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+
2138
@Override
2239
protected void configure(HttpSecurity http) throws Exception {
2340
// @formatter:off

0 commit comments

Comments
 (0)