Untrusted input
A web app has three parts. The browser shows pages and sends requests. The app is code on a server that answers them. The database stores the data. This app lets visitors search its member list by name.
Anything that arrives from the browser is untrusted input: form fields, links, cookies and headers. Anyone can send anything. Here a real visitor, O'Brien, types her own name into the search box. Its apostrophe is about to matter.
Injection: mistake and fix
Line 6 builds the query by gluing the name into the SQL text, between quote marks. The app sends one string, and the database has to work out for itself which part is code and which part is data.
The apostrophe ends the quoted text early, so the database reads Brien' as SQL code and stops with a syntax error. Here that is only an error, but the same mistake lets crafted input change what a query does: SQL injection.
Line 7 sends the query with a ? placeholder, and the name separately as a value. The database settles the code first, then fills in the value as data only, whatever it contains. OWASP and CISA name this the main fix.
Output, access and design
The page shows the name back. Pasting input into HTML raw is the same mistake: input could become page code, called cross-site scripting. html.escape turns ' into ' and < into <, so the browser shows plain text.
Another common mistake is trusting the browser to hide what a user may not see. Anyone can edit a request, say to ask for someone else's order. So the server checks permission on every request and refuses: 403 Forbidden.
OWASP's Top 10 for 2025 ranks broken access control first and injection fifth. CISA asks makers to remove whole classes of flaws, with parameters and escaping as the default. NIST's SSDF adds code review and testing.
What happens
;; step 1/8 · parts browser shows pages, sends requests web app code on a server (Python here) database stores the data (SQLite here) example search members.example by name
The row is a picture of the idea, not of how SQLite really parses: the database splits the whole text into tokens. What it shows is true: with glued text, part of the name ends up outside the quotes and is read as SQL. Real apps seldom call html.escape by hand: template engines such as Jinja2 and frameworks such as Django escape output by default, and database libraries make parameters easy. CISA asks for exactly that: safe by default.