Files
co-lite/openspec/changes/fix-company-scope-fail-closed/proposal.md
T
ngqileandClaude Opus 5.5 998e04b844 fix(mobile-api): fail closed for admins outside the company model
An admin with no company who is not a super admin now gets 403
COMPANY_REQUIRED on every company-scoped request instead of seeing all
companies. The module check and the email detail treat only a real super
admin (no company and role 1) as super; a company user still holding
role 1 gets only what their other roles grant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-12-01 09:31:55 +08:00

24 lines
1.4 KiB
Markdown

## Why
The whole-branch review of add-company-scoping (PR #25) found that the code trusts the "every non-super admin belongs to a company" rule instead of enforcing it. An admin user with no company who is not a super admin (left over from before companies, or created by a direct DB edit) is scoped to all companies. A company user who still holds role 1 skips every module check and is treated as a super admin when reading super admins' emails.
## What Changes
- Company scope fails closed: an admin with no company who is not a super admin gets 403 `COMPANY_REQUIRED` on every company-scoped admin endpoint instead of seeing all companies.
- The admin module check grants all modules only to a super admin (no company and role 1), not to any holder of role 1.
- The email detail hides super admins' emails from every caller who is not a super admin, using the same super-admin test.
## Capabilities
### New Capabilities
### Modified Capabilities
- `company-scoping`: adds the "Invalid admins fail closed" requirement for the two invalid states.
## Impact
- `solvway-mobile-api`: `AdminCompanyScope`, `AppAccessAspect`, `AdminEmailService`.
- No API shape, schema or portal change. Valid users (super admins, and staff with a company) see no difference.
- Deferred: the capture event list still loads only the first 100 enabled events (marked `ponytail:` in `AdminEventLeadService`).