sast-missing-auth
Detect Missing Authorization vulnerabilities — API endpoints accessible without authentication. Use when reviewing all API routes to ensure every endpoint that accesses user data validates the session. Critical for multi-tenant SaaS like Kalmeron.
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-05
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- sast-missing-auth
- description
- Detect Missing Authorization vulnerabilities — API endpoints accessible without authentication. Use when reviewing all API routes to ensure every endpoint that accesses user data validates the session. Critical for multi-tenant SaaS like Kalmeron.
03 SKILL.md 正文
SAST: Missing Authorization Detection
Scan for unprotected endpoints — OWASP A01:2021 (Broken Access Control).
What to Look For
High Risk Patterns
// ❌ VULNERABLE: API route with no auth check
export async function GET(req: NextRequest) {
const users = await db.collection('users').get(); // no session check!
return NextResponse.json(users.docs.map(d => d.data()));
}
// ❌ VULNERABLE: only checking presence, not validity
const token = req.headers.get('authorization');
if (!token) return 401; // but never verifies the token!
// ❌ VULNERABLE: role check missing for admin operation
export async function DELETE(req: NextRequest, { params }) {
const session = await getServerSession(); // authenticated but...
await db.collection('users').doc(params.id).delete(); // no admin check!
}
Safe Patterns
// ✅ SAFE: session verified at route start
export async function GET(req: NextRequest) {
const session = await getServerSession();
if (!session?.user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
// proceed with session.user.id
}
// ✅ SAFE: role-based check for admin operations
const session = await getServerSession();
if (!session?.user || session.user.role !== 'admin') {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
}
// ✅ SAFE: middleware-level protection
// middleware.ts — protect all /api/* routes except auth endpoints
Kalmeron Middleware Analysis
Check middleware.ts for route protection:
/api/auth/*— public (login/register)/api/billing/*— authenticated/api/user/*— authenticated + self-only/admin/*— authenticated + admin role/api/notifications/*— authenticated
Scan Checklist
- [ ] Every
app/api/route that accesses user data callsgetServerSession()first - [ ]
getServerSession()result checked for null before use - [ ] Admin operations check
session.user.role === 'admin' - [ ]
middleware.tscovers all sensitive route patterns - [ ] Public routes (landing, auth) explicitly excluded from auth requirements
- [ ] Webhook endpoints verify HMAC signature instead of session
Protected Route Audit Template
// Pattern to verify in each API route:
export async function [METHOD](req: NextRequest) {
// 1. Get session
const session = await getServerSession();
// 2. Verify authentication
if (!session?.user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
// 3. (for admin routes) Verify authorization
if (session.user.role !== 'admin') return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
// 4. Proceed with session.user.id for data scoping
}
Severity Matrix
| Pattern | Severity |
|---|---|
| No auth on data-returning endpoint | Critical |
| No auth on data-modifying endpoint | Critical |
| Auth present but not verified | Critical |
| Admin endpoint lacks role check | High |
| Webhook without signature verification | High |
Remediation
- Add
getServerSession()+ null check at the top of every protected route - Use Next.js middleware to enforce auth at the infrastructure level
- Create a helper
requireAuth(req)that throws on missing/invalid session - Review all
app/api/routes with a checklist — every endpoint must be classified - Add integration tests that verify 401 on unauthenticated requests
04 同仓库更多 Skills
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".
vitest
Set up Vitest testing in any project — detects project type (Cloudflare Workers, React, Node), generates vitest.config.ts, test setup, utilities, and sample tests. Also covers mocking patterns, coverage config, workspace setup, and Jest migration. Trigger with 'set up vitest', 'add tests', 'configure vitest', 'migrate from jest', 'vitest config', 'add unit tests', or 'testing setup'.
verification-loops
Use when about to claim work is complete, fixed, or passing, before committing or creating PRs. Requires running verification commands and confirming output before making any success claims. Evidence before assertions always.