Claude MCP skill privilege escalation — admin panel and support ticket access control
req.user.role === 'admin' from JWT payload not DB; attacker crafts JWT with role:admin using obtained signing secret; full admin panel access including user management and billing overrideGET /api/support/tickets/:id missing tenant isolation; attacker reads any user's support tickets by sequential ID; tickets may contain security findings, internal service details, and incident post-mortemsPOST /api/admin/impersonate/:userId accessible to support role users; support agents impersonate any user including admins; no impersonation audit log; no time limitGET /api/internal/metrics has no authentication; any network client reads aggregate user counts, revenue metrics, and infrastructure health dataPRIVESC11-001 — JWT role claim bypass grants full admin panel access
The admin panel middleware checks req.user.role === 'admin' where req.user is populated directly from the decoded JWT payload without a database lookup. The JWT signing secret was leaked in a public GitHub commit (a common occurrence when developers accidentally commit .env files). An attacker who obtains the JWT signing secret can craft a valid JWT with {"sub":"any-user-id","role":"admin"} and gain full admin panel access including the ability to list all users, override subscription tiers, approve flagged skills, and read internal configuration.
// PRIVESC11-001 — VULNERABLE
// req.user populated from JWT payload — role comes from the token, not from DB
const jwt = require('jsonwebtoken');
function requireAdmin(req, res, next) {
const token = req.headers.authorization?.replace('Bearer ', '');
if (!token) return res.status(401).end();
try {
req.user = jwt.verify(token, process.env.JWT_SECRET); // role from token payload
} catch {
return res.status(401).end();
}
if (req.user.role !== 'admin') return res.status(403).end(); // trusts JWT claim
next();
}
// Attacker crafts: jwt.sign({ sub: 'any-id', role: 'admin' }, LEAKED_SECRET, { expiresIn: '1y' })
JWT payloads are tamper-evident but not authorization-authoritative: A JWT signature proves the payload has not been modified since it was signed. It does not prove the payload reflects the current state of the user's role in the database. The JWT signing secret is frequently leaked through .env files in git history, CI/CD logs, error messages, or configuration management systems. Any application that trusts a JWT claim as the sole source of truth for authorization is one secret leak away from a complete privilege escalation. Always fetch the role from the database using the JWT's subject (sub) claim as the lookup key.
// PRIVESC11-001 — FIXED
// Role fetched from DB on every admin request — JWT is used only for identity, not authorization
const jwt = require('jsonwebtoken');
async function requireAdmin(req, res, next) {
const token = req.headers.authorization?.replace('Bearer ', '');
if (!token) return res.status(401).end();
let decoded;
try {
decoded = jwt.verify(token, process.env.JWT_SECRET);
} catch {
return res.status(401).end();
}
// Always fetch role from DB — never trust JWT payload for authorization
const user = await db.users.findById(decoded.sub, { select: ['id', 'role', 'suspended'] });
if (!user || user.suspended) return res.status(401).end();
if (user.role !== 'admin') return res.status(403).end();
req.user = { id: user.id, role: user.role }; // set from DB, not from token
next();
}
PRIVESC11-002 — Sequential support ticket IDOR exposes all users' tickets
The support ticket endpoint uses sequential integer IDs. The endpoint fetches the ticket by ID without verifying that the requesting user owns the ticket. Any authenticated user who increments the ticket ID number can read any other user's support tickets. Support tickets for an MCP skill registry frequently contain security vulnerability reports, internal service configuration questions, billing disputes with detailed account information, and incident post-mortems with infrastructure details.
// PRIVESC11-002 — VULNERABLE
// No ownership check — attacker iterates ticket IDs to read all users' tickets
router.get('/tickets/:id', requireSession, async (req, res) => {
const ticket = await db.supportTickets.findById(req.params.id);
if (!ticket) return res.status(404).end();
// Missing: if (ticket.userId !== req.session.userId) return res.status(403).end();
res.json(ticket); // returns ticket content including security reports and billing disputes
});
// PRIVESC11-002 — FIXED
// Use UUID ticket IDs (not sequential integers) + ownership check + 404 on not-owner
router.get('/tickets/:id', requireSession, async (req, res) => {
// findByIdAndUserId returns null for both "not found" and "not owned by this user"
// This prevents 403/404 distinguishability (timing oracle + enumeration)
const ticket = await db.supportTickets.findByIdAndUserId(req.params.id, req.session.userId);
if (!ticket) return res.status(404).end(); // 404 not 403 — prevents user enumeration
res.json({
id: ticket.id,
subject: ticket.subject,
status: ticket.status,
messages: ticket.messages,
createdAt: ticket.createdAt,
// Internal fields (agent notes, internal_flags) never returned to users
});
});
Return 404 not 403 for ownership failures: Returning HTTP 403 (Forbidden) when a resource exists but the caller does not own it leaks the information that the ID is valid. An attacker who gets 403 knows the ticket exists and belongs to someone else; they get 404 knowing the ID is invalid or the resource is theirs but absent. By returning 404 for all "not found or not owned" cases, you prevent ID enumeration attacks. Always combine this with UUID (not sequential integer) resource IDs to remove the sequential enumeration vector entirely.
PRIVESC11-003 — Support role can impersonate any user including admins
The admin impersonation endpoint was intended to allow admin users to impersonate customers for support purposes. The access control check only requires the support role, which is assigned to customer support agents who are not admins. A support agent can call POST /api/admin/impersonate/:userId with any user ID, including other admin accounts. Because there is no impersonation audit log, this escalation leaves no trace. A compromised support agent account provides a lateral movement path to full admin access.
// PRIVESC11-003 — VULNERABLE
// 'support' role can impersonate any user — no restriction on impersonating admins
// No audit log for impersonation events
router.post('/impersonate/:userId',
requireRole('support'), // should be 'admin', not 'support'
async (req, res) => {
const targetUser = await db.users.findById(req.params.userId);
if (!targetUser) return res.status(404).end();
// No check: if targetUser.role === 'admin' and requester is not admin → reject
const impersonationToken = jwt.sign(
{ sub: targetUser.id, role: targetUser.role, impersonatedBy: req.session.userId },
process.env.JWT_SECRET,
{ expiresIn: '1h' }
);
// No audit log — impersonation happens silently
res.json({ token: impersonationToken });
}
);
// PRIVESC11-003 — FIXED
// Restrict to admin role only. Prevent admin impersonating admin.
// Mandatory audit log. Time-limited impersonation session.
router.post('/impersonate/:userId',
requireRole('admin'), // only admins can impersonate — not support role
async (req, res) => {
const targetUser = await db.users.findById(req.params.userId);
if (!targetUser) return res.status(404).end();
// Admin cannot impersonate another admin — prevents privilege escalation via impersonation
if (targetUser.role === 'admin') {
return res.status(403).json({ error: 'Cannot impersonate admin accounts' });
}
// Mandatory audit log — cannot be disabled
await db.auditLog.create({
action: 'user_impersonated',
actorId: req.session.userId,
targetId: targetUser.id,
ip: req.ip,
userAgent: req.headers['user-agent'],
at: new Date(),
});
// Time-limited impersonation token (15 minutes)
const impersonationToken = jwt.sign(
{
sub: targetUser.id,
impersonatedBy: req.session.userId,
isImpersonation: true,
// Role is intentionally NOT set — impersonation sessions have no extra permissions
},
process.env.JWT_SECRET,
{ expiresIn: '15m' } // short expiry — not 1 hour
);
res.json({ token: impersonationToken, expiresInMinutes: 15 });
}
);
PRIVESC11-004 — Unauthenticated internal metrics endpoint
The internal metrics endpoint GET /api/internal/metrics returns aggregate statistics including total registered users, monthly active users, revenue by plan tier, audit counts, top skills by installation count, and infrastructure health data (database connection pool size, Redis memory usage, worker queue depths). The endpoint was intended to be accessible only from internal monitoring systems but has no authentication check. Any network client with access to the application port can retrieve this data.
// PRIVESC11-004 — VULNERABLE
// No authentication — any network client reads business and infrastructure metrics
router.get('/internal/metrics', async (req, res) => {
const metrics = await Promise.all([
db.users.count(),
db.users.countActiveLastMonth(),
db.subscriptions.revenueByPlan(),
db.audits.countByStatus(),
db.skills.topByInstallations(10),
redis.info('memory'),
db.pool.stats(),
]);
res.json({
totalUsers: metrics[0],
mau: metrics[1],
revenue: metrics[2], // attacker reads monthly revenue breakdown by plan tier
audits: metrics[3],
topSkills: metrics[4],
redisMemory: metrics[5],
dbPool: metrics[6],
});
});
// PRIVESC11-004 — FIXED
// Two-layer protection: internal network only (via reverse proxy) + bearer token
// Expose Prometheus format for monitoring systems, not JSON with business data
const METRICS_TOKEN = process.env.INTERNAL_METRICS_TOKEN; // long random token set in env
function requireInternalMetricsAuth(req, res, next) {
// Layer 1: reverse proxy sets X-Internal-Request header only for internal network traffic
if (!req.headers['x-internal-request']) return res.status(403).end();
// Layer 2: bearer token for defence-in-depth
const auth = req.headers.authorization;
if (!auth || auth !== `Bearer ${METRICS_TOKEN}`) return res.status(401).end();
next();
}
router.get('/internal/metrics', requireInternalMetricsAuth, async (req, res) => {
// Return Prometheus text format — not raw business data as JSON
// Monitoring systems scrape /metrics in Prometheus format; this endpoint is for health only
const lines = [
`skillaudit_users_total ${await db.users.count()}`,
`skillaudit_audits_queued ${await workerQueue.queueDepth()}`,
`skillaudit_db_pool_available ${(await db.pool.stats()).available}`,
// Revenue and MAU metrics are NOT exposed here — they go to internal BI tooling only
];
res.set('Content-Type', 'text/plain; version=0.0.4').send(lines.join('\n'));
});
Hardening summary
| Finding | Pattern | Fix |
|---|---|---|
| PRIVESC11-001 | JWT role claim used for admin authorization without DB check | Fetch role from DB on every admin request; JWT for identity only |
| PRIVESC11-002 | Sequential ticket ID without ownership check (IDOR) | UUID IDs; findByIdAndUserId(); return 404 for both not-found and not-owned |
| PRIVESC11-003 | Support role can impersonate admins with no audit log | Admin role required; block admin-on-admin impersonation; mandatory audit log; 15-min expiry |
| PRIVESC11-004 | Internal metrics endpoint with no authentication | Reverse proxy network restriction + bearer token; Prometheus format, no business data |
Related: SA-SKL-PRIVESC10, SA-SKL-PRIVESC9. Run SkillAudit to surface all PRIVESC11 patterns in your MCP skill registry.