verifiable-token-based-authentication-pattern
Security pattern for self-contained token authentication (e.g., JWT). Use when implementing stateless authentication, designing tokens with embedded claims, or building systems where tokens contain principal information and can be verified without server-side storage. Specialization of Authentication pattern.
What this skill does
# Verifiable Token-Based Authentication Security Pattern A subject is authenticated using a token that itself contains the necessary information to determine the principal. The system verifies the token is valid (not tampered, not expired) without needing to look up stored evidence. ## Core Components | Role | Type | Responsibility | |------|------|----------------| | **Subject** | Entity | Provides token with action requests | | **Enforcer** | Enforcement Point | Ensures token verification before processing | | **Verifier** | Decision Point | Manages token validity verification | | **Cryptographer** | Cryptographic Primitive | Verifies token integrity | | **Key Manager** | Entity | Manages cryptographic keys | | **Registrar** | Entity | Issues tokens after initial authentication | ### Data Elements - **token**: Self-contained credential with principal and metadata - **principal**: Identity extracted from valid token - **expiration**: Token validity period - **signature/MAC**: Cryptographic integrity protection ## Token Structure A verifiable token must contain: 1. **Principal identifier** (username, user ID, email) 2. **Expiration date/time** 3. **Cryptographic signature or MAC** 4. **Optional**: Additional claims (roles, permissions, metadata) ## Token Integrity Verification Two approaches: ### Digital Signature (Asymmetric) - Token signed with private key - Verified with public key - Enables verification without sharing signing key - Use RSA (min 2048 bits) or ECDSA (min 256 bits) ### MAC (Symmetric) - Token authenticated with shared secret - Same key for creation and verification - Use HMAC with min 128-bit keys **Recommendation**: Use cryptographic keys with at least 128 bits of entropy. ## Verification Flow ``` Subject → [action + token] → Enforcer Enforcer → [token] → Verifier Verifier → [get key] → Key Manager Key Manager → [key] → Verifier Verifier → [verify integrity] → Cryptographer Cryptographer → [result] → Verifier Verifier → [check expiration, extract principal] → Verifier Verifier → [principal or error] → Enforcer ``` Verification steps: 1. Verify integrity (signature/MAC) 2. Check expiration date 3. Check revocation status (if implemented) 4. Extract and return principal ## Token Registration (Issuance) 1. Subject authenticates via other means (e.g., password) 2. Registrar generates token with: - Principal identifier - Expiration date - Additional claims - Cryptographic signature/MAC 3. Token returned to Subject ## Security Considerations ### Token Lifetime - Shorter = more secure, less convenient - Include absolute expiration - Consider refresh token pattern for long sessions ### Token Revocation - Stateless tokens cannot be directly revoked - Options: short lifetimes, revocation lists, token versioning ### Token Storage (Client-Side) - Web: HttpOnly, Secure cookies or secure storage - Mobile: Secure enclave/keychain - Never store in localStorage for sensitive apps ### Token Transmission - Always use HTTPS - Consider token binding ### No Token Reset - Tokens should never be reset on request - Subject must re-authenticate for new token ### Integrity is Paramount - Never accept tampered tokens - Verify signature before trusting any claims ## Common Implementation: JWT JSON Web Tokens follow this pattern: - Header: algorithm, type - Payload: claims (principal, exp, iat, etc.) - Signature: cryptographic verification **Warning**: Always verify signature; never use "none" algorithm. ## Implementation Checklist - [ ] Strong signing algorithm (RS256, ES256, HS256) - [ ] Expiration claim enforced - [ ] Signature verified before trusting claims - [ ] Keys managed securely - [ ] Transmission over HTTPS only - [ ] Appropriate token lifetime - [ ] Revocation strategy defined ## References - Source: https://securitypatterns.distrinet-research.be/patterns/01_01_003__verifiable_token_based_authentication/ - RFC 7519 (JWT) - OWASP JWT Cheat Sheet
Related in Security
mac-ops
IncludedComprehensive macOS workstation operations — diagnose kernel panics, identify failing drives, audit launchd startup items, decode wake reasons, triage TCC permission denials, manage APFS snapshots, recover from no-boot. Use for: Mac is slow, slow bootup, won't boot, kernel panic, kernel_task hot, mds_stores CPU, photoanalysisd, cloudd, login loop, gray screen, sleep wake failure, drive failing, IO errors, APFS snapshots eating space, Time Machine local snapshots, Spotlight indexing, launchd, LaunchAgent, LaunchDaemon, login items, TCC permissions, Full Disk Access, Screen Recording denied, Gatekeeper, quarantine, com.apple.quarantine, app is damaged, helper tool, /Library/PrivilegedHelperTools, pmset, wake reasons, dark wake, sysdiagnose, panic.ips, DiagnosticReports, configuration profile, MDM profile, remote diagnostics over SSH.
a11y-audit
IncludedRun accessibility audits on web projects combining automated scanning (axe-core, Lighthouse) with WCAG 2.1 AA compliance mapping, manual check guidance, and structured reporting. Output is configurable: markdown report only, markdown plus machine-readable JSON, or markdown plus issue tracker integration. Use this skill whenever the user mentions "accessibility audit", "a11y audit", "WCAG audit", "accessibility check", "compliance scan", or asks to check a web project for accessibility issues. Also trigger when the user wants to verify WCAG conformance or map findings to a specific standard (CAN-ASC-6.2, EN 301 549, ADA/AODA).
erpclaw
IncludedAI-native ERP system with self-extending OS. Full accounting, invoicing, inventory, purchasing, tax, billing, HR, payroll, advanced accounting (ASC 606/842, intercompany, consolidation), and financial reporting. 413 actions across 14 domains, 43 expansion modules. Constitutional guardrails, adversarial audit, schema migration. Double-entry GL, immutable audit trail, US GAAP.
assess
IncludedAssesses and rates quality 0-10 across multiple dimensions (correctness, maintainability, security, performance, testability, simplicity) with pros/cons analysis. Compares against project conventions and prior decisions from memory. Produces structured evaluation reports with actionable improvement suggestions. Use when evaluating code, designs, architectures, or comparing alternative approaches.
spring-boot-security-jwt
IncludedProvides JWT authentication and authorization patterns for Spring Boot 3.5.x covering token generation with JJWT, Bearer/cookie authentication, database/OAuth2 integration, and RBAC/permission-based access control using Spring Security 6.x. Use when implementing authentication or authorization in Spring Boot applications.
code-hardcode-audit
IncludedDetect hardcoded values, magic numbers, and leaked secrets. TRIGGERS - hardcode audit, magic numbers, PLR2004, secret scanning.