Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

Back to skills

Effect Sql Rls

ASecurity

Use when writing any query, migration, or test that touches tenant data in this repository. Covers withOrgScope and withWorkerScope, the two Postgres roles and why the boundary is in the database rather than in a lint rule, the shape a row-level security policy has to take, when Effect.orDie is right, and why a fixture seeds through the product's own write path.

4 stars
0 votes
0 copies
0 views
Added 9/22/2026
ai-agentsrustsqldockerdatabasesecurity

Security Analysis

A100/100

Scanned 9/22/2026

Install to Claude Code

$npx -y skills add vantionlabs/saas-starter --skill effect-sql-rls --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Effect Sql Rls?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Effect Sql Rls
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/vantionlabs-effect-sql-rls/badge)](https://www.skillsdirectory.com/skills/vantionlabs-effect-sql-rls)

More formats (shields.io, HTML) on the badges page.

Download Zip
Files
SKILL.md
---
name: effect-sql-rls
description: Use when writing any query, migration, or test that touches tenant data in this repository. Covers withOrgScope and withWorkerScope, the two Postgres roles and why the boundary is in the database rather than in a lint rule, the shape a row-level security policy has to take, when Effect.orDie is right, and why a fixture seeds through the product's own write path.
---

# Tenant data, and the two things that keep it apart

Every tenant-owned table is protected **twice**: a row-level security policy in Postgres,
and `withOrgScope` around the query. Neither is trusted alone. Unit tests cover each; only
`e2e/tests/tenancy.spec.ts` shows two real users, session to SQL, failing to see each
other's rows.

## The connection is the boundary

`packages/database/src/roles/init.sql` makes two roles:

- **`vantion`** — what every application process connects as, and `NOBYPASSRLS`. A handler
  that forgets `withOrgScope` therefore reads **nothing** rather than reading everybody.
- **`admin`** — holds `BYPASSRLS`, for the cross-tenant surface only. Which process may
  cross tenants is decided by Postgres, not by a reviewer.

This was not true until recently. `docker compose` set `POSTGRES_USER: vantion`, making it
the bootstrap **superuser** — so every policy in this schema was inert while
`pg_class.relrowsecurity` read true. `packages/database/test/Role.test.ts` asserts the
connection cannot bypass, because a suite pointed at a superuser passes every tenancy test
while proving nothing.

Switching the role found two production bugs, both the same shape: a worker escape on
`using` but not on `with check`, and an UPDATE is checked by both.

## Which scope

| Function                    | Who uses it                                        | What it sets                         |
| --------------------------- | -------------------------------------------------- | ------------------------------------ |
| `withOrgScope`              | A handler with a caller                            | `app.current_org` from `CurrentUser` |
| `withOrgScopeFor(orgId, …)` | A seed, a test, anything with an id and no session | the same, from a plain id            |
| `withWorkerScope`           | The relay, delivery, the Stripe webhook            | `app.worker = 'on'`                  |

`withOrgScopeFor` lives in `packages/database` and `withOrgScope` in
`@vantion/module-iam`, because reading the caller is an identity concern and `database`
would otherwise depend on the module that depends on it.

**Filter by organization _and_ scope.** Both, never either. `currentSubscription` relied on
the policy alone and every organization read the first subscription row in the table — a
superuser, or any role with BYPASSRLS, ignores row-level security even on a FORCEd table,
which is what a managed Postgres often hands you.

## Writing a policy

Split by command rather than widening one. `0012_worker_writes.sql` is the worked example:
INSERT stays exactly as strict as it was, and the worker gains only the ability to update
what it is already allowed to read.

```sql
create policy "x_select" on "x" for select
  using ("organizationId" = current_setting('app.current_org', true)
         or current_setting('app.worker', true) = 'on');

create policy "x_insert" on "x" for insert
  with check ("organizationId" = current_setting('app.current_org', true));
```

A table better-auth owns gets **no policy at all** rather than a permissive one — see the
`better-auth` skill and `0011_sso.sql`.

## `Effect.orDie` on a query is usually right

`RULES.md` says when. What reaches an `orDie` on a `sql` call is the database being
unreachable, the query being wrong, or a policy refusing it — all bugs. The durable rule:
**adding a constraint to a table is the moment to revisit every `orDie` writing to it**,
because that is when a defect becomes a message somebody needed.

## Tests seed through the product's write path

Not because it is tidy, but because a fixture needing more privilege than the application
has is a fixture describing a state the application cannot produce. Use `withOrgScopeFor`,
not a bare insert — a bare insert into a policied table is refused outright.

Database-backed tests skip without a database. `describe.skipIf(testDbUrl() === undefined)`.

## Where to look

- `packages/database/src/OrgScope.ts`, `packages/modules/iam/src/identity/OrgScope.ts`
- `packages/database/src/migrations/0002_rls.sql`, `0012_worker_writes.sql`
- `packages/database/test/Role.test.ts` — the test that keeps the role honest
- `packages/modules/admin/` — the only thing using the second role, through `crossTenant`

Attribution

vantionlabsvantionlabs
View sourceMore from vantionlabs →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman

Ultra-compressed communication mode that cuts output tokens while keeping technical accuracy. Levels: lite, full, ultra and the wenyan variants. Use for /caveman, "caveman mode", "talk like caveman", "be brief" or "less tokens".

1066601 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

686011 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3351 votes

catchup

Recovers the conversation and failed tool calls of a previous Codex, Claude Code, Antigravity, Cline, Copilot CLI, Cursor, DeepSeek Harness, Kimi, OpenCode, Pi Agent, or ZCode session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", asks to recover/summarize a previous session before continuing, or asks to diagnose or report a catchup failure. Do NOT use for the current conversation, git history, or any non-agent log.

651 votes

math-skill

A comprehensive mathematical reasoning skill for AI assistants — handles arithmetic to research-level problems with rigorous step-by-step reasoning, systematic verification, and transparent uncertainty handling

381 votes
View all in ai-agents →