fix(auth,env): add missing return statements after error responses#3792
Open
cursor[bot] wants to merge 1 commit intodevelopfrom
Open
fix(auth,env): add missing return statements after error responses#3792cursor[bot] wants to merge 1 commit intodevelopfrom
cursor[bot] wants to merge 1 commit intodevelopfrom
Conversation
Two critical missing-return bugs found in recent code: 1. api/login.go: When login encounters a non-ErrNotFound error (e.g., DB error, validation error from LDAP), the handler writes HTTP 500 but does NOT return. Execution falls through to createSession(), which creates a valid session for a zero-value or stale user struct. This could allow authentication bypass after transient backend failures. 2. api/projects/environment.go AddEnvironment: When project.ID != env.ProjectID, the handler writes HTTP 400 but does NOT return. Execution falls through to CreateEnvironment(), which creates an environment using the body's project ID. Since middleware only checks access for the URL's project, this is an authorization bypass allowing users to create environments in projects they may not have access to. Both fixes add the missing 'return' statement after the error response. Co-authored-by: Denis Gukov <fiftin@outlook.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug and Impact
Two critical missing-
returnbugs that allow control flow to fall through after writing error HTTP responses:1. Authentication bypass in
api/login.go(lines 349-363)Root cause: When
loginByPasswordorloginByLDAPreturns a non-ErrNotFounderror (e.g., DB connection error, validation error), the handler writes HTTP 500 but does NOTreturn. Execution falls through tocreateSession(), which creates a valid authenticated session for a zero-valuedb.User{}struct.Trigger scenario:
loginByPassword(e.g., connection timeout)ErrNotFound, so the 401 early return is skippedcreateSession()is called with a zero-value user (ID=0), creating a session cookieImpact: Session created for user ID 0 (or stale user data from a partial lookup), potentially allowing unauthorized access.
2. Authorization bypass in
api/projects/environment.goAddEnvironment (lines 253-257)Root cause: When
project.ID != env.ProjectID, the handler writes HTTP 400 but does NOTreturn. Execution falls through toCreateEnvironment(), which creates the environment using the request body'sProjectID.Trigger scenario:
POST /api/project/1/environmentwith body{"project_id": 2, ...}project.ID (1) != env.ProjectID (2)and writes 400Impact: Users can create environments in projects they don't have access to.
Fix
Added the missing
returnstatements after both error responses. Both are single-line, minimal fixes.Validation
go vet ./api/projects/...passesgo test ./api/projects/...passes (7 existing tests)go test ./services/server/...passes