Reviewing AI-generated code for security
10 questions on authentication versus authorisation, abuse cases and weakened boundaries in generated code. With explanations.
- 10 questions
- Stopwatch
- Instant feedback
Sample questions
Play now ↑Answers stay hidden. Start the quiz to play them.
Sample 1
A route checks that the caller is signed in. What is still missing?
- Authorisation: whether this caller may see this specific record
- A longer route name
- HTTPS in the browser
How it works
- One question per screen. An answer is final once sent.
- You see right away whether you were right, with a short explanation.
- The stopwatch runs: on equal scores, the faster player ranks first.
- Only your best attempt counts, so replaying is never risky.
About this quiz
Generated code can work perfectly for the intended user and still be unsafe. A route that checks that someone is signed in does not check that this person is allowed to see this record. A feature that passes its happy path test can still let one customer read another customer's invoice just by changing a number in the address. AI assistants write code quickly and confidently, so the habit of reviewing it for security matters more, not less, than when you wrote everything yourself.
Security review asks a different question from does it work. It asks what happens when the input, the identity or the order of events is not what we expected. The first distinction to get right is between authentication and authorisation. Authentication answers who you are. Authorisation answers what you may see or do, and it has to be checked on the server, for each record, every time. Hiding an identifier is not a boundary. The server must return only the records that belong to the signed-in account.
A short threat model keeps the review focused. Five questions are enough: what inputs does this accept, what protected data does it touch, which identity performs the action, where is the boundary enforced, and what happens with malformed or cross-account input. Answering them in a few sentences before reading the code turns a vague worry into specific things to check.
It also helps to know the shortcuts that weaken a boundary. Permissive settings make a demo work faster, which is exactly why generated code reaches for them, so look for them in every review. Building a database query by gluing strings together is dangerous because user input can add clauses the developer never intended, while parameterised queries keep data and query separate. Verbose error messages can reveal internals to an attacker, so show the user something helpful and keep the detail in the server log.
Why does generated code need this attention? Because an assistant optimises for the request you made, which is usually that the feature works. It rarely volunteers what could be abused, and it has no sense of the data your business is responsible for. Code that looks tidy and passes its examples can therefore carry a gap that a careful reader would notice in a minute. The remedy is a short, repeatable routine rather than a general feeling of caution: say what the code protects, say who may reach it, look for the convenient shortcuts and try to break it on purpose. A review of this kind takes minutes, while a leak of customer data can take months to repair and can damage trust that is hard to win back.
Reviewing is not the same as testing. A second model's opinion can catch things you missed, but only running the dangerous path shows whether the boundary actually holds. Write tests for abuse cases, which are requests that should be refused, and for malformed, oversized and wrong-type input, and check that they fail safely. This quiz has 10 questions on authentication and authorisation, fixing access to records, threat modelling, weakened boundaries, queries, error messages and abuse-case tests. Every answer is explained. It suits developers and reviewers who work with AI-written code.
Questions and answers
›How long does the quiz take?
About 3 to 4 minutes for 10 questions at roughly 20 seconds each, with a short explanation after every answer.
›Do I need to be a security specialist?
No, but some familiarity with web applications helps. The questions describe small scenarios and ask for the sound decision, and each answer is explained in plain words.
›What is the difference between authentication and authorisation?
Authentication checks who you are, for example by a login. Authorisation checks what that person may see or do. A route can pass the first test and fail the second, which is how users end up seeing each other's data. Authorisation must be checked on the server for every record.
›Why is hiding an identifier not enough?
An identifier can be guessed, copied or found in a link. If the server returns whatever record is requested without checking ownership, anyone who learns the identifier can read it. The real protection is a server check that the record belongs to the signed-in account.
›What is a threat model?
It is a short analysis of what could go wrong. A quick version asks what inputs the code accepts, what protected data it handles, which identity acts, where the boundary is enforced and what happens with malformed or cross-account input. It points your review at the places that matter.
›Why is building a SQL query by joining strings dangerous?
User input placed directly in the query text can change its meaning, adding conditions or commands the developer did not intend. Parameterised queries send the data separately from the query, so input is always treated as data and never as part of the command.
›Why is a second model's review not enough?
A review can find problems you overlooked, but it is another opinion, not proof. Only running the risky path with a test shows whether the boundary actually holds. Use reviews to find candidates and tests to confirm the fix.
›Why are detailed error messages a risk?
They can reveal internal details such as file paths, database structure or software versions, which help an attacker. A good practice is to show the user a clear, safe message and write the technical detail to a log that only the team can read.