In a multi-user app the worst bug is one user seeing another's data. Add a model that writes queries or calls toolsTool useA model asking to run a function the app describes to it, such as a search or reading a file, with structured arguments. The app runs it and returns the result; the model runs nothing itself. and the risk grows. Do not rely on every line of code being right: put the rule in the databaseDatabaseA program that keeps an app's data organised and lasting, and lets it be searched and changed safely even with many users at once. The best-known kind is relational, spoken to in SQL, such as Postgres. itself.
What RLS is
Row level securityRow level security (RLS)A Postgres feature where the database itself decides which rows each user sees, by rules you write per table. If you forget a check in the code, the rule still protects the data. Talqeen's project privacy rests on it. is a Postgres feature Supabase uses heavily. Once enabled on a table, a query sees only the rows a policy allows:
alter table public.projects enable row level security;
create policy "owner_all" on public.projects
for all to authenticated
using (owner_id = (select auth.uid()))
with check (owner_id = (select auth.uid()));Even if code forgets the owner condition, the database returns the user's rows only.
Practical rules
- Enable RLS in the same migrationMigrationA file describing one change to the structure of a database, such as adding a table or a column, kept in the repository with the code. Migrations are applied in order, so every copy of the database reaches the same structure. that creates the table.
- Test the policies: sign in as one user, try to read another's row, expect failure. Talqeen does this for every project table, and checks that an admin cannot read any project either.
- Audit automatically: one command that fails when a table has no RLS keeps you from forgetting.
The service key is too strong
Supabase's service key bypasses RLS. It never reaches the browser, is read in one serverServerA computer or program that waits for requests and answers them, such as a web server returning pages or a database server. What runs on the server the user cannot see, so secrets and checks belong there. file used by admin services only, and is never handed to a tool a model calls.
Least privilege for the model
- Tools act as the user, so the same RLS applies.
- Separate read from write: a Talqeen project tokenTokenThe unit a model reads and writes text in, which may be a word, part of one or a punctuation mark. Prices and context limits are counted in tokens, and Arabic text often needs more tokens than English of the same length. is read or read-write, and read is enough most days.
- Narrow the scope: a Talqeen token reaches one project, and the tools take no project id at all.
- No delete tool unless truly needed, and then with human confirmation.
Why it matters with models
A model can be tricked by injectionPrompt injectionText that slips into a model's input (from a user, a web page or a file) and tries to change its instructions, such as "ignore the above". The defence is treating outside text as data, with strict limits on permissions. or simply be wrong. If protection lives only in the promptPromptThe text you give a model to work on, from a short question to long instructions with a role, context, examples and a required format. The quality of the output follows the clarity of the prompt more than its length., one mistake is enough; if it lives in the database and permissionsPermissionsWhat a tool or agent may do without asking you: reading files, running commands or reaching the network. Claude Code asks before anything you have not allowed, so do not approve everything without reading., the worst case is a failed query.