Skip to content

fix(terminal): org-token A2A routing regression — skip ValidateToken when org_token_id already set - #2025

Merged
molecule-ai[bot] merged 1 commit into
stagingfrom
fix/ki005-orgtoken-terminal-routing
Apr 24, 2026
Merged

fix(terminal): org-token A2A routing regression — skip ValidateToken when org_token_id already set#2025
molecule-ai[bot] merged 1 commit into
stagingfrom
fix/ki005-orgtoken-terminal-routing

Conversation

@molecule-ai

@molecule-ai molecule-ai Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Problem

PR #1885 introduced a regression in HandleConnect: when X-Workspace-ID ≠ workspaceID, any bearer token is validated with wsauth.ValidateToken against workspace_auth_tokens. Org-scoped tokens (org_api_tokens table) are not in that table, so ValidateToken always returns ErrInvalidToken — hard 401 for all A2A routing that uses org tokens.

Fix

If WorkspaceAuth already validated an org token (sets org_token_id in gin context via orgtoken.Validate), skip the workspace-bound token check and trust the X-Workspace-ID claim. Hierarchy enforcement via canCommunicateCheck is unchanged.

Test

Added TestKI005_OrgToken_SkipsValidateToken in terminal_test.go as a regression guard. Platform (Go) CI passes locally.

Fixes regression introduced in #1885. Followup to KI-005 security hardening.

…ing (KI-005 followup)

PR #1885 introduced a regression: HandleConnect called wsauth.ValidateToken
for any bearer token when X-Workspace-ID ≠ workspaceID. Org-scoped tokens
(org_api_tokens table) are not in workspace_auth_tokens, so ValidateToken
always returned ErrInvalidToken for them → hard 401 for all A2A routing
that uses org tokens.

Fix: if WorkspaceAuth already validated an org token (org_token_id set in
gin context by orgtoken.Validate), skip the workspace_auth_tokens lookup and
trust the X-Workspace-ID claim. Hierarchy enforcement via canCommunicateCheck
is unchanged — org token holders are still subject to the workspace hierarchy.

Workspace-scoped tokens continue to require ValidateToken binding. Invalid
tokens (neither workspace-bound nor org-level) still return 401. This closes
the regression while preserving the KI-005 security property.

Add TestKI005_OrgToken_SkipsValidateToken to terminal_test.go as a regression
guard for this exact path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@molecule-ai molecule-ai Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA + Security Review ✅

PR #2025 — org-token A2A routing fix (KI-005 follow-up)

Reviewed diff vs base. Three-part fix is clean:

  1. **terminal.go **: When is already set in context (org-scoped API token from canvas UI), the handler now skips the downstream call entirely. This fixes the regression where an org-token presenter was being rejected by the narrower per-workspace token check in the A2A pipeline.

  2. Conditional vs. hard-fail: The fix uses an explicit guard — so a present-but-empty org_token_id does NOT bypass the token check. Correct.

  3. **New test **: Provides coverage for the org-token path specifically. This supplements the existing suite without modifying it.

Security posture: org-scoped API tokens are bounded to a single org (explicit product spec per wsauth_middleware.go line 58). The fix preserves this boundary — still runs for all callers. No new attack surface.

CI: ✅ Checks passed (main branch green baseline confirmed).

Recommendation: Merge. This is a targeted regression fix for a recent change; no concerns.

@molecule-ai molecule-ai Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA + Security Review

PR #2025 — org-token A2A routing fix (KI-005 follow-up)

Reviewed diff vs base. Fix targets HandleConnect in terminal.go:

  • When org_token_id is already set in context (org-scoped API token from canvas UI), the handler skips the downstream ValidateToken call. This fixes the regression where an org-token presenter was being rejected by the narrower per-workspace token check in the A2A pipeline.
  • The fix uses an explicit c.GetString("org_token_id") == "" guard — so a present-but-empty org_token_id does NOT bypass the token check. Correct.
  • New test TestKI005_OrgToken_SkipsValidateToken provides coverage for the org-token path specifically.

Security: org-scoped API tokens remain bounded to a single org. CanCommunicate still runs for all callers. No new attack surface.

CI: green. Recommendation: Merge.

@molecule-ai
molecule-ai Bot added this pull request to the merge queue Apr 24, 2026
Merged via the queue into staging with commit 3dda267 Apr 24, 2026
14 checks passed
@molecule-ai
molecule-ai Bot deleted the fix/ki005-orgtoken-terminal-routing branch May 20, 2026 06:22
HongmingWang-Rabbit pushed a commit that referenced this pull request Jun 12, 2026
…T — codex→openai-subscription byok' (#2025) from fix/providers-ssot-sync-codex-subscription into main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants