Skip to content
Back to skills

Guard 20

ASecurity

The write-time companion to audit-20: the same twenty failure classes, applied as rules WHILE writing code instead of hunted afterwards. Load before touching code on any coding task (feature, fix, refactor, generated code). Not an audit; spawns no agents and no fleet, costs no extra tokens; its job is to make the final audit-20 run come back mostly CLEAN. Trigger: writing code, implement, fix, refactor, "guard-20", "coding rules".

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 24, 2026
ai-agentsrustgodockerapisecurity

Works with

  • vscode
  • cli
  • api

Security analysis

A100/100

Scanned October 24, 2026

npx -y skills add kasparovabi/claude-audit-20 --skill guard-20 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Guard 20?

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

Security grade badge for Guard 20
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/kasparovabi-guard-20/badge)](https://www.skillsdirectory.com/skills/kasparovabi-guard-20)

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

Download with Pro
SKILL.md
---
name: guard-20
description: The write-time companion to audit-20: the same twenty failure classes, applied as rules WHILE writing code instead of hunted afterwards. Load before touching code on any coding task (feature, fix, refactor, generated code). Not an audit; spawns no agents and no fleet, costs no extra tokens; its job is to make the final audit-20 run come back mostly CLEAN. Trigger: writing code, implement, fix, refactor, "guard-20", "coding rules".
---

# guard-20: don't find the bug, never write it

audit-20 hunts defects in finished code; that is expensive. guard-20 turns the same
twenty defect classes into writing discipline: rule numbers map one-to-one to the audit
passes, so when the final audit runs, it passes clean.

This skill launches no agents, workflows, or scans. It is a set of rules you follow
while writing, plus a two-minute self-check at the end.

## Before writing (30 seconds)

Answer five questions; the answers tell you which rules are hot for this task:

1. Where does external data enter, and is it processed before auth? (params, headers,
   body, files, queues, third-party responses, LLM/tool output) → G1, G4
2. Which stores / external services does this touch? → G8, G11, G12, G13
3. Any multi-step writes or shared state? → G5, G6, G7, G10
4. Who calls this code, and what do they see on failure? → G3, G16, G17, G18
5. Does it touch dependencies/lockfiles, a Dockerfile, CI workflows, DB migrations,
   server config, or agent/IDE config? → G3, G14, G15

## The 20 rules (while writing)

**Security (G1-G4)**
- G1 Validate or context-encode external input before it reaches a sink (query,
  exec/argv, file path, HTML, redirect, regex compilation, deserializer, URL opener).
  Validate in the representation the sink consumes: require an exact string type on
  token/code/key fields (truthiness and `!empty` only check presence); parse a value
  once so the check and the use see the same object. Use allowlists at trust
  boundaries; a denylist is a finding. Never compile a regex from input; a filename
  passed to an external binary must not start with `-` or `@`. Headers are input too:
  the first element of x-forwarded-for, Host, user-agent, and referer are text the
  client wrote; never key a trust decision on them. Data read back from a store is
  input too: no native deserialization.
- G2 If it's auth code: token generation needs entropy + expiry + rotation; logout must
  actually revoke, and you verify the effect (rows deleted > 0); carry cookies with their
  attributes (Secure/SameSite/Max-Age), never reduce them to name+value. One purpose per
  key (separate keys or an HKDF label), no `KEY = A || B` fallbacks; a successful
  decrypt is not proof of identity, verify the typ/purpose claim. Validate exp/iat with
  a library that type-checks them. Bind identity to immutable IDs (issuer+sub,
  repository_id); email and slugs are never authorization keys.
- G3 Every operation touching a resource checks ownership/role server-side, BEFORE the
  action, on every path (bulk/export/admin included). Never use a client-supplied ID
  unchecked. Server Actions and test/preview/lint/debug endpoints need the authorization
  of the action they simulate. A viewer-dependent response never enters a shared cache
  without the principal in the key (default `private, no-store`). A migration that
  creates a table carries its row-level security, per-operation policies, and per-table
  grants in the same file; no `USING (true)` and no `ON ALL TABLES` grants.
- G4 Secrets and PII never enter code, logs, test fixtures, or example env files. No
  secrets in client-visible names (NEXT_PUBLIC_* and friends). Error responses must not
  leak stacks, queries, or internal paths. Don't log LLM/agent/tool bodies; if you must,
  redact before writing (gho_, ghp_, sk-, sk-ant-, AKIA, JWT, PEM). A secret committed to
  history has leaked even after deletion: rotate it.

**Failure and concurrency (G5-G7)**
- G5 Empty catch blocks are forbidden. If step N fails, name the state steps 1..N-1
  left behind: roll back, compensate, or degrade deliberately + log. Don't swallow the
  framework's control-flow errors (e.g. Next's dynamic bail-out); rethrow them. Build an
  object fully in local scope and publish it to shared structures last, in one step;
  cleanup deletes only what it created. Security checks fail closed: an async error,
  rejection, or timeout is never an allow. In a parser, invalid input is not "need more
  data".
