secure-coding
Skill1 starsChanged 4 months agoApache-2.0View on GitHub
Secure-by-default patterns to apply while writing or modifying application code. Use this skill whenever building or editing code that touches a security-relevant surface: HTTP routes, API endpoints, controllers, resolvers, or webhook handlers; login, signup, sessions, passwords, tokens, or JWTs; database queries, especially raw SQL or dynamic query building; anything that reads a user/tenant/resource ID from a request; file uploads, downloads, or filesystem paths; shell or subprocess execution; outbound HTTP requests to URLs that come from user input; rendering user content as HTML; encryption, hashing, or random token generation; secrets, API keys, and environment configuration; CORS, cookies, and security headers. Also use when the user asks to 'make this secure', 'harden', or 'add auth'. Provides the correct pattern to write the first time, so the vulnerability never exists.
- Reads credentials
11 other projects use a version of this.
Adopted by
Most recently taken up by
- slilbudget/knowledge-delta-skillstheir own version, first seen Sep 28, 2026
- txRandria/skillstheir own version, first seen Sep 21, 2026
- aethrox/doctrinetheir own version, first seen Sep 11, 2026
- g-cqd/skillstheir own version, first seen Sep 4, 2026
- techygarg/latticetheir own version, first seen Sep 3, 2026
- K95M65/AI_ONBOARDtheir own version, first seen Jul 18, 2026
Other versions11 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 11
- techygarg/lattice★ 197same name
- nimadorostkar/Claude-Skills-collection★ 28same name
- aethrox/doctrine★ 18same name
- MartinOlivero/saas-builder★ 4same name
- roodlicht/accans-sec-skills★ 4same name
- slilbudget/knowledge-delta-skills★ 3same name
- ffsshhttiikk/opencode-agents-skills★ 2same name
- g-cqd/skills★ 2same name
- txRandria/skills★ 2same name
- gabrielbauman/skills★ 1same name
1 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
8 rules. 0 are common, 6 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 8 edited versions we read keep these.
6
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 22
When you deviate from a safe default for a real reason, say so in one line and explain the tradeoff.
- Distinctive: line 53
Never rely on unguessable IDs as an access control.
- Distinctive: line 80
Never trust a client-supplied filename.
- Very specific: line 120
Read from the environment or a secrets manager.
- Distinctive: line 125
If you notice a secret already committed, say so immediately and state that it needs
- Distinctive: line 134
Don't log PII, credentials, tokens, or full request bodies.
- Distinctive: line 140
Every list endpoint gets a maximum page size.
- Very specific: line 147
Don't disable protections to make something work.
“Common” is measured: kept by at least 6 in 10 of the 8 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,
reject loopback, link-local (
169.254.0.0/16, especially169.254.169.254), and private ranges; allow onlyhttp/https; and re-validate after every redirect, since the first hop can be public and the second internal. - HTML — let the framework escape by default. Reach for
dangerouslySetInnerHTML,v-html,|safe, orinnerHTMLonly with a maintained sanitizer (DOMPurify, bleach) and an explicit reason. Never build a URL attribute from user input without checking the scheme —javascript:anddata:are executable. - Deserialization —
yaml.safe_load, neverpickleon untrusted data, XML parsers with 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: bcrypt, scrypt, or argon2id. Never a general-purpose hash, salted or not.
- 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), narrowDomain, sane expiry. - 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. - Compare secrets, tokens, and MACs in constant time (
timingSafeEqual,compare_digest) — 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.
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/*, or @SuppressWarnings, 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.
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.

