mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-21 08:15:23 -04:00
[PR #118] [CLOSED] fix: require state parameter in OAuth GET callback #166
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/vxcontrol/pentagi/pull/118
Author: @mason5052
Created: 2/21/2026
Status: ❌ Closed
Base:
master← Head:fix/oauth-get-callback-state-validation📝 Commits (1)
0ab4479fix: require state parameter in OAuth GET callback📊 Changes
1 file changed (+8 additions, -1 deletions)
View changed files
📝
backend/pkg/server/services/auth.go(+8 -1)📄 Description
Description of the Change
Problem
The
AuthLoginGetCallbackhandler inbackend/pkg/server/services/auth.goaccepts requests with an emptystatequery parameter, bypassing CSRF validation. The original condition:When
stateis absent or empty,queryState != ""evaluates tofalse, causing the entire condition to short-circuit. The state mismatch check is never reached, and the handler proceeds to exchange the authorization code without verifying the OAuth state -- a classic CSRF vulnerability.This contrasts with the
AuthLoginPostCallbackhandler (line 386) which correctly validates:The POST handler rejects any mismatched state including empty values.
Solution
Split the single compound condition into two explicit validation steps:
statequery parameter is empty, return an error immediatelystatedoes not match the cookie value, return an errorThis aligns the GET callback validation with the POST callback's strict behavior.
Ref: #101
Type of Change
Areas Affected
Testing and Verification
Test Configuration
Test Steps
AuthLoginGetCallback(auth.go line 331) -- observe compound condition allows empty state to bypass validationAuthLoginPostCallback(auth.go line 386) -- observe strictdata.State != state.Valuecheck that correctly rejects empty statego vet ./pkg/server/services/-- no issuesTest Results
?code=AUTHCODE(no state parameter) proceeds to token exchange, bypassing CSRF protectionErrAuthInvalidAuthorizationStateErrAuthInvalidAuthorizationStateSecurity Considerations
This is a CSRF vulnerability fix. Without state validation, an attacker could craft a malicious OAuth callback URL with a valid authorization code but no state parameter, tricking the application into associating the attacker's OAuth identity with the victim's session.
The fix enforces that:
stateparameter MUST be present in the callback URLstateparameter MUST match the value stored in the session cookieNo new dependencies introduced. No permission changes.
Performance Impact
No performance impact. The fix adds one additional string comparison on the OAuth callback path, which is negligible.
Documentation Updates
No documentation updates needed -- this is a security fix to existing behavior.
Deployment Notes
No special deployment considerations. This is a backward-compatible fix. Legitimate OAuth flows already include the state parameter and will not be affected.
Checklist
Code Quality
go fmtandgo vet(for Go code)npm run lint(for TypeScript/JavaScript code)Security
Compatibility
Documentation
Additional Notes
This fix addresses the CSRF state validation bypass identified in the security audit (issue #101, item 5). The POST callback handler already performs strict state validation -- this PR brings the GET callback handler to the same security standard.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.