Parameterized vs concatenated queries
Build the same product search three ways and watch the token view: concatenation lets input change the query, bound parameters and allowlists keep it a value.
- Interactive lab
- Beginner
- 5 graded steps
- 0 of 5 solved
Your goal
Your goalChoose how the server builds each part of the query so no input can ever change its shape.
The product search on a shop sends three user inputs to the database: the search text, the sort column, and the page size. Today all three are glued into the SQL string.
For each input, choose how the server builds the query, type any value you like, and watch the token view. The query is safe when no input can change its shape. Nothing here runs against a real database.
What’s on screen
- Three inputs
- three panels: Search box, Sort column, and Page size. Each has buttons for how the server builds that part.
- Input value
- the text box in each panel, with Everyday inputs buttons under it. You can type anything.
- Token view
- the list under the query. It shows how the database splits the query into pieces, and the line below says whether the shape changed.
- Walkthrough
- the numbered path beside the workbench (below it on a phone). Each step says what to do and what you should see. Hints open one at a time.
Words to know
- SQL
- Structured Query Language, how programs ask a database for data
SELECT id, name, price FROM products WHERE name LIKE '%O'Brien%'
Unterminated string starting at character 64
ORDER BY price
ORDERkeywordBYkeywordpriceidentifier
The input stayed a single value. The query shape matches the template.
LIMIT 25
LIMITkeyword25number
The input stayed a single value. The query shape matches the template.
At least one input can still change the query or silently break it.
Read first
More in Web and API security
The whole walkthrough
Every step in order: 282 words, about 2 min. It gives away every answer, so try the steps first.