What changed, and why it matters
This commit fixes an OpenID Connect (OIDC) single sign-on login bug. Previously, when a user logged in via SSO without an existing account link, the code tried to decrypt a value that was actually the string 'null', which would fail and block login. The fix treats 'null' or missing state as having no user ID, allowing login to proceed normally. This is a reliability fix; there is no direct evidence in the commit that it fixes a security vulnerability.
Review the broader OAuth state handling to ensure state is validated for CSRF protection and that treating 'null' as no user ID cannot be abused to link an SSO identity to an unintended account. Monitor issue #3970 for any additional context.
Security signals we found
OIDC/OAuth state parameter handling changed
Defensive null/'null' check added before decryption
SSO login availability fix
No explicit security claim in commit title or message
Evidence from the diff
In lnbits/core/views/auth_api.py, handle_oauth_token() now checks whether provider_sso.state is None or the literal string ‘null’ before calling decrypt_internal_message(). If so, it sets user_id to None instead of attempting decryption. This prevents a ValueError/exception during fresh SSO logins where no internal state user ID was stored. The change is defensive and improves availability of the SSO flow, but the diff alone does not demonstrate an exploitable weakness such as authentication bypass, state manipulation, or privilege escalation.
Changed components
lnbits/core/views/auth_api.pyhandle_oauth_token functionOIDC SSO login flowInspect captured patch +5 / −1
diff --git a/lnbits/core/views/auth_api.py b/lnbits/core/views/auth_api.py
index 38d391c..3d3ad25 100644
--- a/lnbits/core/views/auth_api.py
+++ b/lnbits/core/views/auth_api.py
@@ -348,7 +348,11 @@ async def handle_oauth_token(request: Request, provider: str) -> RedirectRespons
userinfo = await provider_sso.verify_and_process(request)
if not userinfo:
raise HTTPException(HTTPStatus.UNAUTHORIZED, "Invalid user info.")
- user_id = decrypt_internal_message(provider_sso.state)
+ if provider_sso.state is None or provider_sso.state == "null":
+ user_id = None
+ else:
+ user_id = decrypt_internal_message(provider_sso.state)
+
request.session.pop("user", None)
return await _handle_sso_login(userinfo, user_id)
Why this scored 48/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.