Skip to content

Commit e904071

Browse files
committed
Set CORS origin properly
Modify CSRF cookie
1 parent be17799 commit e904071

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

core/src/main/kotlin/net/osable/core/SecurityConfiguration.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,20 @@ class SecurityConfiguration {
3535
.anyRequest().authenticated()
3636

3737
}.csrf {
38-
// Configure CSRF token
39-
it.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
38+
// Configure CSRF token through a cookie
39+
// Setting domain allows sending the cookie on that domain **and subdomains**
40+
it.csrfTokenRepository(CookieCsrfTokenRepository().apply {
41+
setSecure(true)
42+
setCookieHttpOnly(true)
43+
setCookieDomain("osable.net")
44+
})
4045
}.oauth2Client()
4146

4247

4348
http.exceptionHandling().accessDeniedHandler { request, response, accessDeniedException ->
4449
println("Access denied. Cause: ${accessDeniedException.cause} | Message: ${accessDeniedException.message}")
4550
accessDeniedException.printStackTrace()
46-
response.status = request.getErrorCode()
51+
response.status = HttpStatus.FORBIDDEN.value()
4752
}
4853

4954
http.cors().configurationSource {

0 commit comments

Comments
 (0)