romm icon indicating copy to clipboard operation
romm copied to clipboard

[Bug] OIDC - CSRF Warning

Open Lowxorx opened this issue 1 year ago • 9 comments

RomM version 4.3.2

Describe the bug Logging in via authentik return a bad request, with error message "Email is not verified."

To Reproduce Steps to reproduce the behavior:

  1. Go to login.
  2. Click on authentik login
  3. Login via authentik
  4. See error

Expected behavior Login with authentik should work without error.

Screenshots Image

Desktop (please complete the following information):

  • OS: Arch Linux
  • Browser: Firefox
  • Version: 144.0.2 (64 bits)

Additional context Despite the error message displayed in the browser, the logs show that there is a CSRF issue. Perhaps this will help you.

Please note that I've read #1502 and tried the various solutions, but nothing works. Any help is appreciated.

romm     | INFO:     [RomM][nginx][2025-11-05 15:46:42] 10.10.10.131 | XX.XX.XX.XX | GET /api/login/openid 302 | 0 | Firefox Linux | 0.003
romm     | INFO:          [RomM][_client][2025-11-05 15:46:42] HTTP Request: POST https://auth.my.domain/application/o/token/ "HTTP/1.1 200 OK"
romm     | ERROR:         [RomM][base_handler][2025-11-05 15:46:42] Email is not verified.
romm     | INFO:          [RomM][httptools_impl][2025-11-05 15:46:42] XX.XX.XX.XX:0 - "GET /api/oauth/openid?code=00a1ace787ed4952b62b006b68ab9571&state=yll10GUE99yt5Pmu59fwSfVgUZEm8U HTTP/1.0" 400
romm     | INFO:     [RomM][nginx][2025-11-05 15:46:42] 10.10.10.131 | XX.XX.XX.XX | GET /api/oauth/openid?code=00a1ace787ed4952b62b006b68ab9571&state=yll10GUE99yt5Pmu59fwSfVgUZEm8U 400 | 35 | Firefox Linux | 0.377
romm     | INFO:          [RomM][httptools_impl][2025-11-05 15:46:42] XX.XX.XX.XX:0 - "GET /api/oauth/openid?code=00a1ace787ed4952b62b006b68ab9571&state=yll10GUE99yt5Pmu59fwSfVgUZEm8U HTTP/1.0" 500
romm     | ERROR:         [RomM][httptools_impl][2025-11-05 15:46:42] Exception in ASGI application
romm     | Traceback (most recent call last):
romm     |   File "/src/.venv/lib/python3.13/site-packages/uvicorn/protocols/http/httptools_impl.py", line 409, in run_asgi
romm     |     result = await app(  # type: ignore[func-returns-value]
romm     |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |         self.scope, self.receive, self.send
romm     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |     )
romm     |     ^
romm     |   File "/src/.venv/lib/python3.13/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
romm     |     return await self.app(scope, receive, send)
romm     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |   File "/src/.venv/lib/python3.13/site-packages/fastapi/applications.py", line 1054, in __call__
romm     |     await super().__call__(scope, receive, send)
romm     |   File "/src/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/starlette.py", line 409, in _sentry_patched_asgi_app
romm     |     return await middleware(scope, receive, send)
romm     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |   File "/src/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/asgi.py", line 174, in _run_asgi3
romm     |     return await self._run_app(scope, receive, send, asgi_version=3)
romm     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |   File "/src/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/asgi.py", line 276, in _run_app
romm     |     raise exc from None
romm     |   File "/src/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/asgi.py", line 271, in _run_app
romm     |     return await self.app(
romm     |            ^^^^^^^^^^^^^^^
romm     |         scope, receive, _sentry_wrapped_send
romm     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |     )
romm     |     ^
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/applications.py", line 113, in __call__
romm     |     await self.middleware_stack(scope, receive, send)
romm     |   File "/src/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/starlette.py", line 200, in _create_span_call
romm     |     return await old_call(app, scope, new_receive, new_send, **kwargs)
romm     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/middleware/errors.py", line 186, in __call__
romm     |     raise exc
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/middleware/errors.py", line 164, in __call__
romm     |     await self.app(scope, receive, _send)
romm     |   File "/src/.venv/lib/python3.13/site-packages/opentelemetry/instrumentation/asgi/__init__.py", line 768, in __call__
romm     |     await self.app(scope, otel_receive, otel_send)
romm     |   File "/src/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/starlette.py", line 200, in _create_span_call
romm     |     return await old_call(app, scope, new_receive, new_send, **kwargs)
romm     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/middleware/errors.py", line 186, in __call__
romm     |     raise exc
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/middleware/errors.py", line 164, in __call__
romm     |     await self.app(scope, receive, _send)
romm     |   File "/src/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/starlette.py", line 200, in _create_span_call
romm     |     return await old_call(app, scope, new_receive, new_send, **kwargs)
romm     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/middleware/base.py", line 182, in __call__
romm     |     with recv_stream, send_stream, collapse_excgroups():
romm     |                                    ~~~~~~~~~~~~~~~~~~^^
romm     |   File "/usr/local/lib/python3.13/contextlib.py", line 162, in __exit__
romm     |     self.gen.throw(value)
romm     |     ~~~~~~~~~~~~~~^^^^^^^
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/_utils.py", line 83, in collapse_excgroups
romm     |     raise exc
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/middleware/base.py", line 184, in __call__
romm     |     response = await self.dispatch_func(request, call_next)
romm     |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |   File "/backend/utils/context.py", line 48, in set_context_middleware
romm     |     return await call_next(request)
romm     |            ^^^^^^^^^^^^^^^^^^^^^^^^
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/middleware/base.py", line 159, in call_next
romm     |     raise app_exc
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/middleware/base.py", line 144, in coro
romm     |     await self.app(scope, receive_or_disconnect, send_no_error)
romm     |   File "/src/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/starlette.py", line 200, in _create_span_call
romm     |     return await old_call(app, scope, new_receive, new_send, **kwargs)
romm     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |   File "/backend/handler/auth/middleware.py", line 162, in __call__
romm     |     await self.app(scope, receive, send_wrapper)
romm     |   File "/src/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/starlette.py", line 348, in _sentry_authenticationmiddleware_call
romm     |     await old_call(self, scope, receive, send)
romm     |   File "/src/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/starlette.py", line 200, in _create_span_call
romm     |     return await old_call(app, scope, new_receive, new_send, **kwargs)
romm     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/middleware/authentication.py", line 48, in __call__
romm     |     await self.app(scope, receive, send)
romm     |   File "/src/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/starlette.py", line 200, in _create_span_call
romm     |     return await old_call(app, scope, new_receive, new_send, **kwargs)
romm     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |   File "/backend/handler/auth/middleware.py", line 30, in __call__
romm     |     await super().__call__(scope, receive, send)
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette_csrf/middleware.py", line 72, in __call__
romm     |     await self.app(scope, receive, send)
romm     |   File "/src/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/starlette.py", line 200, in _create_span_call
romm     |     return await old_call(app, scope, new_receive, new_send, **kwargs)
romm     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/middleware/cors.py", line 85, in __call__
romm     |     await self.app(scope, receive, send)
romm     |   File "/src/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/starlette.py", line 298, in _sentry_exceptionmiddleware_call
romm     |     await old_call(self, scope, receive, send)
romm     |   File "/src/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/starlette.py", line 200, in _create_span_call
romm     |     return await old_call(app, scope, new_receive, new_send, **kwargs)
romm     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/middleware/exceptions.py", line 63, in __call__
romm     |     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
romm     |     raise exc
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
romm     |     await app(scope, receive, sender)
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/routing.py", line 716, in __call__
romm     |     await self.middleware_stack(scope, receive, send)
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/routing.py", line 736, in app
romm     |     await route.handle(scope, receive, send)
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/routing.py", line 290, in handle
romm     |     await self.app(scope, receive, send)
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/routing.py", line 78, in app
romm     |     await wrap_app_handling_exceptions(app, request)(scope, receive, send)
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
romm     |     raise exc
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
romm     |     await app(scope, receive, sender)
romm     |   File "/src/.venv/lib/python3.13/site-packages/starlette/routing.py", line 75, in app
romm     |     response = await f(request)
romm     |                ^^^^^^^^^^^^^^^^
romm     |   File "/src/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/fastapi.py", line 143, in _sentry_app
romm     |     return await old_app(*args, **kwargs)
romm     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |   File "/src/.venv/lib/python3.13/site-packages/fastapi/routing.py", line 302, in app
romm     |     raw_response = await run_endpoint_function(
romm     |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |     ...<3 lines>...
romm     |     )
romm     |     ^
romm     |   File "/src/.venv/lib/python3.13/site-packages/fastapi/routing.py", line 213, in run_endpoint_function
romm     |     return await dependant.call(**values)
romm     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |   File "/backend/endpoints/auth.py", line 254, in auth_openid
romm     |     token = await oauth.openid.authorize_access_token(request)
romm     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
romm     |   File "/src/.venv/lib/python3.13/site-packages/authlib/integrations/starlette_client/apps.py", line 90, in authorize_access_token
romm     |     params = self._format_state_params(state_data, params)
romm     |   File "/src/.venv/lib/python3.13/site-packages/authlib/integrations/base_client/sync_app.py", line 260, in _format_state_params
romm     |     raise MismatchingStateError()
romm     | authlib.integrations.base_client.errors.MismatchingStateError: mismatching_state: CSRF Warning! State not equal in request and response.
romm     | INFO:     [RomM][nginx][2025-11-05 15:46:42] 10.10.10.131 | XX.XX.XX.XX | GET /api/oauth/openid?code=00a1ace787ed4952b62b006b68ab9571&state=yll10GUE99yt5Pmu59fwSfVgUZEm8U 500 | 21 | Firefox Linux | 0.066

