Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.careerseekers.apientrypoint.config

import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.reactive.CorsWebFilter
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource


@Configuration
class CorsConfig {

@Value("\${services.frontend.local}")
private lateinit var frontendLocalHost: String

@Value("\${services.frontend.production}")
private lateinit var frontendProductionHost: String

@Value("\${services.frontend.productionPattern}")
private lateinit var frontendProductionHostPattern: String

@Bean
fun corsWebFilter(): CorsWebFilter {
val corsConfig = CorsConfiguration().apply {
addAllowedOrigin(frontendLocalHost)
addAllowedOrigin(frontendProductionHost)
Comment on lines +26 to +27
Copy link

Copilot AI Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using addAllowedOrigin() with dynamic origins can be a security risk if the environment variables contain wildcard values like '*'. Consider using addAllowedOriginPattern() for better control or validate that the origins are specific URLs.

Suggested change
addAllowedOrigin(frontendLocalHost)
addAllowedOrigin(frontendProductionHost)
addAllowedOriginPattern(frontendLocalHost)
addAllowedOriginPattern(frontendProductionHost)

Copilot uses AI. Check for mistakes.
addAllowedOriginPattern(frontendProductionHostPattern)

allowedMethods = listOf("GET", "POST", "PUT", "DELETE", "OPTIONS")
allowedHeaders = listOf("Content-Type", "Authorization", "Accept", "Origin", "X-Requested-With")
allowCredentials = true
}

val source = UrlBasedCorsConfigurationSource()
source.registerCorsConfiguration("/**", corsConfig)

return CorsWebFilter(source)
}
}
4 changes: 4 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ services:
events-service: ${EVENTS_SERVICE_URI}
mail-service: ${MAIL_SERVICE_URI}
file-service: ${FILE_SERVICE_URI}
frontend:
local: ${LOCAL_HOST}
production: ${PRODUCTION_HOST}
productionPattern: ${PRODUCTION_HOST_PATTERN}

server:
port: 8080