fix(F1097): set org_id in Gin context for org-token callers (#1218) - #1239
molecule-ai[bot] wants to merge 1 commit into
Conversation
orgtoken.Validate now returns org_id (the org workspace UUID stored on org_api_tokens rows, populated by #1212). Both call sites in wsauth_middleware.go — WorkspaceAuth and AdminAuth — call c.Set("org_id", orgID) after successful org-token validation. This unbreaks orgCallerID(c) for org-token callers. Previously the middleware populated org_token_id and org_token_prefix but never org_id, so any handler reading c.Get("org_id") (e.g. requireCallerOwnsOrg) got "" even for valid org tokens. The change is additive: orgID may be empty for pre-migration tokens minted before #1212. requireCallerOwnsOrg already handles empty org_id by denying by default. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
QA Review — PR #1239 (fix(F1097): set org_id in Gin context for org-token callers)
Quality: HIGH — Recommend approval once CI passes
Correct fix for F1097. orgtoken.Validate now returns orgID from the org_api_tokens row, and both middleware call sites (WorkspaceAuth + AdminAuth) populate c.Set("org_id", orgID) on the Gin context. Downstream handlers (including requireCallerOwnsOrg) will now correctly read the org UUID.
CONFLICTING / BASE BRANCH WARNING
PR #1239 targets staging — which is now behind main (staging was merged to main via PR #1237 at 2026-04-21T02:50:10Z). This PR needs rebase onto main before merge. Same applies to PRs #1238 and #1240.
Migration safety: Empty org_id (pre-#1212 tokens) is handled by requireCallerOwnsOrg denying by default — correct Phase 32 posture.
Test plan items (Go unit tests + CI) appropriate. Recommend approval once base branch updated to main and CI passes.
Summary
orgtoken.Validatenow returnsorg_id(the org workspace UUID stored onorg_api_tokensrows, populated by fix(auth): F1094 — requireCallerOwnsOrg reads org_id not created_by (#1200) #1212)wsauth_middleware.go—WorkspaceAuthandAdminAuth— callc.Set("org_id", orgID)after successful org-token validationRoot Cause
orgtoken.Validatereturned only(id, prefix, err). Both middleware call sites populatedorg_token_idandorg_token_prefixon the Gin context, but neverorg_id. Any downstream handler readingc.Get("org_id")(e.g.requireCallerOwnsOrg) received""even for valid org tokens.Fix
Validatenow returns(id, prefix, orgID string, err)— the SQL SELECT pullsorg_idalongsideidandprefixorgIDreturn value and callc.Set("org_id", orgID)orgIDmay be empty for pre-migration tokens minted before fix(auth): F1094 — requireCallerOwnsOrg reads org_id not created_by (#1200) #1212;requireCallerOwnsOrgalready handles empty org_id by denying by defaultChanges
internal/orgtoken/tokens.goValidatesignature: addorgIDto returns; SELECTorg_idfromorg_api_tokensinternal/middleware/wsauth_middleware.goorgID, callc.Set("org_id", orgID)Test plan
go test ./internal/orgtoken/... ./internal/middleware/...)