- G6 Don't write check-then-act; pick the atomic equivalent (unique constraint, upsert,
  CAS). No fire-and-forget on calls with side effects. Freeze UI inputs while a long
  async job runs. In long-lived workers, request data never lives in module/global/
  singleton state; carry it in request context. If you must, clear it on every exit path
  (errors included) and make sure no hook that runs before per-request init reads it.
- G7 Release every resource you acquire (connection, handle, timer, listener, lock) via
  finally/defer/cleanup; if you write an effect, write its cleanup in the same moment.
  Register the cleanup right after the acquisition. Give every stream/emitter an
  'error' listener and use `pipeline` instead of `.pipe()`; check limits before creating
  the resource.

**Data and scale (G8-G10)**
- G8 No queries inside loops; batch. No unbounded query against a table that grows.
  Filtering and sorting are the store's job, not application memory's.
- G9 No unbounded nested loops on hot paths; hoist loop invariants. On collections an
  attacker sizes (form fields, header tokens, JSON arrays), no linear lookup inside a
  loop: build a Map once; a byte limit does not bound CPU, so cap count and depth.
  Equally: don't optimize paths that will never see scale.
- G10 If you write a module-scope collection or cache that grows, write its
  TTL/eviction/cap in the SAME change; "I'll add it later" is an audit finding. When
  expanding external input (decompression, multipart, charset/codec, archives, images),
  apply limits to the decoded output, while streaming and cumulatively (empty elements
  and depth included); a client-chosen codec comes from an allowlist.

**External dependencies (G11-G13)**
- G11 Every out-of-process call gets an explicit timeout. Retries, if needed: bounded,
  with backoff, only on idempotent operations. Choose deliberately what the user sees
  when the dependency is down. For calls whose destination comes from outside: host
  allowlist, resolve DNS once and connect to that IP, re-validate every redirect, and
  never attach the server's credentials.
- G12 Write every state-changing operation as if it will be delivered twice: if it is
  not naturally idempotent, add an idempotency key or constraint.
- G13 Don't write an operation that updates more than one thing (two tables, DB+cache,
  DB+event) without a transaction/saga/outbox. Never update the cache before the commit.

**Environment and supply chain (G14-G15)**
- G14 No dangerous defaults (debug on, permissive CORS, TLS verification off). Missing
  required config never runs silently wrong: fail fast, or degrade deliberately with a
  warning log. Turn off default-on features you don't use; heavy parsing (multipart,
  decompression, deserialization) comes after auth. Dev servers and admin routes need a
  token plus an Origin/Host check. Never silence an error by loosening security (a bulk
  GRANT to fix a 42501, verify=false, CORS `*`).
- G15 A new dependency is the last resort (the ladder: stdlib > platform > existing
  dep). If you add one, check its advisories; pin exact versions on security-critical
  paths (auth/crypto/untrusted-input parsing) and check the version the lockfile
  actually resolves. Install-time surface: scripts, `binding.gyp` `<!(`, `.pth`/
  `sitecustomize`, release age. Pin actions by SHA and base images by digest; workflows
  get narrow `permissions:`, the checkout ref never comes from an input, and no
  `pull_request_target` checks out PR code. Workflows, `.claude/`, `.vscode/tasks.json`,
  `AGENTS.md`, and `CLAUDE.md` are executable code: touch them only when the task asks,
  as a separate change.

**Observability and contracts (G16-G18)**
- G16 Leave no silent failure points: every error branch gets ONE log line with context
  (correlation/IDs yes, PII/secrets no). Security events (login failures, permission
  denials, secret reads/decrypts, bulk exports, token creation) leave a trail with actor
  and IP.
- G17 When touching an API surface, copy the existing contract: same error shape, same
  status codes, same naming. Never create a second shape for the same concept.
- G18 At module boundaries, assign each responsibility to ONE side and make it visible
  (who validates, who retries, who owns the transaction). If both sides do it, delete
  one; if neither does, close the gap. The same check (expiry, type, authorization,
  limit) goes through one shared function on every entry path (REST/WS, sync/async,
  sibling APIs).

**Tests and closing (G19-G20)**
- G19 If you wrote a branch/parser/money/security path, write the smallest failing test
  in the same session; at least one non-happy-path assert. No tests for trivial
  one-liners (YAGNI applies to tests too). In a security fix, the original PoC becomes a
  regression test and you search sibling APIs for the same pattern. Send `[0]`, `0`,
  `true`, `null`, `{}` as a credential: the DB lookup must never be called.
- G20 Before finishing, self-scan (≤2 min, no tools): look at your diff, pick the rules
  it touches, and give each a one-line "applied/clean". The report is a single line:
  `guard-20: [G1,G5,G11] applied; rest N-A`.

## Relationship to lazy-coding styles

A minimalism skill says shorten; guard-20 says what may never be shortened away:
validation at trust boundaries, failure paths, timeouts, resource release, idempotency.
On conflict, guard-20 wins; these are the classic "never simplify away" items.

## Relationship to audit-20

guard-20 does not replace the audit; run audit-20 ONCE at the final milestone (when the
user declares the project final, or asks for it). Code written to these rules makes most
passes come back CLEAN, so the audit closes cheap. Between iterations, don't run the
fleet: typecheck + tests + build + smoke are enough.

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.

View all in ai-agents →

Comments

Loading comments…

Newsletter

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