Lowxorx avatar Nov 05 '25 16:11 Lowxorx

I am seeing the same issue.

drewdrew21b avatar Nov 05 '25 18:11 drewdrew21b

I found the answer this problem. Authentik recently removed "email_verifed: TRUE" as an automatic scope configuration. Now it reports email_verified: False by default.

Looks like this was introduced in either 2025.10 or 2025.10.1 (I just upgraded to .1 today and saw the issues)

References:

  • Documentation of how to fix: https://docs.goauthentik.io/add-secure-apps/providers/property-mappings/#scope-mappings-with-oauth2
  • Reference to 2025.10 that this behavior changed with this release: https://docs.goauthentik.io/releases/2025.10/#default-oauth-scope-mappings
  • Exact Change in Github: https://github.com/goauthentik/authentik/pull/16206/files#diff-c537d4106c7894ea1500a0f2ee3e75f4a96f1fba96232b3ec7a877d05af8d341

My Proposed Fix:

Step 1: Create Custom Scope: Customization > Property Mappings: Create > Scope Mapping

  • Name: Verified Email <-- This can be whatever you want, its just a human readable settting.
  • Scope name: email <-- This needs to be set to email otherwise this won't work
  • Description: Automatically mark email as verified. <-- This can be whatever you want.
  • Expression:
