mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-20 12:37:04 -04:00
[PR #125] [MERGED] fix: validate required fields in OAuth state parser #173
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/125
Author: @mason5052
Created: 2/22/2026
Status: ✅ Merged
Merged: 2/23/2026
Merged by: @asdek
Base:
feature/project_improvements← Head:fix/oauth-state-field-validation📝 Commits (1)
50f1431fix: validate required fields in OAuth state parser📊 Changes
1 file changed (+16 additions, -1 deletions)
View changed files
📝
backend/pkg/server/services/auth.go(+16 -1)📄 Description
Description of the Change
Problem
The
parseState()function inauth.goaccessesstateData["exp"]andstateData["provider"]without first checking whether these keys exist in the map. While Go map access on missing keys returns the zero value (empty string) rather than panicking, this produces misleading error messages:exp:strconv.ParseInt("")fails with "invalid syntax" instead of clearly indicating the field is absentprovider: empty string is used as a provider key, resulting in a confusing "provider not initialized" error inauthLoginCallback()If the HMAC signing key were ever compromised or a signing bug introduced, crafted state payloads with missing fields would produce confusing errors that complicate incident response.
Solution
Add explicit existence checks for required fields (
expandprovider) immediately after JSON unmarshalling inparseState(). Each missing field now returns a clear, specific error message (e.g., "missing required field: exp") with proper logging.This is a defense-in-depth measure that ensures:
Ref: #101 (item 8)
Type of Change
Areas Affected
Testing and Verification
Test Steps
cd backend && go build ./...go test ./pkg/server/services/...exporproviderfields return clear error messagesSecurity Considerations
This change hardens the OAuth state parser against malformed state data. While the state is HMAC-signed (preventing tampering under normal conditions), this defense-in-depth validation ensures clear error handling even if the signing mechanism is bypassed.
Checklist
Code Quality
go fmtandgo vet(for Go code)Security
Compatibility
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.