mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-21 08:15:23 -04:00
[PR #120] [MERGED] fix: require state parameter in OAuth GET callback #170
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/120
Author: @mason5052
Created: 2/22/2026
Status: ✅ Merged
Merged: 2/22/2026
Merged by: @asdek
Base:
feature/project_improvements← 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, short-circuiting the entire condition. The handler proceeds to exchange the authorization code without verifying the OAuth state.The
AuthLoginPostCallbackhandler correctly validates withif data.State != state.Value {which rejects empty values.Solution
Split the compound condition into two explicit checks:
This aligns the GET callback with the POST callback's strict validation.
Ref: #101
Type of Change
Areas Affected
Testing and Verification
Test Configuration
Test Steps
AuthLoginGetCallback(auth.go:331) -- compound condition allows empty state bypassAuthLoginPostCallback(auth.go:386) -- strictdata.State != state.ValuecheckTest Results
ErrAuthInvalidAuthorizationStateSecurity Considerations
CSRF vulnerability fix. Without state validation, an attacker could craft a callback URL with a valid authorization code but no state parameter, associating the attacker's OAuth identity with the victim's session.
No new dependencies. No permission changes.
Performance Impact
Negligible -- one additional string comparison on the OAuth callback path.
Deployment Notes
Backward-compatible. Legitimate OAuth flows already include the state parameter.
Checklist
Code Quality
go fmtandgo vet(for Go code)Security
Compatibility
Documentation
Additional Notes
Addresses the CSRF state validation bypass from the security audit (issue #101, item 5).
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.