mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-18 06:01:49 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The built-in Google Workspace connector uses Paperclip's own Google OAuth client through the Paperclip Cloud broker, or a customer-owned client > - Google is reviewing that client for exactly 14 scopes (Gmail read/compose, Drive read/file, Docs, Sheets, Slides, Calendar) > - The code still accepted the old 21-scope union for the unified connection, and other Paperclip-managed Google methods (Gmail archive, Chat, People, Workspace Search) could ask the same client for scopes outside the submission > - A consent request for an undeclared scope through the verified client breaks the review > - This pull request makes the 14 an explicit constant, enforces it on every unified-connection request, callback and refresh, and stops new consent for managed Google profiles outside it > - The benefit is that Paperclip's Google client cannot request a scope that Google has not reviewed, while saved connections keep working ## Linked Issues or Issue Description Refs the plan in `doc/plans/2026-11-17-google-workspace-code-fixes.md` (items 2, 3 and part of 10). **What happened?** The unified `workspace.all` profile was the 21-scope legacy union, and `isGoogleWorkspaceScopeGrant` accepted any subset of it. The Gmail `paperclip-archive` method asked for `gmail.modify`. The Chat, People and Workspace Search cards had Paperclip-managed methods with Chat, Contacts, Directory, profile and `calendar.readonly` scopes. None of these are in the Google submission. **Expected behavior** Paperclip's own Google client requests, stores and refreshes only the 14 submitted scopes. New managed setup is not offered for anything else. **Steps to reproduce** 1. Advertise `gmail.archive` (or `chat.read`) from the broker. 2. Open Apps. The managed archive/Chat method is offered, and starting it signs a broker session for scopes outside the 14. 3. Refresh a unified grant: the signed binding lists all 21 legacy scopes. ## What Changed - `packages/shared/src/google-workspace-connectors.ts`: add `GOOGLE_WORKSPACE_SUBMITTED_SCOPES` (the 14, written out by hand). `workspace.all` now uses it. `isGoogleWorkspaceScopeGrant` checks against it. Add `googleWorkspaceProfileWithinSubmittedScopes`. - `server/src/services/paperclip-cloud-connector.ts`: add `paperclipCloudConnectorConsentAllowed`. `startAuthorization` refuses a Google profile outside the 14 before any broker call. `appWithPaperclipCloudConnectorAvailability` does not offer those methods for new setup, even when the broker advertises them. - `authorization-start.ts`: a saved connection on such a profile cannot restart consent (`paperclip_cloud_connector_scope_not_offered`, 422). - Capping contract, the same on managed and customer-owned OAuth (`paperclip-cloud-connector.ts` `openCredentials`, `cloud-callback.ts`, `direct-callback.ts`, `grant-refresh.ts`): Paperclip caps Google's reported scopes to the 14 (`googleWorkspaceSubmittedScopesIn`) and to the saved request, then continues. A scope outside the 14 is ignored and never enables an action. Only missing scope evidence or an empty result marks the grant for reconnecting. Reconnecting with a new service choice always works. What Paperclip *requests* stays fail-closed: an outgoing unified authorization request with any scope outside the 14 is rejected. - Docs: `doc/connections/GOOGLE-WORKSPACE.md`, `doc/connections/GOOGLE-WORKSPACE-SERVICE-CONSENT.md`. - `tests/runner-e2e/source-sdk-public-inputs.json`: refreshed pins for the changed shared file. ### Investigation **Scope flow, unified connection.** Both paths start in `authorization-start.ts`. The requested set comes from the picker (`googleWorkspaceSelectedScopes`), a saved draft, or the saved grant, and must be inside the method's `scopesHint` (the 14 since the connector was added in #15545). Managed: `cloudConnector.startAuthorization` signs `scp` = the request; the broker validates it as a subset of its registry; the claim is unsealed with the request as AAD; `cloud-callback.ts` caps Google's grant to the request. Customer-owned: `direct-callback.ts` checks Google's raw `scope`, then caps it. Refresh: managed refresh signs `scp` = the profile definition (previously 21) and unseals with that set as AAD; customer refresh checks the raw `scope`. **What depends on the 21-scope set.** Only the managed refresh binding (`scp` and envelope AAD) and tests. The broker (`paperclip-cloud` origin/master, `src/connections/providers.ts`, `broker.ts`) accepts any nonempty, duplicate-free subset of its `workspace.all` union for session, claim and refresh, and seals with the signed `scp`. So narrowing the app's `workspace.all` to 14 keeps the contract. I narrowed the definition itself instead of adding a parallel check. A saved unified grant can still report one of the 7 extra scopes: older app versions signed the 21-scope `workspace.all` binding on refresh, and Google can return scopes the same client was granted before. This PR therefore caps those scopes instead of failing the grant. **Managed Google methods.** See the table below. The broker's origin/master registry has no `gmail.archive` profile, so `paperclip-archive` could not reach the managed client today. | App / method | Profile | Scopes | Before | After | | --- | --- | --- | --- | --- | | google-workspace / paperclip-workspace | workspace.all | subset of the 14 | 21 accepted | 14 only | | gmail / paperclip-read, paperclip-draft | gmail.read, gmail.draft | gmail.readonly, gmail.compose | offered | offered | | drive, docs, sheets, slides, calendar / paperclip-read, paperclip-write | per service | inside the 14 | offered | offered | | gmail / paperclip-archive | gmail.archive | + gmail.modify | offered if advertised | saved only | | google-chat / paperclip-read, paperclip-write | chat.read, chat.write | chat.* | offered if advertised | saved only | | google-people / paperclip-read | people.read | directory, contacts, userinfo.profile | offered if advertised | saved only | | google-workspace-search / paperclip-read | workspace-search.read | + calendar.readonly, chat.messages.readonly | offered if advertised | saved only | "Saved only": the method stays in the app definition so saved connections resolve their method, refresh and run. New setup and new consent are refused. Customer-owned methods are unchanged. ### Broker changes needed in paperclip-cloud (not in this PR) 1. Narrow the `workspace.all` request allowlist for `session` (and the provider URL) to the 14. On refresh and claim, cap Google's reported scopes to the allowlist (or ignore extras) instead of rejecting with `provider_rejected`, and keep accepting a signed `scp` binding of the old 21 from older app versions until they are retired. 2. Drop or disable `chat.read`, `chat.write`, `people.read`, `workspace-search.read` for new sessions on the verified client. Keep refresh for saved grants until the owner retires them. 3. Do not merge the `gmail-archive-oauth-profile` branch for the Paperclip-managed client. ## Verification - Red first, then green: `pnpm exec vitest run packages/shared/src/google-workspace-connectors.test.ts server/src/services/paperclip-cloud-connector.test.ts` (13 new or changed tests failed before the change). - Red first, then green: `pnpm exec vitest run server/src/__tests__/tool-access-service.test.ts -t "refuses new managed setup|saved Paperclip-managed Gmail archive|fails closed on invalid refreshed|pilot"` (8 failed before the change). - Red first, then green: `pnpm exec vitest run server/src/__tests__/tool-access-service.test.ts -t "caps a|keeps a .* grant on its submitted|reconnects a"` (4 capping tests failed on the earlier fail-closed revision; both reconnect tests pass). - `pnpm exec vitest run server/src/__tests__/tool-access-service.test.ts -t "combined Workspace|Workspace|Gmail|managed"`: 161 passed. Full `tool-access-service` and `connection-management.integration` files: 599 passed on the earlier revision. - `pnpm exec vitest run packages/shared/src/app-definitions.test.ts server/src/services/gmail-tool-governance.test.ts server/src/services/gmail-archive-tool-policy.test.ts`: pass. - `pnpm --filter @paperclipai/shared typecheck`, `pnpm --filter @paperclipai/server typecheck`: pass. - `pnpm verify` returned exit 2 (a global CI input changed). Required CI supplies the broad coverage. ## Risks - Rollout order is app first, then broker. Refresh now signs the 14. If the broker narrows `workspace.all` first, refresh from app versions that still sign 21 (including self-hosted instances on the broker) fails until they upgrade. - A saved unified grant whose provider-reported scopes include a scope outside the 14 keeps working on its in-set scopes; the extra scopes no longer enable any action. A grant with only out-of-set scopes needs reconnecting, and a reconnect with a new service choice succeeds. - When the broker narrows `workspace.all` to the 14, it must cap or ignore extra scopes on refresh and claim (it re-validates them today), not reject saved grants. - Saved Chat, People, Workspace Search and Gmail archive managed connections keep working, but their owners cannot reconnect them through Paperclip's Google client. They see a 422 with a plain message. The owner must decide whether to retire them. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use and code execution in Claude Code. ## 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 - [x] All Paperclip CI gates are green - [x] 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>