Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
Remove the "0" Global-Company Permission Wildcard
Status: IMPLEMENTED 2026-08-18 (2.8 — commit 0cbaf1390, verified in browser ba340f2d9)
Removes the "0" sentinel that grants a permission across ALL companies (present
and future) from Carbon's authorization layer. NIST 800-171 3.1.5 (least
privilege) hardening; item 2.8 of .ai/plans/2026-08-15-nist-800-171-app-remediation.md.
Decision confirmed by the user: "we don't use it."
Problem
A permission array in userPermission.permissions (or an employeeTypePermission
column) containing "0" is interpreted as "granted for every company." It is a
broad-grant primitive the audit flagged under AC-6, and it auto-covers
future-created companies — exactly the over-broad grant an assessor dislikes.
What actually interprets "0" (grounded recon 2026-08-16)
- DB (2 functions):
has_company_permission(claim, company)(latest def20241210140215_rls-performance.sql:12, theELSIF '0' = ANY(...)branch) andget_companies_with_employee_permission(permission)(latest def20260219162954_api-key-scopes-rate-limits.sql:280, theIF ... '0'::text = ANYexpand-to-all-employee-companies block at ~line 328). get_claims(uid, company)is transport, not interpreter — returns the rawuserPermission.permissionsJSONB; no"0"logic. No change. Same forget_companies_with_employee_role().is_claims_admin()(20230123004206_claims.sql:3, only def) gatesupdatePermissionsviahas_company_permission('update_users','0')= "must be a global user-admin." It takes no company arg.- App (10 sites):
auth.server.ts:364; six inusers.server.ts(makeCompanyPermissionsFromClaims1164/1169/1174/1179,makeCompanyPermissionsFromEmployeeType1279/1282/1285/1288);usePermissions.tsx:29;search.tsx:63; workflow$id.test-run.tsx:192;owner.ts:83. is_claims_admincallers (2, both withcompanyIdin scope, none in SQL):apps/erp/app/modules/users/users.server.ts:1441andpackages/jobs/src/inngest/functions/tasks/update-permissions.ts:53.- No seed grants
"0". After removal a residual"0"fails closed (grants nothing; no cross-tenant leak) — so the only risk is a lockout, prevented below.
Resolved decisions
- D1 — Expand-then-drop (safe-by-construction). One atomic migration:
FIRST rewrite any residual
"0"grant to explicit company IDs, THEN redefine the functions to stop interpreting"0". No-op if truly unused; no lockout if not. (Live data unverifiable this session — stack down, MCP needs auth — so correctness must not depend on the "we don't use it" claim.) - D2 —
is_claims_admin(company text)(per-company, option B).DROP FUNCTION is_claims_admin(); createis_claims_admin(company text)→has_company_permission('update_users', company). Both call sites pass thecompanyIdalready in scope. It is the sole authZ before a service-role write, so tighten (per-company) rather than loosen (any-company). Rejected:has_any_company_permission. - D3 — Expansion targets (behavior-preserving).
userPermission.permissions: each array containing"0"→ the user'suserToCompanycompany IDs (any role — covers both the employee-RLS path, which re-filters to employees, and the portal path). Empty membership →"0"simply removed (fails closed; the user had no real access anyway, since RLS requires auserToCompanyrow).employeeTypePermission.{create,update,view,delete}:array_replace('0' → employeeType."companyId")(each type belongs to one company). - D4 — Reject
"0"going forward. The twoupdatePermissionswriters strip"0"from every array before persisting, so the authoritativeuserPermissiontable can never hold"0"again (the UI never produces it; the only source is a hand-authoredemployeeTypePermissionpassed throughmakePermissionsFromEmployeeType). - D5 — One migration, ordered,
NOTIFY pgrst. data-expand → redefine functions →NOTIFY pgrst, 'reload schema'(the newis_claims_adminsignature must be reloaded, per the migrate-append lesson).
Out of scope
get_claims,get_companies_with_employee_role— no"0"; untouched.- Removing the deprecated
has_company_permissionhelper — still used by supplier/customer-portal RLS; only its"0"branch is dropped. - Migrating portal RLS off the deprecated helper (separate cleanup).