fix #547: secure VM deployment behind HTTPS proxy
This commit is contained in:
@@ -11,7 +11,7 @@ public record BackofficeProperties(
|
||||
Ai ai
|
||||
) {
|
||||
|
||||
public record Security(String adminUser, String adminPassword) {
|
||||
public record Security(String adminUser, String adminPassword, boolean requireHttps) {
|
||||
}
|
||||
|
||||
public record Token(int maxDays) {
|
||||
|
||||
@@ -14,9 +14,19 @@ import org.springframework.security.web.SecurityFilterChain;
|
||||
public class SecurityConfig {
|
||||
|
||||
@Bean
|
||||
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
SecurityFilterChain securityFilterChain(
|
||||
HttpSecurity http,
|
||||
BackofficeProperties properties
|
||||
) throws Exception {
|
||||
if (properties.security().requireHttps()) {
|
||||
http.requiresChannel(channel -> channel.anyRequest().requiresSecure());
|
||||
}
|
||||
|
||||
return http
|
||||
.csrf(csrf -> csrf.ignoringRequestMatchers("/mcp/messages", "/mcp/*/messages"))
|
||||
.headers(headers -> headers.httpStrictTransportSecurity(hsts -> hsts
|
||||
.includeSubDomains(true)
|
||||
.maxAgeInSeconds(31_536_000)))
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers("/css/**", "/js/**", "/webjars/**").permitAll()
|
||||
.anyRequest().authenticated())
|
||||
|
||||
Reference in New Issue
Block a user