docs(openspec): archive fix-company-scope-fail-closed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-01 09:32:21 +08:00
1 parent a1aa906a66
commit b6b05f12df
5 files changed
+17

No files matched your search

@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-12-01
@@ -0,0 +1,23 @@
## 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`).
@@ -0,0 +1,18 @@
## ADDED Requirements
### Requirement: Invalid admins fail closed
The system SHALL refuse every company-scoped request from an admin with no company who is not a super admin, and SHALL grant a company user who holds the super admin role only the modules and records their company and other roles allow.
#### Scenario: Admin without a company who is not a super admin
- **GIVEN** an admin user with no company and no super admin role
- **WHEN** they open Leads, Events, Users or any other company-scoped list or record
- **THEN** the request is refused with 403
- **AND** no company's records are returned
#### Scenario: Company user still holding the super admin role
- **GIVEN** a user of INS who holds the super admin role and a role granting only Leads
- **WHEN** they open Users or another super admin's email
- **THEN** the request is refused with 403
@@ -0,0 +1,10 @@
## 1. Fail closed
- [x] 1.1 `AdminCompanyScope.scope` and `requireCompanyForCreate` refuse (403 `COMPANY_REQUIRED`) an admin with no company who is not a super admin
- Depends on: none
- Scope: `solvway-mobile-api/src/**/useraccess/AdminCompanyScope*.java`
- Verify: `mvn -T 1C -q -pl solvway-mobile-api verify`
- [x] 1.2 `AppAccessAspect` skips the module check only for `AdminCompanyScope.isSuper`; `AdminEmailService` uses the same test
- Depends on: 1.1
- Scope: `solvway-mobile-api/src/**/useraccess/AppAccessAspect*.java`, `solvway-mobile-api/src/**/service/AdminEmailService*.java`
- Verify: `mvn -T 1C -q -pl solvway-mobile-api verify`