paperclip/server/src/routes
Dotta 93fdb9c218
[codex] Harden same-company CEO authorization (#8276)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Companies are the primary tenant boundary for agents, board users,
settings, and portability operations.
> - CEO agents need limited same-company management powers, but those
powers must not cross into another company.
> - The affected company routes mixed route-level access checks with
validation middleware and repeated CEO checks, which left adjacent
mutation and portability surfaces easy to drift.
> - This pull request centralizes same-company CEO-or-board
authorization for those company-scoped surfaces.
> - It also adds regression coverage proving a CEO agent from one
company cannot read, mutate, archive, delete, export, or import against
another company.
> - The benefit is tighter company isolation without removing legitimate
same-company CEO operations.

## Linked Issues or Issue Description

Internal task: PAP-11205 / PAP-11347.

Bug report:
- What happened: same-company CEO authorization for company settings,
branding, and portability routes was implemented per-route, making it
possible for adjacent surfaces to drift and risking company-boundary
mistakes.
- Expected behavior: an agent API key must only manage the company that
owns the authenticated agent, and only CEO agents should get the limited
same-company management permissions.
- Steps to reproduce: authenticate as a CEO agent from Company A and
call Company B company routes such as `PATCH /api/companies/:companyId`,
`PATCH /api/companies/:companyId/branding`, export/preview export, safe
import preview/apply, archive, delete, or read.
- Version/commit: fixed on this branch at `45edaccb8` on top of
`public/master` `ddc193c2b`.
- Deployment mode: server API behavior; no UI change.

Related search results reviewed, not duplicates of this exact route
hardening:
- Refs #2212
- Refs #1083
- Refs #8053

## What Changed

- Added a shared `assertSameCompanyCeoAgentOrBoard` company route guard
and reused it for company settings, branding, export, and safe import
endpoints.
- Moved request parsing after authorization on sensitive company
mutation/export/import routes so unauthorized cross-company callers are
rejected before route body validation side effects or service calls.
- Tightened archive and delete ordering to assert route company access
before board-only mutation authorization.
- Added a cross-company company-route authorization regression suite
covering read, settings, branding, archive, delete, export, export
preview, import preview, and import apply paths.
- Extended adjacent route/service tests to prove non-CEO and
cross-company agent keys are rejected on the relevant company-scoped
surfaces.
- Addressed Greptile follow-ups by removing a redundant board assertion
and inlining the portability authorization wrapper.

## Verification

Local focused verification on rebased head `45edaccb8`:
- `pnpm exec vitest run
server/src/__tests__/companies-route-cross-company-authz.test.ts
server/src/__tests__/company-branding-route.test.ts
server/src/__tests__/company-portability-routes.test.ts
server/src/__tests__/agent-permissions-routes.test.ts
server/src/__tests__/authorization-service.test.ts
server/src/__tests__/openclaw-invite-prompt-route.test.ts`
  - 6 test files passed
  - 127 tests passed

Remote PR checks on rebased head `45edaccb8`:
- Paperclip PR workflow: green, including policy, typecheck, build, e2e,
canary dry run, workspace tests, server general tests, and all
serialized server shards.
- Greptile Review: success with 5/5 confidence on `45edaccb8`.
- Greptile review threads: all resolved.

## Risks

Low to moderate risk. This intentionally tightens company route
authorization and changes whether some unauthorized requests fail at the
authz layer before schema validation. Legitimate board users and
same-company CEO agents remain covered by tests, but callers that
depended on validation errors from unauthorized company routes will now
receive authorization errors first.

No migrations. No `pnpm-lock.yaml` changes. No `.github/workflows`
changes. No screenshots or design images added.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

OpenAI Codex, GPT-5.5-based coding agent with tool use, terminal
execution, repository inspection, and GitHub connector access.

## 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 run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] If this change affects the UI, I have included before/after
screenshots (N/A: no UI change)
- [x] I have updated relevant documentation to reflect my changes (N/A:
no docs needed beyond this PR description)
- [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

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-06-22 10:34:13 -05:00
..
access.ts Improve CLI API parity coverage (#6626) 2026-06-02 17:13:29 -07:00
activity.ts Add low-trust review containment (#7530) 2026-06-05 16:48:02 -05:00
adapters.ts feat(adapters): allow external overrides of built-ins (#7394) 2026-06-07 10:47:01 -07:00
agents.ts fix(server): let codex_local agents inherit host Codex login by default (#8425) 2026-06-20 22:51:56 -07:00
approvals.ts [codex] feat(watchdog): add task watchdog control plane (#8339) 2026-06-19 15:38:52 -05:00
assets.ts Use attachment-size limit for company logos 2026-03-16 10:13:19 -05:00
auth.ts feat: implement multi-user access and invite flows (#3784) 2026-04-17 09:44:19 -05:00
authz.ts fix: resolve secret refs before sandbox draft probes (#8256) 2026-06-18 07:48:09 -07:00
board-chat.ts feat(ui): NUX rework behind enableConferenceRoomChat experimental flag — capsule onboarding, conference-room chat, unified composer (#8000) 2026-06-11 16:32:55 -05:00
cloud-upstreams.ts [codex] Add local Cloud Upstream sync (#6548) 2026-05-22 09:56:22 -05:00
companies.ts [codex] Harden same-company CEO authorization (#8276) 2026-06-22 10:34:13 -05:00
company-import-paths.ts [codex] Runtime control-plane fixes (#6380) 2026-05-20 10:37:11 -05:00
company-skills.ts fix(server): resolve published skills catalog package root and fallback (#8327) 2026-06-19 09:14:41 -07:00
costs.ts Add low-trust review containment (#7530) 2026-06-05 16:48:02 -05:00
dashboard.ts refactor: rename packages to @paperclipai and CLI binary to paperclipai 2026-03-03 08:45:26 -06:00
environment-selection.ts refactor(environments): make execution environments instance-scoped (#8375) 2026-06-20 09:42:53 -07:00
environments.ts refactor(environments): make execution environments instance-scoped (#8375) 2026-06-20 09:42:53 -07:00
execution-workspaces.ts Add low-trust review containment (#7530) 2026-06-05 16:48:02 -05:00
file-resources.ts Add workspace file viewer and artifact links (#7681) 2026-06-09 17:17:43 -05:00
goals.ts Add versioned telemetry events 2026-04-03 09:25:00 -05:00
health.ts [codex] Add private browser first-admin claim flow (#6755) 2026-05-27 21:15:01 -10:00
inbox-dismissals.ts Persist non-issue inbox dismissals 2026-04-09 06:16:05 -05:00
index.ts Add workspace file viewer and artifact links (#7681) 2026-06-09 17:17:43 -05:00
instance-database-backups.ts [codex] Add backup endpoint and dev runtime hardening (#4087) 2026-04-20 06:08:55 -05:00
instance-settings.ts refactor(environments): make execution environments instance-scoped (#8375) 2026-06-20 09:42:53 -07:00
issue-tree-control.ts Improve CLI API parity coverage (#6626) 2026-06-02 17:13:29 -07:00
issues-checkout-wakeup.ts Cut over OpenClaw adapter to strict SSE streaming 2026-03-05 15:54:55 -06:00
issues.ts Fix mention-granted closed issue comments with resume intent (#8350) 2026-06-19 16:47:06 -07:00
llms.ts [codex] Harden create-agent skill governance (#4422) 2026-04-24 14:15:28 -05:00
openapi.ts refactor(environments): make execution environments instance-scoped (#8375) 2026-06-20 09:42:53 -07:00
org-chart-svg.ts Improve generated company org chart assets 2026-03-23 16:58:07 -05:00
plugin-ui-static.ts Add plugin framework and settings UI 2026-03-13 16:22:34 -05:00
plugins.ts Auto-build bundled plugins on install (#8254) 2026-06-17 22:39:55 -07:00
projects.ts Add low-trust review containment (#7530) 2026-06-05 16:48:02 -05:00
resource-memberships.ts [codex] Add resource membership controls (#6677) 2026-05-25 13:12:41 -05:00
routines.ts Add routine revision history and restore flow (#5285) 2026-05-05 11:54:52 -05:00
secrets.ts [codex] Provider vault secrets UX (#6381) 2026-05-19 15:50:23 -05:00
sidebar-badges.ts feat: implement multi-user access and invite flows (#3784) 2026-04-17 09:44:19 -05:00
sidebar-preferences.ts [codex] Improve workspace runtime and navigation ergonomics (#3680) 2026-04-14 12:57:11 -05:00
teams-catalog.ts [codex] Add teams catalog extraction (#7550) 2026-06-05 12:55:49 -05:00
user-profiles.ts [codex] Add access cleanup and user profile page (#4088) 2026-04-20 06:10:20 -05:00
workspace-command-authz.ts Add cheap model profiles for local adapters (#4881) 2026-04-30 15:32:04 -05:00
workspace-runtime-service-authz.ts Add low-trust review containment (#7530) 2026-06-05 16:48:02 -05:00