T05 · Unauthorized Access and Privilege Escalation
- Location
assets/moderation-dashboard-starter/src/server.ts:34- Finding
Unauthenticated Moderation and Audit API
- Content
View full analysis
Vulnerability Details
File Location:
assets/moderation-dashboard-starter/src/server.ts:34-61
Vulnerability Type: Missing authentication, missing guild-level authorization, and client-controlled actor attribution
Risk Level: HighVulnerable Code
ts app.get('/warnings/:guildId/:userId', (req, res) => { const rows = db.prepare('SELECT * FROM warnings WHERE guild_id = ? AND user_id = ? ORDER BY id DESC').all(req.params.guildId, req.params.userId); res.json(rows); }); app.post('/warnings', (req, res) => { const now = new Date().toISOString(); db.prepare('INSERT INTO warnings (guild_id, user_id, moderator_user_id, reason, created_at) VALUES (?, ?, ?, ?, ?)') .run(req.body.guildId, req.body.userId, req.body.moderatorUserId, req.body.reason, now); db.prepare('INSERT INTO audit_log (actor_user_id, guild_id, action_type, payload_json, created_at) VALUES (?, ?, ?, ?, ?)') .run(req.body.moderatorUserId, req.body.guildId, 'warning.create', JSON.stringify(req.body), now); res.json({ ok: true, createdAt: now }); }); app.post('/mod-actions', (req, res) => { const now = new Date().toISOString(); db.prepare('INSERT INTO mod_actions (guild_id, target_user_id, moderator_user_id, action_type, reason, created_at) VALUES (?, ?, ?, ?, ?, ?)') .run(req.body.guildId, req.body.targetUserId, req.body.moderatorUserId, req.body.actionType, req.body.reason, now); db.prepare('INSERT INTO audit_log (actor_user_id, guild_id, action_type, payload_json, created_at) VALUES (?, ?, ?, ?, ?)') .run(req.body.moderatorUserId, req.body.guildId, `mod.${req.body.actionType}`, JSON.stringify(req.body), now); res.json({ ok: true, createdAt: now }); }); app.get('/audit-log/:guildId', (req, res) => { const rows = db.prepare('SELECT * FROM audit_log WHERE guild_id = ? ORDER BY id DESC LIMIT 100').all(req.params.guildId); res.json(rows); });Technical Analysis
All moderation ...[truncated 2041 chars]
- Remediation
View remediation
Remediation Suggestions
- Require authentication middleware on every warning, moderation-action, and audit endpoint.
- Derive the acting moderator ID from the authenticated session or verified service credential; never accept authoritative actor identity from the request body.
- On every request, verify that the authenticated user belongs to the specified guild and possesses the required Discord moderation or administrative permission.
- Enforce tenant isolation in the data-access layer so records can only be queried or modified for authorized guilds.
- Restrict CORS to an explicit configuration-based allowlist rather than using unrestricted
cors(). - Validate request bodies with a strict schema, including Discord snowflake format, allowed action types, required text fields, and reasonable length limits.
- Return generic authorization errors without disclosing whether unauthorized guild or user records exist.
- Add rate limiting, security logging, and tests covering unauthenticated access, moderator impersonation, and cross-guild requests.
