Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS issue while logging out from OAuth2/OIDC provider configured in Spring #2858

Open
tamasmak opened this issue Oct 22, 2024 · 2 comments
Open
Labels
bug Something isn't working hilla Issues related to Hilla Impact: High Severity: Major

Comments

@tamasmak
Copy link

tamasmak commented Oct 22, 2024

Describe the bug

A CORS issue happens in the preflight request when using a fetch request while logging out from OAuth2/OIDC provider configured in Spring.
An example of the issue:

Access to fetch at 'https://keycloak.local.com/realms/test-app/protocol/openid-connect/logout?id_token_hint=...&post_logout_redirect_uri=https://vaadinapp'
(redirected from 'https://vaadinapp/logout') from origin 'https://vaadinapp/' has been blocked by CORS policy: Request header field x-csrf-token is not allowed by Access-Control-Allow-Headers in preflight response.
  1. Hilla’s Authentication.logout method triggers a fetch request to /logout (Spring’s default logout handler) setting Spring’s CRSF token
  2. Spring’s /logout handler redirects to the provider's RP-Initiated logout endpoint (different host) and the preflight request fails since the custom x-csrf-token header is not allowed by the provider.

Expected-behavior

The application should be redirected to the expected logout success URI without issues.
Could the fetch request handle the redirect and redirect the user to the provider's RP-Initiated logout endpoint?

Reproduction

  1. Setup an OAuth2/OIDC provider for authentication for a Hilla application (e.g. using Keycloak)
  2. Use the logout() method to logout the user
import { useAuth } from './auth';
const { logout } = useAuth();
<Button onClick={async () => logout()}>Sign out</Button>

System Info

Hilla 24.5.0

@tamasmak tamasmak added bug Something isn't working hilla Issues related to Hilla labels Oct 22, 2024
@platosha
Copy link
Contributor

platosha commented Oct 31, 2024

The default logout() implementation is specific to Spring Security form login. In OIDC provider case, it does not work.

What we need for the logout button is a navigation to the provider's logout page.

@platosha
Copy link
Contributor

We could make logout always make a form-submitting HTML navigation to the specified URL instead of fetch. Full page reload is needed anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hilla Issues related to Hilla Impact: High Severity: Major
Projects
None yet
Development

No branches or pull requests

2 participants