Skip to content

fix(auth): scope org tools to the caller and document the auth flow#182

Open
annextuckner wants to merge 4 commits into
mainfrom
fix/auth-org-scoping-and-docs
Open

fix(auth): scope org tools to the caller and document the auth flow#182
annextuckner wants to merge 4 commits into
mainfrom
fix/auth-org-scoping-and-docs

Conversation

@annextuckner
Copy link
Copy Markdown
Contributor

@annextuckner annextuckner commented Jun 5, 2026

What this changes

Tightens authentication in HTTP mode and documents the auth flow for the org-scoped tools.

  • Scope org tools to the caller, not the deploy key (52a87e8). In HTTP mode, organization-aware tools now resolve the caller's own token from the Authorization: Bearer header instead of falling back to the operator's boot-time deploy key. Stdio mode is unchanged. Covered by new tests in test/http-server.test.ts and test/server.test.ts.
  • Document the org-scoped tools and the SOCKET_API_TOKEN / SOCKET_API_KEY auth flow (9b78353). Adds the tool reference and the per-mode authentication guidance to README.md and docs/claude.md/repo/architecture.md.

Auth model after this change

  • Stdio mode: the local user's SOCKET_API_TOKEN authenticates every tool.
  • HTTP mode: org-scoped tools use the caller's bearer token (or OAuth); they no longer borrow the operator's deploy key.

Testing

pnpm test — new HTTP-server and server cases assert the caller-scoped behavior.

Add README reference entries for the organizations, alerts, threat_feed,
package_files, package_file_contents, and package_file_grep tools, plus an
authentication section and a worked organizations -> alerts example. Mirror
the tool inventory in the architecture doc.
…mode

The organizations, alerts, threat_feed, and package_files tools resolved
their Socket token through resolveAuthToken, which falls back to the
boot-time static key. In HTTP mode that key is the deploy operator's, so a
shared/hosted server answered every caller's org lookup with the operator's
private organizations, alerts, and threat feed.

Split the resolver: resolveScopedAuthToken (per-tenant tools) returns the
per-request token, and only falls back to the static key when it is the
local user's own (stdio mode); in HTTP mode it returns undefined so the tool
emits the auth-required error. setStaticApiKey now records whether the key is
shared (HTTP) or user-owned (stdio). Non-OAuth HTTP mode reads the caller's
Authorization: Bearer token into req.auth so per-tenant tools act on the
caller's behalf. depscore keeps the public static fallback since package
scores are not tenant-scoped.
Comment thread README.md
export SOCKET_API_TOKEN="your-socket-api-token"
```

When no token is available, these tools return: `Authentication is required. Configure SOCKET_API_TOKEN for stdio mode or connect through OAuth-enabled HTTP mode.`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Consider not quoting the verbatim error string here. 269acc0 reworded AUTH_REQUIRED_MSG in lib/server.ts but this line still shows the old text, so the doc and the code have already drifted. The string is a human-readable diagnostic, not a contract clients match on, so pinning it in prose just creates a two-place-update trap — and the paragraph above already explains the per-transport auth model, making the quote redundant. Describing the behavior keeps lib/server.ts as the single source of truth.

Suggested change
When no token is available, these tools return: `Authentication is required. Configure SOCKET_API_TOKEN for stdio mode or connect through OAuth-enabled HTTP mode.`
When no token is available, these tools return an authentication-required error explaining how to supply one for each transport.

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.

2 participants