return {
    "email": user.email,
    "email_verified": True,
}
  • Create

Step 2: Replace OpenID "email" scope with new scope Providers > RomM (or whatever you called your provider for this integration) Edit > Advanced Protocol Settings

  • Add: Verified Email (or whatever you ended up naming this on step 1).
  • Remove: authentik default OAuth Mapping: OpenID 'email'
  • Update

Step 3: Test configuration

  • Log out of Authentik
  • Log into RomM again and verify problem is fixed.

Note: If any of your other OIDC applications were impacted by this, you should be able to repeat Steps 2 and 3 for all the impacted applications.

drewdrew21b avatar Nov 05 '25 18:11 drewdrew21b

I'm also impacted by this. I added "email_verified: true" to just my romm.app OIDC provider to restore pre-2025.10.x functionality.

The proper fix is to have romm ignore email_verified or implement email verification :)

brianmiller avatar Nov 05 '25 19:11 brianmiller

I found the answer this problem. Authentik recently removed "email_verifed: TRUE" as an automatic scope configuration. Now it reports email_verified: False by default.

Looks like this was introduced in either 2025.10 or 2025.10.1 (I just upgraded to .1 today and saw the issues)

References:

* Documentation of how to fix: https://docs.goauthentik.io/add-secure-apps/providers/property-mappings/#scope-mappings-with-oauth2

* Reference to 2025.10 that this behavior changed with this release: https://docs.goauthentik.io/releases/2025.10/#default-oauth-scope-mappings

* Exact Change in Github: https://github.com/goauthentik/authentik/pull/16206/files#diff-c537d4106c7894ea1500a0f2ee3e75f4a96f1fba96232b3ec7a877d05af8d341

My Proposed Fix:

Step 1: Create Custom Scope: Customization > Property Mappings: Create > Scope Mapping

* Name: Verified Email <-- This can be whatever you want, its just a human readable settting.

* Scope name: email <-- This needs to be set to email otherwise this won't work

* Description: Automatically mark email as verified. <-- This can be whatever you want.

* Expression:
return {
    "email": user.email,
    "email_verified": True,
}
* Create

Step 2: Replace OpenID "email" scope with new scope Providers > RomM (or whatever you called your provider for this integration) Edit > Advanced Protocol Settings

* Add: Verified Email (or whatever you ended up naming this on step 1).

* Remove: authentik default OAuth Mapping: OpenID 'email'

* Update

Step 3: Test configuration

* Log out of Authentik

* Log into RomM again and verify problem is fixed.

Note: If any of your other OIDC applications were impacted by this, you should be able to repeat Steps 2 and 3 for all the impacted applications.

That's a good catch, ty! Your workaround fixes the problem for me.

According to this, this is indeed the desired behavior in Romm : https://github.com/rommapp/romm/commit/7fedaca59a3fdd58644cbe95d80f278667df5d88

@gantoine Do you want a PR to explicitly ignore this email_verified field?

Lowxorx avatar Nov 05 '25 20:11 Lowxorx

related to this https://github.com/rommapp/romm/issues/2673 too

NB: i'm not a huge fan of changing default stuff from Authentik side ..

2 solutions from my point of view ,

  • add options to bypass email_verified on romm side
  • add options to set custom Scope mapping with default openid profile email like many other app

DrummyFloyd avatar Nov 16 '25 23:11 DrummyFloyd

@DrummyFloyd OIDC_CLAIM_ROLES can be used to extend scope mapping in romm due to "scope": f"openid profile email {OIDC_CLAIM_ROLES}".strip(),

gantoine avatar Jan 04 '26 17:01 gantoine

To elaborate on this fix, am I supposed to add:

OIDC_CLAIM_ROLES: "openid profile email"

To my environment variables in my docker compose stack to resolve this issue?

emteedubs avatar Jan 05 '26 02:01 emteedubs

@emteedubs to be honest i have no idea, i build the OIDC feature but I don't personally use it 🤷🏼

gantoine avatar Jan 05 '26 02:01 gantoine

@emteedubs that fixed the issue for me.

pacnpal avatar Mar 09 '26 16:03 pacnpal