fix(auth): avoid nil deref when OIDC UserInfo fetch fails#4053
fix(auth): avoid nil deref when OIDC UserInfo fetch fails#4053cursor[bot] wants to merge 1 commit into
Conversation
When an OIDC provider returns no id_token and the UserInfo endpoint errors, oidcRedirect accessed userInfo.Profile before checking err, panicking on a nil pointer and crashing the server process. Extract oidcClaimsFromUserInfo so the error path returns immediately and add regression tests. Co-authored-by: Denis Gukov <fiftin@outlook.com>
There was a problem hiding this comment.
Security review
Outcome: No medium, high, or critical vulnerabilities found in the added/modified code.
Scope reviewed: api/login.go (oidcClaimsFromUserInfo extraction and oidcRedirect call site) and api/login_test.go.
Prior threads: No unresolved automation review threads were present on this PR.
Analysis
This change fixes a nil-pointer dereference in the OIDC callback path when _oidc.UserInfo fails (no id_token in the OAuth2 response). Previously, claim population was guarded by if err == nil, but userInfo.Profile was read unconditionally afterward, which could panic and deny service to the auth handler.
The refactor preserves the successful-path behavior:
- UserInfo errors are returned immediately and
oidcRedirectresponds with HTTP 502, so no session is created. - Successful UserInfo responses still populate claims via
claimOidcUserInfoor direct field mapping, with the samesubempty-check andresolveExternalUsergating beforecreateSession.
No new attacker-controlled sinks, authn/authz bypasses, injection paths, or secret-exposure risks were introduced by this diff.
Sent by Cursor Automation: Find vulnerabilities
There was a problem hiding this comment.
Pull request overview
Fixes a crash in the OIDC login redirect flow when an OIDC provider does not return an id_token and the subsequent UserInfo fetch fails, by ensuring UserInfo errors are handled before any dereference of the returned *oidc.UserInfo.
Changes:
- Extracts
oidcClaimsFromUserInfoto centralize claim construction for the no-id_tokenpath and return early on UserInfo errors. - Refactors
oidcRedirectto use the new helper instead of inlined logic. - Adds regression tests covering the UserInfo error path and a successful UserInfo response with email.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| api/login.go | Adds oidcClaimsFromUserInfo and uses it in oidcRedirect to prevent nil dereference on UserInfo failure. |
| api/login_test.go | Adds unit tests for the new helper’s error and success paths. |
| func oidcClaimsFromUserInfo(userInfo *oidc.UserInfo, userInfoErr error, provider util.OidcProvider) (claimResult, error) { | ||
| if userInfoErr != nil { | ||
| return claimResult{}, userInfoErr | ||
| } | ||
|
|
||
| var claims claimResult | ||
| var err error | ||
| if userInfo.Email == "" { |


Bug and impact
When an OIDC provider does not return an
id_tokenand the UserInfo endpoint call fails (network error, 401, misconfiguration),oidcRedirectaccesseduserInfo.Profilebefore checking the error. That dereferenced a nil*oidc.UserInfoand panicked the Semaphore server process during the login redirect.Root cause
In the no-
id_tokenbranch ofoidcRedirect, username/name defaults were applied unconditionally after theUserInfo()call, even whenerr != nilleftuserInfonil. This path predates the external-identity work but was left unfixed when the branch was extended in #4025.Fix
oidcClaimsFromUserInfoso UserInfo errors return immediately without touchinguserInfo.Validation
go test ./api -run TestOidcClaimsFromUserInfogo test ./db/sql -run TestMigration_2_20Note
Low Risk
Small, localized auth-path refactor with regression tests; behavior on success is unchanged and failures now return 502 instead of panicking.
Overview
Fixes a server panic on OIDC login when there is no
id_tokenand the UserInfo request fails:oidcRedirectused to readuserInfo.Profileeven whenUserInfo()returned an error anduserInfowas nil.UserInfo handling is moved into
oidcClaimsFromUserInfo, which returns the fetch error immediately and only then builds claims (empty email →claimOidcUserInfo, otherwise direct fields plus random username / default name).oidcRedirectcalls that helper instead of inlined logic.Adds
TestOidcClaimsFromUserInfo_UserInfoFailureandTestOidcClaimsFromUserInfo_WithEmail.Reviewed by Cursor Bugbot for commit 4e7499a. Configure here.