Skip to content

fix(db): tighten organizations and competitors access policies - #1873

Merged
gkhngyk merged 1 commit into
mainfrom
security/tighten-org-competitor-access
Oct 30, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
security/tighten-org-competitor-access

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Tightens two access policies, with the app changes they need.

  • Organizations: members read their own organization; the table isn't readable without signing in. Onboarding now picks the new organization's id itself and inserts it without reading it back before the person joins it (web/src/lib/organization-insert.ts), retrying once with a suffix when the slug is taken.
  • Competitors: members read their brand's competitors; adding, editing and removing them is for Admins and Managers, as 00382 does for topics. The Competitors page and Citations' "Add as competitor" show those controls to Admins and Managers only, and a removal that changed nothing now says so.

Migration: 00387_organization_competitor_access.sql. schema.sql is rebuilt with build-schema.sh.

Related

Follows 00382 (topics).

Type

  • Bug fix

How to test

  • Sign up a new account and finish onboarding: the organization is created and the dashboard opens.
  • As an Analyst, the Competitors page has no Add, Suggest or Delete; as a Manager, they work.

Deploy order

Merge first (the web deploys), then apply 00387: the new onboarding code works with both the old and the new policies.

Checks

  • Web vitest: 7,617 tests pass, including new policy and insert-helper tests.
  • tsc, eslint and prettier are clean on the touched files; plan-row.test.ts and next build pass.
  • The migration was run on production in a rolled-back transaction with each role.

🤖 Generated with Claude Code

https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A

organizations: a signed-in person reads the organization their profile
belongs to; the policies apply to signed-in people, and the anon role no
longer has table privileges. Onboarding creates the organization with an
id it chooses and no longer reads it back before the profile joins it; a
taken slug is retried once with a suffix (insertOrganization).

competitors: every member still reads them; adding, changing and deleting
need an admin or a manager of the brand's organization, as for topics
(00382). The Competitors page and Citations' "Add as competitor" show
their write controls to admins and managers only, and deleteCompetitor
reports a delete that removed nothing.

Adds 00387_organization_competitor_access.sql, rebuilds schema.sql, and
tests that replay the migrations' policies on both tables.
@gkhngyk
gkhngyk merged commit 703a686 into main Oct 30, 2026
6 checks passed
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant