Skip to content
Back to skills

1319 Rls 4bbb39df

ASecurity

RLS controls data access at the row level based on the authenticated user.

  • 9 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added October 11, 2026
databasesgosqlsecurityperformance

Security analysis

A100/100

Scanned October 11, 2026

npx -y skills add tools-only/X-Skills --skill 1319-rls_4bbb39df --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 1319 Rls 4bbb39df?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 1319 Rls 4bbb39df
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-1319-rls-4bbb39df/badge)](https://www.skillsdirectory.com/skills/tools-only-1319-rls-4bbb39df)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

SKILL.md
# Row Level Security (RLS)

RLS controls data access at the row level based on the authenticated user.

## Enabling RLS

```sql
alter table public.posts enable row level security;
```

## Policy Types

| Operation | Clause                 | Purpose                          |
| --------- | ---------------------- | -------------------------------- |
| SELECT    | `using`                | Filter which rows can be read    |
| INSERT    | `with check`           | Validate new rows                |
| UPDATE    | `using` + `with check` | Filter + validate                |
| DELETE    | `using`                | Filter which rows can be deleted |

## Common Policy Patterns

**1. User owns row:**

```sql
create policy "Users can view own data" on profiles
to authenticated
using ( (select auth.uid()) = user_id );

create policy "Users can update own data" on profiles
to authenticated
using ( (select auth.uid()) = user_id )
with check ( (select auth.uid()) = user_id );
```

**2. Public read, owner write:**

```sql
create policy "Public read" on posts
for select using (true);

create policy "Owner can modify" on posts
for all to authenticated
using ( (select auth.uid()) = author_id );
```

**3. Team/organization access:**

```sql
create policy "Team members can view" on documents
to authenticated
using (
  team_id in (
    select team_id from team_members
    where user_id = (select auth.uid())
  )
);
```

**4. Role-based access:**

```sql
create policy "Admins can do anything" on posts
to authenticated
using (
  exists (
    select 1 from users
    where id = (select auth.uid()) and role = 'admin'
  )
);
```

## RLS Performance Tips

**Always use `(select auth.uid())` instead of `auth.uid()`:**

```sql
-- SLOW (recalculates per row)
using ( auth.uid() = user_id )

-- FAST (calculates once, 99%+ improvement)
using ( (select auth.uid()) = user_id )
```

**Add indexes on RLS columns:**

```sql
create index idx_posts_user_id on posts using btree (user_id);
create index idx_documents_team_id on documents using btree (team_id);
```

**Specify roles with `TO`:**

```sql
-- Good: policy only applies to authenticated users
create policy "..." on posts to authenticated using (...);

-- Bad: policy applies to all roles including anon
create policy "..." on posts using (...);
```

## Viewing Policies

```sql
select schemaname, tablename, policyname, permissive, roles, cmd, qual, with_check
from pg_policies
where tablename = 'your_table';
```

Attribution

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

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.