agentleFS
NikoxkxNikoxkx/Agent-Skills/skills/security/jwt-security-auditor/SKILL.md

jwt-security-auditor

Skill1 starsChanged 5 months agoApache-2.0View on GitHub

Audits JWT implementation for common security vulnerabilities. Use when reviewing authentication systems that use JSON Web Tokens.

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 7 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    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
  1. Distinctive:

    Check that the library is actually verifying the signature (many footguns in older or custom code).

    line 40
  2. Distinctive:

    No critical business logic decisions based solely on unverified claims.

    line 47
  3. Distinctive:

    Never localStorage or sessionStorage for access or refresh tokens (XSS risk).

    line 51
  4. Distinctive:

    Test cases (none alg, alg confusion, expired token, missing signature, etc.).

    line 64
  5. Distinctive:

    Run the audit checklist against the implementation — findings are documented with evidence.

    line 79
  6. Distinctive:

    Test vectors (none alg, expired, wrong audience, alg confusion) are run against the validation code — vulnerable paths are identified.

    line 80
  7. Distinctive:

    After remediation, the same test vectors are rejected.

    line 81

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Overview

Audits JWT implementations for common and critical vulnerabilities. Covers JWT structure review (header alg, "none" attack, RS256 vs HS256), signature validation, expiry and clock skew handling, sensitive data in payload, token storage (httpOnly cookies vs localStorage), refresh token security, algorithm confusion attacks, and a comprehensive JWT audit checklist with code-level indicators and fixes.

When to Use This Skill

  • Reviewing or implementing authentication that uses JWTs.
  • Auditing an existing auth system (especially custom JWT code).
  • The user mentions "JWT", "JSON Web Token", "access token", or is building login/refresh flows.

Prerequisites

  • The JWT implementation code (issuance, validation, refresh).
  • Example tokens (valid, expired, malformed).
  • Knowledge of how tokens are stored and transmitted on the client.

Steps

  1. Decode and inspect sample tokens (use jwt.io or jwt decode):
    • Header: alg, typ, kid.
    • Payload: claims (sub, exp, iat, aud, iss, scopes/roles, any PII?).
    • Signature present and looks valid.
  2. Algorithm & signature validation audit:
    • Never allow alg: "none".
    • For asymmetric (RS256/ES256): verify with public key, never secret.
    • For symmetric (HS256): use a strong, long, random secret; never hardcode.
    • Check that the library is actually verifying the signature (many footguns in older or custom code).
    • Algorithm confusion (HS256 with public key as secret) — test if the implementation is vulnerable.
  3. Claims validation:
    • exp is checked and enforced (with small clock skew tolerance, e.g., 30-60s).
    • aud and iss are validated against expected values.
    • iat / nbf considered where relevant.
    • No critical business logic decisions based solely on unverified claims.
  4. Token storage & transmission:
    • httpOnly + Secure + SameSite cookies (strongly preferred for web).
    • Never localStorage or sessionStorage for access or refresh tokens (XSS risk).
    • Short-lived access tokens (5-15 min) + rotating refresh tokens.
    • Refresh tokens stored securely (httpOnly cookie or secure backend session) and rotated on use.
  5. Refresh & revocation:
    • Refresh token rotation (old refresh token is invalidated when a new one is issued).
    • Refresh token reuse detection (if the same old token is presented again → revoke the whole family and force re-login).
    • Ability to revoke individual sessions or all sessions for a user (e.g., on password change or suspected compromise).
  6. Output:
    • JWT audit checklist (with pass/fail + evidence + severity).
    • Code-level red flags to search for ("alg", "verify", "localStorage.setItem", hard-coded secrets, long-lived tokens, etc.).
    • Recommended secure patterns (httpOnly cookie issuance, refresh rotation, library usage).
    • Test cases (none alg, alg confusion, expired token, missing signature, etc.).
    • Remediation steps for each finding.

Examples

A complete JWT audit report for a typical custom JWT implementation (using jsonwebtoken in Node) with several issues (long-lived tokens, localStorage, missing audience check, no refresh rotation, potential alg confusion due to custom verification) plus the exact fixes and test vectors is included.

Edge Cases & Error Handling

  • Clock skew between services: Allow small exp leeway but not too much.
  • Key rotation (kid): Support multiple public keys during rotation; never use the same key forever.
  • Token binding (advanced): Consider DPoP or mTLS-bound tokens for high-security scenarios.

Verification

  1. Run the audit checklist against the implementation — findings are documented with evidence.
  2. Test vectors (none alg, expired, wrong audience, alg confusion) are run against the validation code — vulnerable paths are identified.
  3. After remediation, the same test vectors are rejected.
  4. Token storage is verified in browser (httpOnly cookie, no tokens in localStorage).
  5. Success: The JWT implementation follows current best practices and resists the common attacks in the checklist.

References

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.