mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 05:47:10 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - App connections sign in with OAuth, and an operator can set a deployment-wide OAuth client with `PAPERCLIP_TOOL_OAUTH_*` variables > - The server picked that client by a provider name, and a connection's own settings could set both the provider name and the token URL > - So a deployment client secret could go to a token URL that the deployment did not choose > - A deployment secret must go only to the endpoint of the app it was set up for > - This pull request pins each deployment client to the token endpoint that its app definition fixes, and fails closed for any other endpoint > - The benefit is that member-entered or custom endpoints get only a member-entered client ## Linked Issues or Issue Description Refs #22635 **What happened?** `configuredOAuthClientForConnection` returned the deployment client for any connection whose provider name matched, or the unsuffixed client for any connection. The token exchange then sent that client secret to the connection's token URL. **What did you expect to happen?** A deployment client goes only to the token endpoint that its app definition fixes. A custom endpoint needs a client that the member adds. **Steps to reproduce** Set a provider-specific deployment client. Create a custom connection that names that provider and a different token URL, and start sign-in. The new unit tests cover this case. **Impact** Secret-handling hardening for deployment OAuth clients. ## What Changed - `configuredOAuthClientForConnection` now takes the token URL that the caller will post to. It returns a deployment client only when the connection comes from a real app definition, the provider is that app, the method lists `customer` ownership, and the token URL equals the method's `defaults.tokenEndpoint` (or, when the method fixes no token endpoint, is on the exact host of its fixed server, discovery, metadata or authorization URL). - A pasted (custom) server never gets a deployment client, including the unsuffixed one. It needs a client of its own, or CIMD or dynamic registration. - The token URL is required at every call site: start, callback, connection refresh and grant refresh. - When a deployment client exists but the endpoint does not match, and the connection has no client of its own, sign-in fails with `oauth_instance_client_endpoint_mismatch` and a clear message. - Pin `defaults.tokenEndpoint` in the Asana and Railway definitions, whose token endpoints are on another host than their MCP servers. - Update `doc/connections/GENERIC-REMOTE-MCP.md` and `doc/connections/CONNECTOR-PLAYBOOK.md`. ## Verification - New `server/src/services/tool-access/oauth/client-settings.test.ts` (16 tests): other hosts, a path that resolves elsewhere, plain HTTP, vendor subdomains, another port, a missing URL, empty or padded gallery markers, colliding host names, a custom connection that names a provider, the unsuffixed client on a custom connection, and a connection that names another app's provider all get no deployment client. Slack's fixed endpoint, Notion's server host and the pinned Asana and Railway endpoints still get it. These cases failed before the fix and pass now. - `server/src/__tests__/generic-mcp-connection.test.ts` and the machine-to-machine test in `tool-access-service.test.ts` now check that a pasted server never receives the deployment client or secret. Both failed before the fix. Two other pasted-server tests now use a client of their own. - A positive test sends the Slack deployment client to Slack's pinned token endpoint, with its secret, and nowhere else. - The connect route keeps the draft and returns `manualClientRequired` with a plain reason when a deployment client cannot be used (route and UI tests). - `npx vitest run` on the OAuth service and connection tests: 686 tests pass. Shared app-definition tests pass. `tsc --noEmit` for `server` passes. - `pnpm verify` exits 2 because a global CI input (a doc) changed. Required CI gives the broad coverage. ## Risks - A self-hosted deployment that used `PAPERCLIP_TOOL_OAUTH_*` for a pasted server must add a client to that connection. Sign-in shows a clear error instead of sending the secret. - A gallery app with `customer` ownership whose token endpoint is on another host than its fixed URLs needs `defaults.tokenEndpoint` to keep using a deployment client. Asana and Railway are pinned here. Box, Notion, PostHog, Sentry and Xero rely on the same-host rule: if their discovery returns a token endpoint on another host, a deployment-wide client is refused until the endpoint is pinned, and a client added to the connection always works. A test lists these apps by name, so a new app must choose. Gallery apps with a fixed token endpoint (Slack, Linear, Google) do not change. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, in Claude Code with tool use and code execution. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>