mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-21 08:15:23 -04:00
[PR #131] [CLOSED] fix: replace unsafe type assertions in session cookie middleware #179
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/131
Author: @mason5052
Created: 2/22/2026
Status: ❌ Closed
Base:
master← Head:fix/auth-middleware-unsafe-type-assertions📝 Commits (1)
d26209bfix: replace unsafe type assertions in session cookie middleware📊 Changes
1 file changed (+31 additions, -8 deletions)
View changed files
📝
backend/pkg/server/auth/auth_middleware.go(+31 -8)📄 Description
Description of the Change
Problem
session.Get()returnsinterface{}for each session claim. The middleware correctly validates that all required claims are non-nil (line 102) and uses the two-value assertion form forprmandexp(lines 108-117), but then performs bare, unchecked type assertions on six remaining claims:A crafted or corrupted session cookie containing a claim with the wrong underlying type (e.g.,
uidstored asstringinstead ofuint64) causes a runtime panic. Gin's recovery middleware catches the panic and returns a 500, but the request fails and the panic is logged as an unhandled error.Solution
Replace all bare type assertions with the two-value form and return
authResultFailon type mismatch, consistent with the pattern already established in the same function forprmandexp:Also fixes a pre-existing typo:
"no pemissions granted"->"no permissions granted".Ref: #101
Type of Change
Areas Affected
Testing and Verification
Test Steps
Security Considerations
authResultFail(HTTP 403) instead.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.