How to fix: Sequential/Predictable IDs in API Responses
API responses contain predictable sequential integer IDs for user accounts or resources. This enables IDOR (Insecure Direct Object Reference) enumeration: an attacker can iterate IDs to access any user's data.
Why it matters
Predictable IDs allow attackers to enumerate all resources: change /users/1000 to /users/1001 to access another user's data if the authorization check is absent or weak. This is one of the most common and dangerous patterns in AI-generated CRUD APIs.
AI-generated CRUD scaffolding uses integer primary keys and exposes them directly. The correct defense is either UUIDs (random, non-enumerable) or strict per-object authorization checks that verify ownership on every request.
How to fix it
- 1Use random UUIDs (uuid_generate_v4()) as public-facing IDs instead of sequential integers.
- 2Add authorization checks on every resource endpoint: verify the requesting user owns or has access to the object.
- 3Never assume 'the user can only see their own data'; always verify ownership server-side.
- 4Consider using opaque tokens (base64url of encrypted ID) to hide internal ID structure.
Code examples
UUID primary key in PostgreSQL
-- Use UUIDs instead of SERIAL
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email TEXT NOT NULL UNIQUE,
created_at TIMESTAMPTZ DEFAULT NOW()
);Authorization check on resource access
export async function GET(req: Request, { params }: { params: { id: string } }) {
const session = await getSession(req);
const resource = await db.getResource(params.id);
if (!resource) return notFound();
if (resource.userId !== session.userId) return forbidden();
return Response.json(resource);
}References
Detected automatically by VulnRadar. The check id is vibe-predictable-userid, stable across every scan so you can filter or diff on it.
More ai code checks
- LowGeneric Error Messages Leak No Context
- MediumTODO/FIXME Security Note in Response
- Higheval() Usage in Page Scripts
- HighSSL Certificate Verification Disabled
- HighMath.random() Used for Security Tokens
- CriticalHardcoded Credential in Authentication Logic
- CriticalJWT 'none' Algorithm Accepted
- CriticalSQL String Concatenation Pattern Detected
Questions
- How severe is Sequential/Predictable IDs in API Responses?
- VulnRadar rates this medium severity in the ai code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id vibe-predictable-userid, which stays the same between runs so you can filter, diff, or gate CI on it.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.