/poka-yoke:authzfrom Poka-Yoke
Prevents cross-tenant data leaks by making unscoped queries impossible. Covers scoped repositories, RLS, default-deny routing, and two-tenant testing. Use when building multi-tenant isolation or auditing for IDOR.
Ships in Poka-Yoke. 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.
None: SKILL.md is the whole skill.
Cross-tenant data leaks are almost never caused by a wrong access-control decision. They are
caused by no decision at all: a query that is correct except it lacks WHERE tenant_id = ?,
an endpoint that loads by ID without checking who is asking. The developer did not choose
wrongly; they forgot, in one of the two hundred places the check was required.
That is the signature of a poka-yoke problem: a step that must be performed every single time, by a human, with nothing enforcing it. The fix is never "be more careful in code review," and it is never a checklist. The fix is to make the unscoped query unwritable.
Most of the time this mode is reached while someone is building the thing, not afterwards. That changes the deliverable. They asked for the scoping, so produce the scoping, working, complete, in their stack. Do not hand back a severity table when the person is mid-feature; a list of findings about code they have not written yet is not useful to them.
Then add a short closing note, three or four lines, covering:
That closing note is what stops the device being undone in six months by someone who cannot see why it is there. It is also the difference between mistake-proofing and a code generator: the reasoning travels with the code.
When the code already exists and they are asking what is wrong with it, switch to the audit voice, ranked findings with the mistake, the consequence, and the device. Match the mode to where they are in the work, not to this file's default.
Right now, in most codebases, the unsafe form is the short form:
user = db.query(User).filter(User.id == user_id).first() # unscoped: 1 line
user = db.query(User).filter(User.id == user_id,
User.tenant_id == current_tenant).first() # safe: longer
Every incentive points at the first line, and it works perfectly in every test, because tests usually have one tenant. Invert it so the safe form is the default and the unsafe form requires deliberate, visible effort:
user = tenant_db.users.get(user_id) # tenant scope baked in; cannot be omitted
user = db.unscoped().users.get(user_id) # possible, greppable, reviewable, rare
Everything below is a variation on that inversion. When you audit, the question is not "is this query scoped?" but "could an unscoped query even be written here?"
RLS enforces the predicate in the database, so it applies to every query from every service,
every migration, every script, and every engineer with a psql shell. It is the only device
that protects you from code paths you did not write. Its reach stops only at roles that are
exempt from policies: superusers, roles with BYPASSRLS, and the table owner unless you force
the policy on.
ALTER TABLE documents ENABLE ROW LEVEL SECURITY;
ALTER TABLE documents FORCE ROW LEVEL SECURITY; -- applies to the table owner too
CREATE POLICY tenant_isolation ON documents
USING (tenant_id = current_setting('app.tenant_id')::uuid);
The catch that turns this into a false sense of security: the connection must set
app.tenant_id reliably, and a pooled connection that carries a previous request's setting is
a cross-tenant leak with extra steps. Set it per-transaction, and make the middleware that sets
it the only path to a connection. FORCE ROW LEVEL SECURITY matters too, without it the
table owner bypasses the policy, and your application user is often the owner.
Make the tenant a required constructor argument, so no repository exists without one:
class DocumentRepo {
// No default. There is no way to construct this without a tenant.
constructor(private readonly db: Db, private readonly tenant: TenantId) {}
async byId(id: DocumentId): Promise<Document | null> {
return this.db.documents.findFirst({ where: { id, tenantId: this.tenant } });
}
}
The raw client is then confined to infrastructure code and lint-banned from handlers. The
device is not the where clause. It is that the handler has no way to reach a client that
lacks one.
Rather than loading an object and then checking it, make the check the only way to obtain it:
// Handlers accept Owned<Document>. There is no path to one that skips the check.
async function authorizeDocument(user: User, id: DocumentId): Promise<Owned<Document>>
A handler that takes Owned<Document> cannot receive an unauthorized document, so the check
cannot be forgotten: the compiler asks for it. This is the same move as parse-don't-validate,
applied to permission instead of shape.
Require every route to declare its authorization explicitly, and refuse to start if any route has not:
UUIDs and ULIDs instead of sequential integers raise the cost of enumeration, and they are worth using. But an ID is not a permission, anyone who has ever seen the resource still has the ID forever. Never treat unguessability as the control; it is a mitigation layered behind one.
The high-yield sequence, in order:
tenant_id in a request body is client-controlled.UPDATE ... WHERE id = ? lets one tenant modify another's data.document.comments where the comment scope is assumed rather than enforced).
Nested resolvers are a common blind spot because the parent was checked and the child
inherits nothing.tenant_id = None, and
what does that match? In SQL, tenant_id = NULL matches nothing; the dangerous failure is
a query builder that drops a missing predicate and issues the query unscoped.One test pattern is worth more than any number of unit tests here: create two tenants, then attempt every operation from tenant A against tenant B's resources, and assert 404 for all of them. Table-drive it over your route list so a new endpoint without a case is visible.
Two details matter. Assert 404, not 403: a 403 confirms the resource exists, which leaks membership. And make the test enumerate routes automatically where you can, so adding an endpoint without isolation coverage fails rather than passes silently.
This is a Detection-rung device, and it is the one that tells you whether your Control-rung devices actually work. Write it even when RLS is in place, especially then, since RLS failures are silent and total.
Use the finding structure from audit. Blast radius for this class is
near-maximum, cross-tenant exposure is a breach, with disclosure obligations, so findings
here outrank almost everything else in an audit. Propose before changing anything, and be
precise about which device reaches Control: adding a where clause to one query fixes one
site, and the whole point is that there are two hundred.
What SKILL.md sets; muted values are Claude Code's defaults
11 skills in this plugin
/agent-guardrailsStop an AI agent damaging your repo: PreToolUse hooks, permission deny rules, protected paths, verification gates. Use when "claude keeps force pushing", "CLAUDE.md says X but it still does Y", "stop the agent touching prod or .env", or making a repo safe for unattended agent work. For AI features you ship to users use llm./auditFind footguns in code that already exists: swappable arguments, silent fallbacks, unguarded deletes, signatures that are easy to misuse. Use when someone asks "what could bite us here", "what is easy to misuse", "poka-yoke this repo", or wants a diff or PR reviewed for ways to get it wrong. Ranks by blast radius. For code not yet written use design; for something that already broke use retro./dataPipelines, warehouses, dbt models and metrics, where failure is silently wrong numbers rather than a crash. Use when "the dashboard is wrong", "the numbers do not match", "add data quality checks", "safe backfill", or an upstream schema change broke a join. Covers freshness, row-count and null-rate assertions, data contracts, reconciliation. For a crash rather than wrong numbers use audit./designDesign APIs, schemas, types and state machines so misuse cannot be expressed. Use when writing a new interface and someone asks "what should the types look like", "make invalid states unrepresentable", "so callers cannot screw it up", or wants illegal state transitions rejected. Covers branded types, discriminated unions, typestate, parse-don't-validate. For code that already exists use audit./guardrailsPre-commit hooks, CI gates, lint rules, database constraints and branch protection. Use when a rule needs enforcing rather than documenting: "set up enforcement", "unformatted or untyped code must not get merged", "gate this in CI", "we agreed to X and people still do not", "stop secrets getting committed". Covers baselining and ratcheting so existing violations do not block anyone. For constraining an AI agent use agent-guardrails./llmAI features you ship to users: structured output, tool schemas, prompt injection, evals. Use when "the model returns bad JSON", "it hallucinates", "stop it calling the wrong tool", "add evals", or an LLM feature can trigger refunds, emails or writes. Covers schema-constrained output, idempotent tool calls, confirmation gates. For agents editing your repo use agent-guardrails.npx claudepluginhub rainmanjam/poka-yoke --plugin poka-yokeOther plugins' skills for the same job