Teardown: An AI-Built App Before and After an Engineering Review

An engineering review of an AI-built app is mostly not about style. It is about one question asked of every route: who is allowed to do this, to whose data? This review was run on a 76-line invoice tracker that works perfectly for its owner. It failed 8 of 9 security checks. The same app, fixed, passes all 9.
The app is a demo written for this post, in the style AI coding tools produce by default. It is not a real customer’s app or the output of one named tool, and its flaws are the ordinary kinds. OWASP ranked broken access control #1 in both its 2021 and 2025 lists, and in 2025 it reports that 100% of the applications it tested (the ones tested by contributing organizations) had some form of broken access control. Yours is probably in that number too.
All the code is on the site, so you can run the before and the after yourself: /examples/invoice-tracker-teardown/.
What the app does, and why it looks fine
The prompt was one paragraph: freelancers sign up, log in, create invoices, mark them paid, search by client name. Express, SQLite, login tokens. Everything works for the owner, and a demo delights whoever asked for it. That is the trap: a feature that works for the owner says nothing about what happens when a second person logs in and gets curious.
The review order: start at the doors
The review does not read the code top to bottom. It lists every place where something from outside enters the program, then asks the question at each one. In this app that is a handful of lines you can find with grep:
grep -nE 'req\.(params|query|body)' server.js # every doorgrep -nE '\$\{' server.js | grep -iE 'select|update|insert' # SQL built from stringsgrep -nE 'process\.env\.[A-Z_]+ \|\|' server.js # secrets with a fallback valuegrep -n 'Object.keys(req.body)' server.js # the whole body written to the databasegrep -nE 'md5|sha1|createHash' server.js # password storageOn this file the second command finds the injectable search and the PATCH route, the third finds the default secret, and the last finds the MD5. The first lists seven doors, and the missing ownership check is any door whose query never mentions req.user. That works for 76 lines. Past that, rely on a per-route two-user test, as the tests below do. Run them on your own app.
Then play two users. Alice has one invoice. Mallory has an account and nothing else. These are the six things Mallory did, using only her own login and curl, against the real “before” code.
What a stranger could do
1. Read Alice’s invoice by asking for its number.
GET /api/invoices/1 (as Mallory){"id":1,"user_id":1,"client":"Acme Corp","amount":4200,"status":"unpaid"}Nothing asks whose invoice it is. OWASP calls this broken object level authorization, and it is easy to ship because the happy path never trips over it: the owner always sees their own data.
2. Mark Alice’s invoice paid. Same missing question, on PATCH. Returns {"ok":true}.
3. Take Alice’s invoice for herself. The PATCH route writes whatever fields arrive in the request body, so Mallory sent {"user_id":2} and the invoice moved to her account. OWASP has a name for this too, broken object property level authorization. Most people know it as mass assignment.
4. Dump every user and password hash through the search box. The search term is pasted into the SQL string. Mallory searched for a snippet of SQL and got back this:
[{"client":"[email protected]","amount":"15da1f78ad7d474862865bab1aab4d51"}, ...]The second value is the MD5 of Alice’s password. MD5 is fast and unsalted, so a lookup table cracks it instantly. OWASP’s password storage guide says to use a slow, salted algorithm: Argon2id first, scrypt if Argon2id is not available.
5. Create an invoice for negative $99,999. Accepted. The amount is stored as a floating point number, and nothing checks it is above zero.
6. Read the server’s internals from an error message. One bad request returned a stack trace with the file paths on the server.
There is a seventh problem that never showed up as a request, because you have to read the code to see it:
const SECRET = process.env.JWT_SECRET || "supersecret123";Forget to set JWT_SECRET in production and the app runs on a password that sits in the source code. Anyone who finds it can sign a login token for any user. Tokens without an expiry never stop working, either. A test signs a token with that default secret, and the “before” app accepts it.
The fixes, in the order to do them
Rank by how bad it is when it goes wrong and how easy it is for a stranger to try.
Ownership goes into the query, not after it. Every query that takes an id also takes the owner:
db.prepare("SELECT * FROM invoices WHERE id = ? AND user_id = ?").get(req.params.id, req.user.id);If nothing comes back, answer 404, not 403. A 403 says “this exists, but not for you”; a 404 does not reveal which invoice numbers are real. That is a judgment call, and the tests accept either answer.
Writes use an allowlist. The PATCH route now accepts client, amount and status. Anything else, including user_id, gets a 400.
Search uses placeholders. A placeholder is the ? in the query: the database receives the SQL and the user’s text separately, so text can never be read as SQL. The user’s % and _ are also escaped, because they are wildcards in a LIKE search.
The server refuses to start without a real secret. No fallback value: a crash on deploy day beats a silent default. Login tokens now expire in one hour, and the check pins the one signing algorithm the app uses.
Passwords go through scrypt, with a catch. Node’s built-in crypto.scryptSync makes this easy, but its default is far weaker than what OWASP asks for. OWASP’s minimum for scrypt is N=2^17, r=8, p=1. That exact setting was tried on Node 22:
ERR_CRYPTO_INVALID_SCRYPT_PARAMS: memory limit exceededNode refuses until you raise maxmem, which is why many apps stay on the default. With it raised, one hash took about 300 ms on the test machine (a Linux container, Node 22), against about 38 ms for the default, and each login holds about 128 MB for a moment. An attacker who hammers login can eat your memory, so the “after” app also rate-limits login and signup.
Two smaller details: a login for an email that does not exist still hashes a dummy password, so timing does not reveal which emails have accounts, and behind a proxy the rate limiter needs app.set("trust proxy", ...) set for your host, or every visitor looks like one address (the library logged ERR_ERL_UNEXPECTED_X_FORWARDED_FOR when tried).
Money becomes whole cents, and the database says no too. Amounts are stored as integers (420000 for $4,200.00), because floating point cannot represent most cents exactly. The table also gets CHECK (amount_cents > 0). The second guard is there because the next AI-added feature or script may skip your route’s validation. The database does not.
Errors go to the log, not to the caller.
The tests are the deliverable
The most useful thing here is not the fixed server. It is a file of nine tests that each play Mallory:
test("a stranger cannot read someone else's invoice", async () => { const r = await call("GET", `/invoices/${invoiceId}`, mallory); assert.ok(r.status === 403 || r.status === 404);});These tests check behavior: what a logged-in person can get or do through the API. None of them look at how the code is written, so a rewrite that breaks a behavior still fails. Each test also checks that the feature still works, not only that the attack fails: the search test confirms Alice can still find her invoice, and the PATCH test confirms ownership did not change whatever status the API returned. (The expiry test uses Node’s experimental clock mock to jump 25 hours ahead, so it prints an experimental warning.) They also only protect what they cover. Nine tests do not prove the app is safe. They prove these nine promises hold.
They were run against the “before” app first, in a scratch folder after a clean npm install:
$ npm run test:before✖ a stranger cannot read someone else's invoice✖ a stranger cannot edit someone else's invoice✔ the owner can still read and edit✖ user_id cannot be reassigned through PATCH✖ search input is data, not SQL, and search still works✖ negative and zero amounts are rejected✖ a token signed with a guessable secret is rejected✖ errors do not leak stack traces✖ a login token stops working after a dayℹ tests 9 ℹ pass 1 ℹ fail 8The one that passes is the only thing a demo ever checks. After the fixes:
$ npm run test:after✔ a stranger cannot read someone else's invoice✔ a stranger cannot edit someone else's invoice✔ the owner can still read and edit✔ user_id cannot be reassigned through PATCH✔ search input is data, not SQL, and search still works✔ negative and zero amounts are rejected✔ a token signed with a guessable secret is rejected✔ errors do not leak stack traces✔ a login token stops working after a dayℹ tests 9 ℹ pass 9 ℹ fail 0Write the failing test before the fix and you cannot fool yourself, and neither can your AI tool. It also means the next prompt that touches this file cannot quietly undo a fix.
What this review did not cover
Limits. This was one review of 76 lines. Real apps are thousands of lines. It did not look at HTTPS settings, password reset, email verification, logging, token revocation, backups, or whether the dependencies have known problems. Signup still reveals whether an email is registered, a trade most small apps accept. The first two things to add next are npm audit --omit=dev (plain npm audit is noisy with advisories for tools that never reach production) and a test that a second user can never see the first user’s data on every new route.
Paste this into your AI tool
Review this app like a hostile second user. For every route that takes an id,a query string or a request body, tell me: (1) who is allowed to call it,(2) where in the code that is checked, and (3) what happens if a differentlogged-in user calls it with someone else's id. Then write one failing testper problem you find, run them, show me the output, and only then fix the codeand rerun. Do not change anything until the failing tests exist.Check by hand
Make two accounts in your own app. Create something with the first, copy its URL or id, and open it logged in as the second. If it loads, you have found the bug that fills the OWASP list. For the longer version of this check, see Is Your Lovable App Safe?.
If your database is Supabase, row level security does the job of the AND user_id = ? clause for you. This post explains how. And if a key is ever exposed, here is how to find it and rotate it. When you are close to launching, run the launch checklist.
The Get AI Native ebook goes deeper on this. It is free, and the expected launch is around Christmas. Join the waitlist on the homepage.