adding-authentication
Skill0 starsChanged 4 months agoMITView on GitHub
Adds token-based authentication to an app, with 5 real attack scenarios (tampering, expiry, wrong secret, algorithm confusion) tested against actual JWT code to confirm what's actually safe. Use whenever the user wants to add login, signup, or authentication to an app, or mentions JWTs, sessions, Auth0, or protected routes.
In this repository19 other files it gives its agents.
- auditing-seoSkill
- automating-git-workflowsSkill
- building-email-sequencesSkill
- building-graphql-apisSkill
- building-wordpress-pluginsSkill
- designing-carouselsSkill
- fine-tuning-ml-modelsSkill
- handling-web-formsSkill
- n8n-automationSkill
- organizing-spreadsheetsSkill
- reviewing-cloudflare-workers-codeSkill
- reviewing-code-for-securitySkill
- scaffolding-landing-pagesSkill
- setting-up-error-monitoringSkill
- setting-up-firebase-authSkill
- using-nextjs-best-practicesSkill
- working-with-postgres-databasesSkill
- writing-marketing-copySkill
- writing-terraform-codeSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Never store tokens in localStorage for anything sensitive: - prefer httpOnly cookies where the framework supports it, to reduce XSS …
- Distinctive: line 40
If multi-factor auth or social login is needed, confirm which providers before scaffolding - each addition usually needs separate …
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Adding authentication
Adds token-based authentication, verified against 5 real attack scenarios run against actual signing/verification code - not just "JWTs are secure if implemented correctly" as an unverified claim.
Workflow
- Detect the framework first - the SDK and setup pattern differ across Next.js, React SPA, Express API, or mobile.
- Decide session model: server-side session vs client-held JWT - state the trade-off (revocation ease vs statelessness) rather than picking silently.
- Never store tokens in localStorage for anything sensitive - prefer httpOnly cookies where the framework supports it, to reduce XSS exposure.
- Pin the algorithm explicitly when verifying - see the tested attack below, this is the one mistake that turns a correct-looking JWT setup into a real vulnerability.
- Test the logout/expiry path explicitly - session invalidation is frequently untested.
Tested: 5 real attacks against a working JWT implementation
Ran with the real jsonwebtoken npm package, not simulated:
| # | Attack | Result |
| 1 | Valid token, normal verification | PASS - verified correctly, payload intact |
| 2 | Payload tampered after signing (role changed to admin, signature not redone) | PASS - rejected: invalid signature |
| 3 | Expired token (expiresIn: '-1s') | PASS - rejected: jwt expired |
| 4 | Token forged with the wrong secret | PASS - rejected: invalid signature |
| 5 | "alg": "none" token (classic JWT library vulnerability) | PASS - rejected: jwt signature is required |
All 5 held using the library's default verification settings. The important caveat from test 5: this only holds because the code never explicitly allows algorithms: ['none'] or omits algorithm pinning in a custom verifier. Some JWT libraries (and hand-rolled verifiers) historically accepted alg: none if the caller didn't restrict allowed algorithms - always verify with an explicit algorithms: ['HS256'] (or whichever is actually used) rather than trusting library defaults blindly, since defaults have changed across versions and libraries.
// Explicit is safer than implicit, even though the default passed the test above:
jwt.verify(token, SECRET, { algorithms: ['HS256'] });Notes
- Test 2 (tampering) is the one people most often assume "obviously works" without checking - it does, but only because the signature covers the full payload. If a custom implementation ever splits signing from the full payload (e.g. signs a hash but ships extra unsigned fields the app trusts), this protection silently breaks.
- If multi-factor auth or social login is needed, confirm which providers before scaffolding - each addition usually needs separate configuration in the auth provider's dashboard.
- Server-side verification is non-negotiable for anything with real access control - never trust a client-supplied claim (including a decoded-but-unverified JWT payload) without running it through
verify().
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.

