skills/authentication-pattern/SKILL.md
Security pattern for implementing authentication in software systems. Use when designing or reviewing authentication mechanisms, implementing login systems, verifying user identity, protecting system access, or addressing OWASP authentication flaws. Provides guidance on enforcers, verifiers, evidence providers, subject registration, credential management, and security considerations.
npx skillsauth add igbuend/grimbard 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.
Authentication verifies that a subject (user, service, device) is who they claim to be before allowing system access. This pattern is a prerequisite for authorization and auditing.
Use this pattern when:
| Role | Type | Responsibility | |------|------|----------------| | Subject | Entity | Requests actions from the system | | Enforcer | Enforcement Point | Intercepts requests; ensures authentication before processing. Must be incorporated into the system | | Verifier | Decision Point | Validates credentials against evidence to determine authentication success | | Evidence Provider | Entity | Stores/provides evidence for credential verification (internal or external) |
Subject → [action + credential] → Enforcer
Enforcer → [credential] → Verifier
Verifier → [request evidence] → Evidence Provider
Evidence Provider → [evidence] → Verifier
Verifier → [principal or error] → Enforcer
Enforcer → [action + principal] → System (if authenticated)
→ [error] → Subject (if failed)
Registration establishes the credential/evidence pair. Three approaches:
Key requirements:
Credential factors:
Evidence guidelines:
Prevent brute-force attacks:
BAD (Vulnerable):
# ❌ VULNERABILITY: Plaintext comparison and timing attack risk
def login(username, password):
user = database.get_user(username)
if user and user.password == password: # Never store plaintext!
return True
return False
GOOD (Secure):
import hmac
from werkzeug.security import check_password_hash
def login(username, password):
user = database.get_user(username)
# ✅ Use robust hashing (Argon2/PBKDF2/bcrypt) via verified library
if user and check_password_hash(user.password_hash, password):
return True
return False
BAD (Vulnerable):
// ❌ VULNERABILITY: Broken Logic
app.post('/login', (req, res) => {
const user = db.findUser(req.body.username);
if (user && user.password === req.body.password) { // Plaintext
res.status(200).send({ token: user.id }); // Leaking ID as token
}
});
GOOD (Secure):
const bcrypt = require('bcrypt'); // or argon2
app.post('/login', async (req, res) => {
const user = await db.findUser(req.body.username);
// ✅ Robust comparison, handle timing attacks implicitly by library
if (user && await bcrypt.compare(req.body.password, user.hash)) {
req.session.userId = user.id; // Use secure session
return res.status(200).send({ message: "Authenticated" });
}
// Generic error message to prevent enumeration
res.status(401).send({ error: "Invalid credentials" });
});
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.