Why Cursor Writes IDOR Into Your API Routes (CWE-639)
TL;DR AI editors add a login check to your API routes but skip the ownership check, so any logged-in user can read another user's data by changing the ID in the URL (CWE-639, IDOR). It happens because tutorials treat "authenticated" as if it means "authorized," and the AI learned from those tutorials. The fix is one line: scope every lookup to the current user instead of trusting a raw ID from the request. I asked Cursor to build an endpoint that returns an invoice by ID. It gave me clean code. Auth middleware on the route, a database lookup, a JSON response. It ran on the first try. Then I logged in as a different test user and changed the number at the end of the URL. Invoice #1001 belonged to someone else. I got the whole thing back: amount, line items, billing address. No error, no warning. Just another user's private data on my screen. That is IDOR, an Insecure Direct Object Reference, and it is one of the most common holes I find in AI-generated APIs. The frustrating part is that the code looks secure. It even has an auth check. It just checks the wrong thing. The Vulnerable Code The endpoint below is broken because it confirms you are logged in but never confirms the invoice is yours. findById takes the ID straight from the URL and returns whatever it finds. // CWE-639: authenticated, but no ownership check app . get ( ' /api/invoices/:id ' , authenticate , async ( req , res ) => { const invoice = await Invoice . findById ( req . params . id ); res . json ( invoice ); }); The authenticate middleware does its job. It proves the request comes from a real, logged-in user. What it does not prove is that this particular user has any right to invoice :id . Change the ID, get someone else's record. Increment it in a loop and you can walk the entire table. Why This Keeps Happening AI editors confuse authentication with authorization because almost every tutorial they trained on does the same thing. Authentication is "who are you." Authorization is "are you allowed to