secure-coding
Skill1 starsChanged 49 days agoApache-2.0View on GitHub
Load BEFORE writing or editing any server-side code that handles a request, a user, an ID, a query, a file, a secret, or a dependency — it supplies the secure pattern to write the first time, so the vulnerability never exists. Covers: HTTP routes, routers, API endpoints, handlers, controllers, resolvers, webhooks; login, signup, sessions, passwords, tokens, JWTs; database queries, especially raw SQL or dynamic query building; anything that reads a user/tenant/ resource ID from a request (the ownership check); file uploads, downloads, and filesystem paths; shell or subprocess calls; outbound HTTP to user-supplied URLs; rendering user content as HTML; encryption, hashing, random tokens; secrets, API keys, env config; CORS, cookies, security headers; adding a dependency. Any web stack (Express, Next.js API routes, FastAPI, Django, Flask, Rails, Spring, Go net/http). Trigger on 'route', 'endpoint', 'router', 'API', 'handler', 'controller', 'GET /', 'POST /', ':id', 'req.user', 'current user', 'login', 'auth', 'query', 'SQL', 'upload', 'webhook', 'make this secure', 'harden', 'add auth'.
- Reads credentials
20 other projects use a version of this.
Adopted by
Most recently taken up by
- g-cqd/skillstheir own version, first seen Nov 27, 2026
- TheLunchTrae/claude-code-configstheir own version, first seen Nov 8, 2026
- profdorly/ultimate-dev-skillstheir own version, first seen Nov 8, 2026
- AxlZero21/Skillstheir own version, first seen Nov 8, 2026
- its-ash/skillstheir own version, first seen Nov 1, 2026
- gabrielbauman/skillstheir own version, first seen Nov 1, 2026
Other versions20 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 20
- techygarg/lattice★ 218same name
- nimadorostkar/Claude-Skills-collection★ 41same name
- HyunjunJeon/claude-workflow-mods★ 10same name
- MartinOlivero/saas-builder★ 4same name
- sergeyizmailov/knowledge-delta-skills★ 3same name
- slilbudget/knowledge-delta-skills★ 3same name
- ffsshhttiikk/opencode-agents-skills★ 2same name
- g-cqd/skills★ 2same name
- mondoohq/secure-stack★ 2same name
- txRandria/skills★ 2same name
10 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository2 other files it gives its agents.
- llm-app-securitySkill
- security-review-methodSkill
The file
We split this skill into the rules it gives an agent
9 rules. 0 are common, 7 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 15 edited versions we read keep these.
7
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 24
When you deviate from a safe default for a real reason, say so in one line and explain the tradeoff.
- Distinctive: line 55
Never rely on unguessable IDs as an access control.
- Distinctive: line 82
Never trust a client-supplied filename.
- Very specific: line 141
Read from the environment or a secrets manager.
- Distinctive: line 146
If you notice a secret already committed, say so immediately and state that it needs
- Distinctive: line 155
Don't log PII, credentials, tokens, or full request bodies.
- Distinctive: line 165
Every list endpoint gets a maximum page size.
- Very specific: line 172
Don't disable protections to make something work.
- Distinctive: line 180
Before adding a package, confirm it exists and is the one you meant — AI assistants hallucinate plausible package names, and attackers …
“Common” is measured: kept by at least 6 in 10 of the 15 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Secure Coding
The cheapest security fix is the one you never have to make. When writing code on any of the surfaces below, use these patterns by default — without being asked, and without announcing that you're doing something special. Secure code should just look like normal good code.
When you deviate from a safe default for a real reason, say so in one line and explain the tradeoff. Don't silently ship the unsafe version.
Authorization — the highest-value habit
Every query that fetches a user-owned resource must constrain by the owner in the query itself, using the identity from the session. Not fetched-then-checked, and never using an owner ID that came from the request.
# wrong — the ID is attacker-controlled, ownership is never checked
order = db.query(Order).filter(Order.id == request.params.id).one()
# right — ownership is part of the lookup; a wrong ID is simply not found
order = db.query(Order).filter(
Order.id == request.params.id,
Order.user_id == session.user_id, # from the session, never the request
).one_or_none()Rules that follow from this:
- The acting identity comes from the verified session. Never from a request body field, a header, a query parameter, or a client-supplied claim you didn't verify.
- Apply it to writes as much as reads. Update and delete paths are the ones that get missed.
- For nested resources, verify the whole chain: that the project belongs to the org and the org belongs to the user.
- In multi-tenant systems, enforce the tenant filter structurally — row-level security, a
scoped base query, a repository layer that can't be bypassed. Isolation enforced by
remembering to add a
whereclause will eventually be forgotten. Design so that forgetting fails closed. - Never rely on unguessable IDs as an access control. UUIDs are a speed bump, not a permission.
- Hiding a control in the UI is not authorization. Assume every endpoint is called directly.
Never accept a raw request body into a model. Allowlist the fields the client may write:
# wrong — client can set role, credits, tenant_id, is_verified…
user.update(**request.json)
# right
ALLOWED = {"display_name", "bio", "avatar_url"}
user.update(**{k: v for k, v in request.json.items() if k in ALLOWED})Untrusted input reaching a sink
Untrusted means: anything from a request, an upload, a webhook, a third-party API, an LLM, or a database row another user wrote.
- SQL — always parameterize. Identifiers (table, column,
ORDER BY) cannot be parameterized, so map them through an allowlist dictionary. Never build a query by concatenation or interpolation, even "just for a column name". - Shell — avoid the shell entirely. Use the argument-array form (
spawn(cmd, [args]),subprocess.run([...])withoutshell=True). Even then, prefix user-controlled filenames with./or pass--so a leading-can't become a flag. Best of all: use a library instead of shelling out. - Paths — join, resolve, then verify containment against the resolved base directory.
Never trust a client-supplied filename; generate the stored name server-side.
full = os.path.realpath(os.path.join(BASE, user_input)) if not full.startswith(os.path.realpath(BASE) + os.sep): raise Forbidden() - Outbound URLs (SSRF) — allowlist the destination host if you possibly can. If you can't,
allow only
http/httpsand reject loopback (127.0.0.0/8,::1), unspecified (0.0.0.0,::), link-local (169.254.0.0/16— especially169.254.169.254— andfe80::/10), private (10/8,172.16/12,192.168/16,fc00::/7), CGNAT100.64.0.0/10, and IPv4-mapped IPv6 (::ffff:0:0/96). Resolve DNS once, validate every resolved IP, then connect to that pinned IP — checking the hostname and letting the HTTP client resolve again is defeated by DNS rebinding. Disable automatic redirects; if you must follow them, re-run the full check per hop. Better still, route egress through a proxy that enforces this (e.g. smokescreen). - HTML — let the framework escape by default. Reach for
dangerouslySetInnerHTML,v-html,|safe, orinnerHTMLonly with a maintained sanitizer (DOMPurify, nh3) and an explicit reason. Never build a URL attribute from user input without checking the scheme —javascript:anddata:are executable. - Deserialization —
yaml.safe_load; neverpickle, JavaObjectInputStream, .NETBinaryFormatter, PHPunserialize, or RubyMarshalon untrusted data; XML parsers with DTDs and external entities disabled. - Templates — pass user data as context, never concatenate it into the template string.
Validate at the boundary with a schema (zod, pydantic, valibot, struct tags) so the rest of the code works with typed, known-shaped data. Allowlist what's permitted rather than denylisting what isn't.
Authentication and sessions
- Passwords: argon2id (minimum m=19 MiB, t=2, p=1), scrypt (N=2^17, r=8, p=1), bcrypt (cost ≥10), or PBKDF2-HMAC-SHA256 (≥600,000 iterations, where FIPS is required) — the OWASP Password Storage minimums. A framework's built-in default hasher is fine. Never a general-purpose hash, salted or not. bcrypt silently uses only the first 72 bytes: reject longer passwords or use argon2id, and never pre-hash into a raw binary digest (a NUL byte truncates it). Verify with the library's own (constant-time) verify function.
- Tokens, session IDs, reset codes, OTPs, salts, IVs: a CSPRNG only —
crypto.randomBytes,secrets.token_urlsafe,crypto/rand. NeverMath.random(),random, or a timestamp. - Cookies:
HttpOnly,Secure,SameSite=Lax(orStrict) set explicitly, narrowDomain, sane expiry. Prefer the__Host-prefix for session cookies. - CSRF: cookie-authenticated state-changing requests need a CSRF token (or a verified
Origin/Sec-Fetch-Sitecheck) in addition to SameSite — browser default-Lax is Chromium-only, SameSite does nothing against a sibling subdomain, and it allows top-level GET. Never change state on GET. - Regenerate the session on login and on any privilege change. Invalidate server-side on logout.
- JWTs: verify the signature, pin the algorithm, and check
exp,iss, andaud. Neverdecodewithout verification. Keep them short-lived, since you usually can't revoke them. Ignorejku/x5u/embeddedjwkheaders, and never letkidselect a file path or SQL row unvalidated. - Compare secrets, tokens, and MACs in constant time — Node
crypto.timingSafeEqualon equal-length Buffers (e.g. compare HMAC digests of both values, since it throws on a length mismatch), Pythonhmac.compare_digest, Gosubtle.ConstantTimeCompare— never with==or a prefix/startswithcheck. - Password reset tokens: random, hashed at rest, single-use, short expiry, and the link's host
from config — never from the
Hostheader. - Rate-limit login, signup, reset, and OTP by account and by IP. Return identical responses for existing and non-existing accounts.
Secrets
Read from the environment or a secrets manager. Never a literal in source, a committed .env,
a Dockerfile ENV, or a test fixture. Never log a token, a header, a password, or a full
request body that might contain one. Remember that NEXT_PUBLIC_*, VITE_*, and REACT_APP_*
ship to the browser and are public by definition.
If you notice a secret already committed, say so immediately and state that it needs rotating, not just deleting.
Output, errors, and logging
- Return an explicit field allowlist, not the whole database object. It's easy to leak
password_hashor another user's email through an eagerly-loaded relation. - Errors to the client: generic. Errors to the log: detailed. Never send a stack trace, a SQL statement, or an internal path to a user.
- Don't log PII, credentials, tokens, or full request bodies. Do log auth failures, authz denials, and admin actions with actor, action, target, and time — you'll need them during an incident.
- Fail closed. An exception inside an auth/authz check, a policy-engine timeout, a
signature-verification error, or a missing config value must deny — never fall through to
next(),return True, or a default role. No emptycatcharound a security check; noexcept Exception: pass.
Limits, by default
Every list endpoint gets a maximum page size. Every upload gets a size and type cap. Every request body gets a size limit. Every loop over client-supplied data gets a length cap. Every expensive or metered operation gets a rate limit. Unbounded anything is an availability and cost problem waiting for someone to notice.
Framework defaults to keep
Don't disable protections to make something work. If you find yourself writing
rejectUnauthorized: false, verify=False, InsecureSkipVerify: true, csrf_exempt,
# nosec, eslint-disable security/*, @SuppressFBWarnings, or // NOSONAR, stop — that is almost always
the wrong fix. If it's genuinely necessary, isolate it to the narrowest possible scope and
leave a comment explaining why it's safe there.
Adding dependencies
Before adding a package, confirm it exists and is the one you meant — AI assistants hallucinate
plausible package names, and attackers register them (slopsquatting). Prefer well-maintained
packages, commit the lockfile, pin exact versions, install with npm ci --ignore-scripts (or
the ecosystem equivalent) where feasible, and pin CI actions and base images by commit SHA or
digest.
When you're unsure
Say so. "This needs an ownership check but I can't see how sessions work in this codebase — where does the current user come from?" is far more useful than a confident guess that ships a vulnerability.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

