/claude-crown:sql-securityfrom Claude Crown
Securing the database layer of a TypeScript app on Postgres/Supabase — everything outside the row level. Covers separating and hiding API keys (publishable vs. secret, .env, key rotation after a leak), real account and role management (CREATE ROLE, group and login roles), granting privileges with GRANT/REVOKE and default privileges, who may create and drop tables and databases, rate limiting, and SQL injection prevention. ALWAYS use this skill when: keys, tokens, .env files or secrets appear; the user mentions "privileges", "roles", "permission", "GRANT", "access", "admin", "service_role", "anon key", "rate limit", "abuse", "injection", "DROP" or "who is allowed to"; an endpoint, edge function or server script touches the database; a key ended up in client code or the frontend; a new table needs grants. Also trigger when client code talks to the database directly, even if security was never mentioned.
Ships in Claude Crown. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
This skill protects the layers before and around row level security. Row level security
itself — which user may see which row — lives in rls-security.
The governing sentence:
The client must never be able to do more than the worst imaginable user should be able to do. Anything that reaches the browser is public: code, keys, network traffic.
| Area | Core question | Reference |
|---|---|---|
| Keys and secrets | Which key is allowed where? | references/keys-and-secrets.md |
| Roles and privileges | Who may perform which operation on which object? | references/roles-and-privileges.md |
| Rate limiting | How often may they do it? | references/rate-limiting.md |
| Injection | Can input become code? | references/injection.md |
There are exactly two classes of key:
| Class | Supabase format | Legacy (until end of 2026) | Belongs in |
|---|---|---|---|
| Public | sb_publishable_… | anon | browser, app, repo, CI — may be visible |
| Secret | sb_secret_… | service_role | servers, edge functions, workers only |
The secret key carries the Postgres attribute BYPASSRLS. It ignores every policy. An
sb_secret_… in a frontend bundle means full read and write access to the entire database for
every visitor.
Check this for every key in the code:
Does this file end up in the browser bundle?
├─ yes → publishable/anon only. Anything else is an incident.
└─ no → secret is allowed, but from process.env, never in source.
In Next.js, anything prefixed NEXT_PUBLIC_ is compiled into the bundle. So
NEXT_PUBLIC_SUPABASE_SECRET_KEY is always wrong, no matter how plausible it looks.
Legacy anon/service_role keys are being switched off by the end of 2026, and new projects
no longer receive them. Build new work directly on sb_publishable_… / sb_secret_….
Sources: Supabase — API keys, Migrating to new API keys
Key leaked? The emergency steps and their order are in references/keys-and-secrets.md.
The key point up front: reverting the commit is not enough — the key stays valid until it is
rotated.
Postgres has no separate concept of "users" and "groups", only roles. A role with LOGIN
behaves like an account, one without behaves like a group.
-- Group role (no login) — carries the privileges
create role app_readonly nologin;
grant usage on schema public to app_readonly;
grant select on all tables in schema public to app_readonly;
-- Login role — an actual account that inherits the group's privileges
create role reporting_service login password '…';
grant app_readonly to reporting_service;
Always attach privileges to the group role, never directly to the account. When a service or a person goes away, you revoke one membership instead of unwinding a dozen grants and missing one.
| Action | Who is allowed |
|---|---|
DROP TABLE | only the table owner (or a superuser). GRANT ALL is not enough |
ALTER TABLE, enabling/disabling RLS, creating policies | only the owner |
DROP DATABASE | the database owner or a superuser, and only with no open connections |
CREATE DATABASE | roles with the CREATEDB attribute |
| Creating and altering roles | roles with the CREATEROLE attribute |
| Everything | SUPERUSER — not available to customers on managed platforms like Supabase |
The consequence: ownership outranks grants. An application role must never own the tables, otherwise it can change the schema and its own policies.
Sources: Postgres — Database roles, Role attributes, DROP DATABASE
In existing Supabase projects, new tables in the public schema automatically receive
select, insert, update, delete for anon, authenticated and service_role. Those grants
do not go away when policies are added. So clean them up explicitly:
revoke all on my_table from anon;
grant select, insert, update, delete on my_table to authenticated;
Default rule of thumb: anon gets nothing, unless the table is deliberately public
(a price list, say) — and then only select.
The full grant matrix, ALTER DEFAULT PRIVILEGES and audit queries:
references/roles-and-privileges.md
Source: Supabase — Securing your API
Without limits, a single script can blow up the bill or saturate the database. RLS does not help here: someone who is authorised is authorised any number of times.
| Layer | What it limits | Where to configure |
|---|---|---|
| Auth | logins, OTP, emails, token refresh | Supabase dashboard → Authentication → Rate Limits |
| API / application | requests per user or IP on your own endpoints | middleware, edge function, Upstash Redis |
| Database | connections, query runtime, result size | pool size, statement_timeout, LIMIT |
Supabase Auth uses a token bucket per IP address with a capacity of roughly 30 requests and answers with 429 Too Many Requests when exceeded. The REST layer (PostgREST) has no built-in per-table limit — that one has to be built.
Concrete implementations (middleware, edge function plus Redis, statement_timeout,
pre-request function): references/rate-limiting.md
Sources: Supabase — Rate limits, Rate limiting edge functions
// dangerous: input becomes part of the command
const sql = `select * from customers where name = '${input}'`
// safe: input stays a value
const { data } = await supabase.from('customers').select('*').eq('name', input)
The Supabase client parameterises automatically. In an app like this, injection mostly appears
in three places: dynamic SQL inside plpgsql functions, SECURITY DEFINER without a fixed
search_path, and hand-built filter strings. All three, with countermeasures:
references/injection.md
Source: OWASP — SQL Injection Prevention
Run through this before every release:
[ ] 1. No sb_secret_ / service_role key in client code, in a NEXT_PUBLIC_ variable, or in the repo
[ ] 2. .env* is in .gitignore; .env.example contains only placeholders
[ ] 3. Every table in public has RLS enabled (check the Supabase Security Advisor)
[ ] 4. anon holds no grants on any internal table
[ ] 5. No application role owns the tables
[ ] 6. Every SECURITY DEFINER function has set search_path = ''
[ ] 7. Auth rate limits configured; your own endpoints have a limit
[ ] 8. statement_timeout set for the application role
[ ] 9. No string-concatenated SQL in code or in functions
[ ] 10. Key rotation is documented and has been rehearsed at least once
Points 3 and 4 can be checked automatically in Supabase: dashboard → Advisors → Security, or
supabase db lint. Points 1, 3, 4, 6 and 9 are also covered statically by the sql-king skill's
scripts/sql_scan.py — run it on the repository before the release checklist.
process.env, add rate limiting.references/keys-and-secrets.md — key types, .env layout, client/server separation in
TypeScript, leak response plan, rotation. Read for anything involving keys.references/roles-and-privileges.md — creating roles, the grant matrix, ownership, default
privileges, audit queries, app accounts vs. database roles. Read for every new table and any
privilege question.references/rate-limiting.md — auth limits, middleware, edge function with Redis, timeouts,
pool sizes, cost protection. Read for public or expensive endpoints.references/injection.md — parameterisation, dynamic SQL, format(), SECURITY DEFINER,
input validation with Zod. Read when writing functions or dynamic filters.At the end of every task, check:
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub 2fwn2rnh7v-pixel/claude-crown --plugin claude-crownOther plugins' skills for the same job
12 skills in this plugin
/api-guardAudits and hardens API usage in TypeScript web apps: rate limiting and quotas, API keys and paid calls in the backend instead of the frontend, protection against cost explosions, and lowering API consumption for the same result (caching, batching, debouncing, payload trimming, model routing). Script-backed quick scan of existing code. Use ALWAYS when: an API call, fetch(), axios or an SDK client is written; an endpoint, route, Server Action, server function or Edge Function is created; API keys, secrets, tokens, .env, NEXT_PUBLIC_/VITE_ variables appear; an external service is connected (LLM, weather, maps, payment, Supabase, Cloudflare); the user says "Rate Limit", "Quota", "Kosten", "teuer", "Rechnung", "Verbrauch", "zu viele Requests", "429", "API-Key", "Missbrauch", "cost", "usage", "throttle", "caching" or "prüf mal meine API-Nutzung". Also trigger implicitly — when the frontend calls an external service directly, or a search, autocomplete or polling loop is built without anyone mentioning cost.
/java-pioneerExpert playbook for writing production-grade Java (21/25 LTS) backends with Spring Boot 4 and connecting them to web frontends (React, Angular, Vue, plain TypeScript) with maximum safety and performance. Use this skill whenever the user writes, reviews, refactors, debugs, or designs Java code — Spring Boot services, REST APIs, JPA/Hibernate persistence, Spring Security, login/sessions/OAuth2/JWT, CORS or CSRF errors, OpenAPI contracts, TypeScript clients for a Java API, JVM or database performance, Maven/Gradle builds, or Java tests with JUnit/Mockito/Testcontainers — even if the user never says "best practices". Also use it for migrations from older Java versions or Spring Boot 2/3./prompt-verstaendnisInterprets and understands the prompts of a German-speaking developer working on his own app (Agrarmonitor, TypeScript). The user writes fast, directly and with natural typos — this skill decodes the actual intent, recognises the recurring three-agent setup (Research → Code → Test), identifies quality requirements and makes sure the self-reflection clause at the end of every piece of work is honoured. Use this skill ALWAYS when: the user writes a complex development prompt in German; mentions an agent setup; uses terms like "sehr detailliert", "spezifisch", "hinterfrage", "Agenten", "Testsprite", "Agrarmonitor"; or when the prompt contains several nested instructions that must be untangled. Also trigger on short prompts when they contain agent references or quality markers.
/rls-securityRow Level Security (RLS) in Postgres/Supabase — who may see, create, change and delete an individual ROW. Explains policies from the ground up (USING vs. WITH CHECK, one policy per operation, auth.uid(), auth.jwt()), gives ready-made patterns for owner, team and role based access, shows the performance traps (missing indexes, recursive policies) and the negative tests that make a policy proven rather than merely claimed. ALWAYS use this skill when: a table holding user data is created or changed; the user mentions "RLS", "policy", "row level security", "who can see what", "tenant", "team", "user sees someone else's data", "auth.uid", "unrestricted" or "security hole"; a query unexpectedly returns an empty result; data is read directly from the frontend; one user could see another user's data. Also trigger when multi-user data is only implicit — for example any table with a user_id, employee_id or team_id column.
/scroll-worldBuild an immersive scroll-scrubbed "fly through the world" landing page for any industry or brand using Higgsfield. As the visitor scrolls, a pre-rendered camera flies from outside each scene into its interior, then flows on to the next scene with NO cuts — one continuous connected flight (Emons-style isometric diorama world, or any art direction you pick). The skill interviews the user for the topic, the story beats/sections, and brand kit, then generates cohesive scenes + seamless camera clips with Higgsfield and wires a portable, framework-agnostic scroll-scrub engine. Use when the user wants a "3D world" / "browse-through-the-industry" hero, a scroll cinematic, a diorama landing, or to turn a business into a scrollable world.
/security-reviewPerforms systematic security reviews of code, specialised in TypeScript web applications. Identifies weaknesses in input validation, authentication, authorisation, injection risks, error handling, cryptography, file access, dependencies, business logic and security tests. Use this skill ALWAYS when: code is written, changed or refactored; a code review takes place; security questions come up; the user says "Security", "Sicherheit", "Review", "prüfen", "Schwachstelle", "Vulnerability", "Injection", "Auth", "Validierung" or similar; new endpoints, APIs or forms are implemented; database queries or shell commands are built; files are uploaded or processed; passwords, tokens or sessions are handled. Also trigger on implicit security relevance — e.g. when a new API endpoint or a form is created without anyone mentioning "security".