sast-broken-auth
Detect Broken Authentication vulnerabilities in Next.js middleware, API routes, and session management. Use when reviewing login flows, session validation, password handling, or token management. Covers session fixation, credential exposure, weak passwords, and account enumeration.
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-05
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- sast-broken-auth
- description
- Detect Broken Authentication vulnerabilities in Next.js middleware, API routes, and session management. Use when reviewing login flows, session validation, password handling, or token management. Covers session fixation, credential exposure, weak passwords, and account enumeration.
03 SKILL.md 正文
SAST: Broken Authentication Detection
Scan for authentication flaws — OWASP A07:2021 (Identification and Authentication Failures).
What to Look For
High Risk Patterns
// ❌ VULNERABLE: credentials in URL
fetch(`/api/login?email=${email}&password=${password}`); // logged in server logs!
// ❌ VULNERABLE: session token in localStorage (XSS accessible)
localStorage.setItem('token', authToken);
// ❌ VULNERABLE: weak session ID generation
const sessionId = Math.random().toString(); // not cryptographically random
// ❌ VULNERABLE: password comparison timing attack
if (storedHash === inputHash) { ... } // use timingSafeEqual instead
// ❌ VULNERABLE: no rate limiting on login endpoint
// app/api/auth/login/route.ts with no rate limiting
// ❌ VULNERABLE: hardcoded admin credentials
if (password === 'admin123') { return true; }
// ❌ VULNERABLE: credential exposure in error messages
return NextResponse.json({ error: `User ${email} not found` }); // enumeration!
Safe Patterns
// ✅ SAFE: credentials in POST body (HTTPS)
fetch('/api/auth/login', { method: 'POST', body: JSON.stringify({ email, password }) });
// ✅ SAFE: HttpOnly, Secure, SameSite cookies
cookies().set('session', token, {
httpOnly: true, secure: true, sameSite: 'lax', maxAge: 86400
});
// ✅ SAFE: cryptographically secure session ID
import { randomBytes } from 'crypto';
const sessionId = randomBytes(32).toString('hex');
// ✅ SAFE: constant-time comparison
import { timingSafeEqual } from 'crypto';
const safe = timingSafeEqual(Buffer.from(a), Buffer.from(b));
// ✅ SAFE: generic error messages (no enumeration)
return NextResponse.json({ error: 'Invalid credentials' }, { status: 401 });
Kalmeron-Specific Checks
- Firebase Auth handles most auth — verify Firebase rules are correct
- Check
src/lib/auth/session.tsfor session management - API key generation in
app/(dashboard)/settings/api-keys/— verifyrandomBytesused - Webhook signing in
app/(dashboard)/settings/webhooks/— verify HMAC-SHA256
Scan Checklist
- [ ] Credentials never in URL query parameters
- [ ] Session tokens stored in HttpOnly cookies (not localStorage)
- [ ] Cryptographically secure random session IDs
- [ ] Rate limiting on authentication endpoints
- [ ] Generic error messages (no user enumeration)
- [ ] MFA available for sensitive operations
- [ ] Session invalidated on logout (server-side)
- [ ] Password hashing uses bcrypt/argon2 (not MD5/SHA1)
Severity Matrix
| Pattern | Severity |
|---|---|
| Hardcoded credentials | Critical |
| Credentials in URL | High |
| Session in localStorage | High |
| No rate limiting on login | High |
| Timing attack in comparison | Medium |
| User enumeration via errors | Medium |
Remediation
- Use Firebase Auth or established auth library — don't roll your own
- Store sessions in HttpOnly, Secure, SameSite cookies
- Implement rate limiting on
/api/auth/*routes - Return
401 Invalid credentialsfor both wrong email AND wrong password - Use
crypto.randomBytes(32)for all tokens and session IDs
04 同仓库更多 Skills
skill-creator
To create new CLI skills following Anthropic's official best practices with zero manual configuration. This skill automates brainstorming, template application, validation, and installation processes while maintaining progressive disclosure patterns and writing style standards.
business-investment-advisor
Business investment analysis and capital allocation advisor. Use when evaluating whether to invest in equipment, real estate, a new business, hiring, technology, or any capital expenditure. Also use for ROI calculations, IRR, NPV, payback period, build vs buy decisions, lease vs buy analysis, vendor evaluation, or deciding where to allocate limited budget for maximum return.
add-new-agent
خطوات تفصيليّة لإضافة وكيل ذكاء اصطناعي جديد إلى منصّة Kalmeron من الفكرة إلى الإنتاج
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
writing-plans
Use when you have a spec or requirements for a multi-step task, before touching code
web-design-guidelines
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".