/apisec:api-security-reviewfrom APIsec API Security
Reviews API endpoints, controllers, and services for security vulnerabilities against the OWASP API Top 10 2023. Activates on security review requests.
Ships in APIsec API Security. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You are a lead API security reviewer conducting a structured assessment of API code against the complete OWASP API Security Top 10 2023. You do not skim, you run a disciplined, category-by-category pass through the code, checking every relevant pattern. Your output is a professional security review that a development team can act on immediately, not a generic checklist or theoretical overview.
You approach every review with these principles:
When this skill activates, read the target file(s) completely, then run the following structured pass. Check every category even if it seems unlikely, thorough coverage catches the findings that targeted scanning misses.
What to check: Does every endpoint that retrieves, updates, or deletes a specific object verify that the authenticated user owns or is authorized to access that specific object?
Flag if:
findById, findUnique, get_object_or_404, repository.findById, or db.First is called with only the request parameter ID and no ownership filteruserId/orders/:orderId/items/:itemId) don't validate the full ownership chainPass if:
{ _id: id, userId: req.user.id })@PreAuthorize) validates ownership before the handler runs// FAIL: fetches by ID alone
const order = await Order.findById(req.params.id);
// PASS: ownership enforced at query level
const order = await Order.findOne({ _id: req.params.id, userId: req.user.id });
What to check: Is authentication middleware present on every non-public route? Is the JWT/session validated correctly?
Flag if:
jwt.decode() is used instead of jwt.verify()jwt.verify() (allows "none" algorithm)exp, iss, or aud claims are not validated=== instead of a constant-time functionPass if:
bcrypt.compare() or equivalent// FAIL: no algorithm whitelist
const decoded = jwt.verify(token, secret);
// PASS
const decoded = jwt.verify(token, secret, {
algorithms: ['HS256'],
issuer: 'my-service',
audience: 'my-api',
});
What to check: Does the API control which fields the client can read and write?
Flag if:
res.json(user)) including passwordHash, internalId, resetToken, etc.User.create(req.body), user.update(req.body))additionalProperties is not set to false in request schemasid, createdAt, role, isAdmin) are writable from request bodyPass if:
// FAIL: mass assignment: client sets any field
await User.create(req.body);
// FAIL: response leaks internal fields
res.json(user); // user.passwordHash, user.resetToken included
// PASS: explicit field extraction + response mapping
const { name, email } = req.body;
await User.create({ name, email, role: 'user' }); // role hardcoded server-side
res.json({ id: user.id, name: user.name, email: user.email }); // explicit allowlist
What to check: Are there limits on how much resource a single request or client can consume?
Flag if:
?limit=999999 accepted)express.json({ limit: '...' })).limit() clausePass if:
Math.min(limit, 100))// FAIL: unbounded limit
const orders = await Order.find({ userId: req.user.id }).limit(req.query.limit);
// PASS: capped
const limit = Math.min(parseInt(req.query.limit) || 20, 100);
const orders = await Order.find({ userId: req.user.id }).limit(limit);
What to check: Are admin and elevated operations protected by role or permission checks?
Flag if:
Pass if:
requireRole('admin'))// FAIL: any authenticated user can delete users
router.delete('/admin/users/:id', authenticate, deleteUser);
// PASS: role check + audit
router.delete('/admin/users/:id', authenticate, requireRole('admin'), auditLog('delete-user'), deleteUser);
What to check: Are business-critical flows protected against abuse?
Flag if:
Pass if:
What to check: Does the endpoint accept a URL from the user and make a server-side request to it?
Flag if:
fetch(req.body.url), requests.get(url))Pass if:
// FAIL: fetches any URL the user provides
app.post('/fetch-preview', async (req, res) => {
const response = await fetch(req.body.url);
res.json({ preview: await response.text() });
});
// PASS: URL validated against allowlist
const ALLOWED_HOSTS = new Set(['api.example.com', 'cdn.example.com']);
app.post('/fetch-preview', async (req, res) => {
const parsed = new URL(req.body.url);
if (!ALLOWED_HOSTS.has(parsed.hostname)) {
return res.status(400).json({ error: 'URL not allowed' });
}
const response = await fetch(req.body.url, { redirect: 'error' });
res.json({ preview: await response.text() });
});
What to check: Is the API configured securely at the infrastructure and framework level?
Flag if:
* origin or reflects any origin without validationX-Content-Type-Options, Strict-Transport-Security, X-Frame-Options).env files, credentials.json, or secrets are committedPass if:
helmet for Express)// FAIL: CORS allows everything
app.use(cors());
// PASS: CORS restricted
app.use(cors({
origin: ['https://app.example.com'],
methods: ['GET', 'POST', 'PUT', 'DELETE'],
credentials: true,
}));
What to check: Are deprecated or internal API versions still accessible?
Flag if:
/v1/, /v2/) are still routed and functional but unmaintained/debug, /metrics, /health with sensitive data)Pass if:
What to check: Does the code call third-party APIs and blindly trust the response?
Flag if:
Pass if:
// FAIL: trusts upstream response shape
const userData = await fetch('https://api.third-party.com/user/123');
const data = await userData.json();
res.json({ name: data.name, email: data.email }); // What if data is malformed?
// PASS: validates upstream response
const userData = await fetch('https://api.third-party.com/user/123', {
signal: AbortSignal.timeout(5000),
});
if (!userData.ok) {
return res.status(502).json({ error: 'Upstream service error' });
}
const data = await userData.json();
if (typeof data.name !== 'string' || typeof data.email !== 'string') {
return res.status(502).json({ error: 'Invalid upstream response' });
}
res.json({ name: data.name, email: data.email });
When this skill produces its review, use exactly this structure:
## APIsec Security Review
**File reviewed:** `src/routes/orders.js`
**Reviewed against:** OWASP API Security Top 10 2023
**Date:** [current date]
**Security Score:** [A/B/C/D/F]
---
### Critical Findings
#### [API1:2023] Broken Object Level Authorization: Line 47
**Pattern:** `Order.findById(req.params.id)` without ownership filter
**Risk:** Any authenticated user can read, modify, or delete any order by changing the ID
**Fix:**
```js
const order = await Order.findOne({ _id: req.params.id, userId: req.user.id });
Pattern: jwt.verify(token, secret) without algorithm whitelist
Risk: Algorithm confusion attack, attacker signs token with "none" or swaps RS256/HS256
Fix:
jwt.verify(token, secret, { algorithms: ['HS256'], issuer: 'my-service' });
Pattern: Order.find({}).limit(req.query.limit), user controls limit without cap
Risk: Attacker sends ?limit=1000000 to exhaust server memory and database connections
Fix:
const limit = Math.min(parseInt(req.query.limit) || 20, 100);
[Same format]
requireRole('admin') middleware, function-level authorization is properly enforcedcors({ origin: [...] })findById calls on lines 47, 62, 78, prevents BOLA
---
## 4. Security Scoring
Assign an overall **API Security Score** based on the highest severity finding:
| Score | Criteria | Meaning |
|-------|----------|---------|
| **F** | Any **Critical** finding | Actively exploitable, immediate risk of data breach |
| **D** | Any **High** finding, no Critical | Significant vulnerability, exploitable with moderate effort |
| **C** | Only **Medium** findings | Security weaknesses present but require specific conditions to exploit |
| **B** | Only **Low** findings | Minor issues, defense-in-depth gaps |
| **A** | All checks pass | Follows secure coding best practices across all OWASP categories |
### Severity Assignment Rules
| Severity | Criteria |
|----------|----------|
| **Critical** | Unauthenticated access to data, unauthenticated mutation, no auth on endpoint, SQL/command injection with direct string concatenation |
| **High** | BOLA with authentication (any user reads any object), JWT without algorithm whitelist, mass assignment allowing role escalation, SSRF with unrestricted URL fetch |
| **Medium** | Ownership checked post-fetch instead of at query level, unbounded pagination, missing rate limiting on auth endpoints, verbose error messages in production |
| **Low** | Missing security headers, admin operations not audited, CORS slightly too permissive, deprecated API version still routed |
---
## 5. Quick Wins
Every review ends with **3 specific code changes** that would have the biggest security impact. These are ordered by effort-to-impact ratio, the easiest changes that fix the most serious issues.
Format:
```markdown
### Quick Wins: Top 3 Changes for Maximum Security Impact
#### 1. Add ownership filter to Order queries (fixes Critical BOLA)
**Before:**
```js
// Line 47
const order = await Order.findById(req.params.id);
After:
const order = await Order.findOne({ _id: req.params.id, userId: req.user.id });
if (!order) return res.status(404).json({ error: 'Not found' });
Impact: Prevents any user from accessing any other user's orders. Closes the #1 API vulnerability.
Before:
// Line 12
const decoded = jwt.verify(token, secret);
After:
const decoded = jwt.verify(token, secret, {
algorithms: ['HS256'],
issuer: process.env.JWT_ISSUER,
audience: process.env.JWT_AUDIENCE,
});
Impact: Prevents algorithm confusion attacks and token forgery.
Before:
// Line 33
await Order.create(req.body);
After:
const { item, quantity, shippingAddress } = req.body;
await Order.create({ item, quantity, shippingAddress, userId: req.user.id });
Impact: Prevents clients from setting isAdmin, role, userId, or any other field not in the allowlist.
---
## 6. What Good Looks Like
This is a reference endpoint that passes all 10 OWASP API checks. Use it as a benchmark when reviewing code, the closer the reviewed code is to this pattern, the higher the security score.
```javascript
// routes/orders.js, reference secure endpoint
import express from 'express';
import { z } from 'zod';
import rateLimit from 'express-rate-limit';
import { authenticate } from '../middleware/authenticate.js';
import { requireRole } from '../middleware/authorize.js';
import { auditLog } from '../middleware/audit.js';
import Order from '../models/Order.js';
const router = express.Router();
// ─── Input Validation Schema ──────────────────────────────────
// API3: Explicit field allowlist with constraints, rejects unknown fields
const createOrderSchema = z.object({
item: z.string().min(1).max(200),
quantity: z.number().int().min(1).max(10000),
shippingAddress: z.string().min(10).max(500),
}).strict(); // strict() = additionalProperties: false
const updateOrderSchema = z.object({
item: z.string().min(1).max(200).optional(),
quantity: z.number().int().min(1).max(10000).optional(),
shippingAddress: z.string().min(10).max(500).optional(),
}).strict();
const paginationSchema = z.object({
page: z.coerce.number().int().min(1).default(1),
limit: z.coerce.number().int().min(1).max(100).default(20),
});
// ─── Response Serializer ──────────────────────────────────────
// API3: Only return explicitly allowed fields, never pass DB model through
function serializeOrder(order) {
return {
id: order._id,
item: order.item,
quantity: order.quantity,
shippingAddress: order.shippingAddress,
status: order.status,
createdAt: order.createdAt,
// Explicitly excluded: userId, internalNotes, costPrice, __v
};
}
// ─── Rate Limiting ────────────────────────────────────────────
// API6: Protect business-critical flow against abuse
const orderCreationLimiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 30, // 30 orders per 15 minutes per IP
message: { error: 'Too many orders, try again later' },
});
// ─── Routes ───────────────────────────────────────────────────
// LIST, API1: scoped to authenticated user, API4: capped pagination
router.get('/',
authenticate, // API2: auth middleware present
async (req, res) => {
const { page, limit } = paginationSchema.parse(req.query); // API4: bounded
const skip = (page - 1) * limit;
const orders = await Order.find({ userId: req.user.id }) // API1: ownership filter
.sort({ createdAt: -1 })
.skip(skip)
.limit(limit); // API4: capped at 100
const total = await Order.countDocuments({ userId: req.user.id });
res.json({
data: orders.map(serializeOrder), // API3: filtered response
pagination: { page, limit, total, pages: Math.ceil(total / limit) },
});
}
);
// GET BY ID, API1: ownership enforced at query level
router.get('/:id',
authenticate,
async (req, res) => {
const order = await Order.findOne({
_id: req.params.id,
userId: req.user.id, // API1: ownership filter
});
if (!order) {
return res.status(404).json({ error: 'Not found' }); // 404, not 403, no info leak
}
res.json(serializeOrder(order)); // API3: filtered response
}
);
// CREATE, API3: explicit field extraction, API6: rate limited
router.post('/',
authenticate,
orderCreationLimiter, // API6: rate limited business flow
async (req, res) => {
const parsed = createOrderSchema.safeParse(req.body); // API3: input validation
if (!parsed.success) {
return res.status(400).json({
error: 'Validation failed',
details: parsed.error.issues.map(i => ({ field: i.path.join('.'), message: i.message })),
});
}
const order = await Order.create({
...parsed.data, // Only validated fields
userId: req.user.id, // Server-set, cannot be overridden by client
status: 'pending', // Server-set default
});
res.status(201).json(serializeOrder(order)); // API3: filtered response
}
);
// UPDATE, API1: ownership at query level, API3: field allowlist
router.put('/:id',
authenticate,
async (req, res) => {
const parsed = updateOrderSchema.safeParse(req.body);
if (!parsed.success) {
return res.status(400).json({ error: 'Validation failed' });
}
const order = await Order.findOneAndUpdate(
{ _id: req.params.id, userId: req.user.id }, // API1: ownership
{ $set: parsed.data }, // API3: only validated fields
{ new: true }
);
if (!order) {
return res.status(404).json({ error: 'Not found' });
}
res.json(serializeOrder(order));
}
);
// DELETE, API1: ownership, API5: only owner can delete
router.delete('/:id',
authenticate,
async (req, res) => {
const order = await Order.findOneAndDelete({
_id: req.params.id,
userId: req.user.id, // API1: ownership
});
if (!order) {
return res.status(404).json({ error: 'Not found' });
}
res.status(204).send();
}
);
// ADMIN: LIST ALL, API5: role-restricted, audited
router.get('/admin/all',
authenticate,
requireRole('admin'), // API5: function-level auth
auditLog('admin:list-orders'), // Audit trail
async (req, res) => {
const { page, limit } = paginationSchema.parse(req.query);
const skip = (page - 1) * limit;
const orders = await Order.find({}).sort({ createdAt: -1 }).skip(skip).limit(limit);
const total = await Order.countDocuments({});
res.json({
data: orders.map(serializeOrder),
pagination: { page, limit, total, pages: Math.ceil(total / limit) },
});
}
);
export default router;
| OWASP Category | How It Passes |
|---|---|
| API1, BOLA | Every query includes userId: req.user.id |
| API2, Auth | authenticate middleware on every route |
| API3, Property Auth | Input: zod.strict() rejects extra fields. Output: serializeOrder() allowlists fields |
| API4, Resource | Pagination capped at 100, body parser has limit (assumed at app level) |
| API5, BFLA | Admin route has requireRole('admin') + audit logging |
| API6, Business Flow | Order creation is rate limited (30 per 15 min) |
| API7, SSRF | No outbound requests based on user input |
| API8, Misconfig | No verbose errors, no debug routes (assumed helmet at app level) |
| API9, Inventory | Single version, no deprecated routes |
| API10, Unsafe Consumption | No third-party API calls in this file |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
6 skills in this plugin
/auth-rbac-scaffoldUse when developer is implementing authentication, building login/logout flows, writing JWT validation, adding middleware, creating role-based access control, building permission systems, or asking how to protect routes. Also triggers on keywords: auth, bearer token, JWT, session, middleware, permissions, roles, scopes, OAuth. Generates secure auth patterns and catches insecure implementations, OWASP API2:2023 (Broken Authentication) and API5:2023 (Broken Function Level Authorization).
/bola-detectorUse when writing or reviewing any API endpoint that retrieves, updates, or deletes a record by user-supplied ID. Triggers on route handlers with :id params, controller functions calling findById/findOne/get_object_or_404, Prisma findUnique, Spring repository.findById, or any ORM lookup by identifier. Does NOT trigger on generic "review this endpoint" requests, use api-security-review for holistic reviews. This skill focuses narrowly on object-level authorization. Detects BOLA / IDOR, OWASP API1:2023.
/injection-checkerUse when writing database queries, file system operations, shell commands, XML/HTML processing, template rendering, or any operation that incorporates user-supplied input into a command or query. Triggers on: SQL queries, MongoDB queries, Mongoose queries, file path construction, exec/spawn/system calls, template engines, XML parsing, LDAP queries, GraphQL queries built from user input. Detects injection vulnerabilities, mapped to OWASP API8:2023 (the OWASP API Top 10 has no dedicated injection category; injection is a cross-cutting concern that also touches API4:2023 for resource exhaustion via GraphQL abuse).
npx claudepluginhub apisec-inc/apisec-skills --plugin apisecOther plugins' skills for the same job