skills/opaque-token-based-authentication-pattern/SKILL.md
Security pattern for server-side token authentication (e.g., session IDs). Use when implementing session management, designing stateful authentication where server maintains token-to-principal mapping, or building systems requiring immediate token revocation. Specialization of Authentication pattern.
npx skillsauth add igbuend/grimbard opaque-token-based-authentication-patternInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
A subject is authenticated based on a unique, opaque token provided with action requests. The system maintains a mapping of valid tokens to principals. Token secrecy is crucial as it's the sole proof of identity.
| Role | Type | Responsibility | |------|------|----------------| | Subject | Entity | Provides token with action requests | | Enforcer | Enforcement Point | Ensures token verification before processing | | Verifier | Decision Point | Validates token and retrieves principal | | Principal Provider | Entity | Maintains token-to-principal mapping | | Registrar | Entity | Issues tokens after initial authentication | | Token Generator | Cryptographic Primitive | Generates secure random tokens |
Opaque tokens:
java.security.SecureRandomsecrets modulecrypto.randomBytes()RNGCryptoServiceProviderSubject → [action + token] → Enforcer
Enforcer → [token] → Verifier
Verifier → [get_principal(token)] → Principal Provider
Principal Provider → [principal or error] → Verifier
Verifier → [principal or error] → Enforcer
Enforcer → [action + principal] → System (if valid)
Important: Check for duplicate tokens before issuing; regenerate if collision detected.
Web session identifiers follow this pattern:
| Aspect | Opaque Token | Verifiable Token | |--------|--------------|------------------| | Principal storage | Server-side | In token | | Revocation | Immediate | Requires strategy | | Scalability | Requires shared storage | Stateless | | Token size | Small | Larger |
development
Security anti-pattern for Cross-Site Scripting vulnerabilities (CWE-79). Use when generating or reviewing code that renders HTML, handles user input in web pages, uses innerHTML/document.write, or builds dynamic web content. Covers Reflected, Stored, and DOM-based XSS. AI code has 86% XSS failure rate.
development
Security anti-pattern for XPath injection vulnerabilities (CWE-643). Use when generating or reviewing code that queries XML documents, constructs XPath expressions, or handles user input in XML operations. Detects unescaped quotes and special characters in XPath queries.
development
Security anti-pattern for weak password hashing (CWE-327, CWE-759). Use when generating or reviewing code that stores or verifies user passwords. Detects use of MD5, SHA1, SHA256 without salt, or missing password hashing entirely. Recommends bcrypt, Argon2, or scrypt.
development
Security anti-pattern for weak encryption (CWE-326, CWE-327). Use when generating or reviewing code that encrypts data, handles encryption keys, or uses cryptographic modes. Detects DES, ECB mode, static IVs, and custom crypto implementations.