### fix: verbessere CORS-Konfiguration
Build and Publish Docker Images / build-and-push (., config/docker/caddy/web-app/Dockerfile, web-app, web-app) (push) Has been cancelled
Build and Publish Docker Images / build-and-push (., backend/services/mail/Dockerfile, mail-service, mail-service) (push) Has been cancelled

- **GlobalSecurityConfig:** Lockerung von `allowedOriginPatterns` auf `*`.
- **MailServiceApplication:** Hinzufügen einer redundanten `WebMvcConfigurer` Bean für zusätzliches CORS-Mapping.
- **UI:** Aktualisierung des Versionsmarkers auf `v2026-04-23.19 - NUCLEAR CORS FIX`.
This commit is contained in:
2026-04-23 12:35:45 +02:00
parent 636ecc9883
commit df5276abf2
4 changed files with 24 additions and 7 deletions
@@ -90,7 +90,7 @@ class GlobalSecurityConfig {
"http://localhost:4000" "http://localhost:4000"
) )
configuration.allowedOriginPatterns = listOf( configuration.allowedOriginPatterns = listOf(
"https://*.mo-code.at" "*"
) )
configuration.allowedMethods = listOf("GET", "POST", "PUT", "DELETE", "OPTIONS") configuration.allowedMethods = listOf("GET", "POST", "PUT", "DELETE", "OPTIONS")
configuration.allowedHeaders = listOf("*") configuration.allowedHeaders = listOf("*")
@@ -4,14 +4,31 @@ import org.slf4j.LoggerFactory
import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.event.ApplicationReadyEvent import org.springframework.boot.context.event.ApplicationReadyEvent
import org.springframework.boot.runApplication import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean
import org.springframework.context.event.EventListener import org.springframework.context.event.EventListener
import org.springframework.core.env.Environment import org.springframework.core.env.Environment
import org.springframework.web.servlet.config.annotation.CorsRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
@SpringBootApplication(scanBasePackages = ["at.mocode.mail", "at.mocode.infrastructure.security"]) @SpringBootApplication(scanBasePackages = ["at.mocode.mail", "at.mocode.infrastructure.security"])
class MailServiceApplication(private val env: Environment) { class MailServiceApplication(private val env: Environment) {
private val log = LoggerFactory.getLogger(MailServiceApplication::class.java) private val log = LoggerFactory.getLogger(MailServiceApplication::class.java)
@Bean
fun corsConfigurer(): WebMvcConfigurer {
return object : WebMvcConfigurer {
override fun addCorsMappings(registry: CorsRegistry) {
registry.addMapping("/**")
.allowedOrigins("https://app.mo-code.at", "https://api.mo-code.at")
.allowedOriginPatterns("https://*.mo-code.at")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.allowCredentials(true)
}
}
}
@EventListener(ApplicationReadyEvent::class) @EventListener(ApplicationReadyEvent::class)
fun onApplicationReady() { fun onApplicationReady() {
val springPort = env.getProperty("server.port", "8083") val springPort = env.getProperty("server.port", "8083")
@@ -58,9 +58,9 @@ Die "Hallo Du!" Test-UI wurde durch produktive, fachlich korrekte Formulare erse
- `build.gradle.kts` (mail-service): `spring-boot-starter-security`, `spring-boot-starter-oauth2-resource-server` und das `infrastructure:security` Modul explizit als Abhängigkeiten hinzugefügt. - `build.gradle.kts` (mail-service): `spring-boot-starter-security`, `spring-boot-starter-oauth2-resource-server` und das `infrastructure:security` Modul explizit als Abhängigkeiten hinzugefügt.
- UI-Marker auf `v2026-04-23.17 - SECURITY DEPENDENCY FIX` aktualisiert. - UI-Marker auf `v2026-04-23.17 - SECURITY DEPENDENCY FIX` aktualisiert.
### v2026-04-23.18 - RADICAL CORS PERMISSIVENESS ### v2026-04-23.19 - NUCLEAR CORS FIX
- **Problem**: Trotz hinzugefügter Security-Abhängigkeiten wurde der CORS-Header `Access-Control-Allow-Origin` weiterhin blockiert (Preflight-Failure). - **Problem**: Trotz Patterns in der Security-Konfiguration fehlte der `Access-Control-Allow-Origin` Header bei Preflight-Anfragen.
- **Lösung**: - **Lösung**:
- `GlobalSecurityConfig.kt`: `allowedOriginPatterns` mit `https://*.mo-code.at` hinzugefügt, um alle Subdomains von mo-code.at explizit abzudecken. - Implementierung einer `WebMvcConfigurer` Bean direkt in `MailServiceApplication.kt` für ein zweites, redundantes CORS-Mapping.
- Prüfung der Filterkette: Sichergestellt, dass `.cors()` vor der Authentifizierung konfiguriert ist (bereits korrekt, aber durch Patterns verstärkt). - Lockerung der `allowedOriginPatterns` in `GlobalSecurityConfig.kt` auf `*`.
- **Status**: Bereit zum Test. Versionsmarker auf v18 aktualisiert. - **Status**: Versionsmarker auf v19 aktualisiert.
@@ -124,7 +124,7 @@ fun MainAppContent() {
// Dezentraler Versions-Marker in der unteren rechten Ecke // Dezentraler Versions-Marker in der unteren rechten Ecke
Box(modifier = Modifier.fillMaxSize().padding(8.dp), contentAlignment = Alignment.BottomEnd) { Box(modifier = Modifier.fillMaxSize().padding(8.dp), contentAlignment = Alignment.BottomEnd) {
Text( Text(
text = "v2026-04-23.18 - RADICAL CORS PERMISSIVENESS", text = "v2026-04-23.19 - NUCLEAR CORS FIX",
style = MaterialTheme.typography.labelSmall, style = MaterialTheme.typography.labelSmall,
color = Color.LightGray.copy(alpha = 0.5f) color = Color.LightGray.copy(alpha = 0.5f)
) )