fix(handlers): KI-005 — CanCommunicate hierarchy guard on terminal endpoint (REOPEN) - #1834
Closed
molecule-ai[bot] wants to merge 4 commits into
Closed
molecule-ai[bot] wants to merge 4 commits into
molecule-ai[bot] wants to merge 4 commits into
Conversation
Both handlers used shell-interpolated concat form "/configs/" + path which allows path traversal to escape the /configs bind mount. Switch to two-arg exec form: ["cat", "/configs", relPath] and ["rm", "-rf", "/configs", filePath] which bind the command to the configs volume regardless of path content. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Validate() scans: SELECT id, prefix, org_id FROM org_api_tokens (sql.NullString for org_id). Updated all mock expectations: - TestValidate_HappyPath: 3-column WillReturnRows - TestValidate_UnknownHashErrInvalid: 3-col regex, ErrNoRows - TestValidate_RevokedTokenNotAccepted: 3-col regex, ErrNoRows Also rewrote wsauth_middleware_org_id_test.go: - orgTokenValidateQueryV1 uses 3-column SELECT (no ::text cast) - Removed dead orgTokenOrgIDQuery secondary lookup - Removed redundant F1097 secondary lookup mock - Validate() now returns org_id inline — no follow-on DB lookup needed Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…I-005) KI-005 CRITICAL: terminal.go HandleConnect had zero CanCommunicate check. Any workspace could reach any other workspace's terminal by knowing the target's UUID (enumeration via canvas, logs, or delegation). Fix: when caller presents X-Workspace-ID header with a bearer token: 1. ValidateToken binds the token to the claimed workspace (prevents identity forgery via org-scoped token) 2. canCommunicateCheck(callerID, workspaceID) gates terminal access Self-access (callerID == workspaceID) always allowed — a workspace's own token reaches its own terminal without hierarchy check. Legacy access (no X-Workspace-ID header) passes through unchanged — WorkspaceAuth gates apply upstream on the WS-authenticated route. Added 5 tests: - TestKI005_SelfAccess_AlwaysAllowed - TestKI005_CanCommunicatePeer_Allowed - TestKI005_CanCommunicateNonPeer_Forbidden - TestKI005_TokenMismatch_Unauthorized - TestKI005_NoXWorkspaceIDHeader_LegacyAllowed Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Resolve conflicts: - wsauth_middleware_org_id_test.go: take 3-column org_id scan version - orgtoken/tokens_test.go: take 3-column org_id scan version Both our staged files and origin/main's files reflect the F1097 migration-036 org_id single-round-trip refactor; the only difference was the base version (stage 1) still had the pre-migration 2-query pattern. Take the post-migration version from stage 2. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Author
auto-merge was automatically disabled
April 23, 2026 18:35
Pull request was closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Security note
PR #1690 was closed without merge (token expired mid-review). This is a RE-OPEN with the fix branch rebased onto latest main.
Test coverage
Status