Home / Learn Secure SQL / Project: Secure Search Feature
Project: Secure Search Feature
Build a product search box without string-built queries.
How to think about this
The basic idea
A search feature: users type a keyword, and the app returns matching products, built entirely with bound parameters and a bounded LIKE pattern, never by inserting the keyword into the SQL text.
Why this comes up
Real projects are where secure patterns become habits instead of theory.
The mechanics
Work through the steps in order; do not skip the checklist.
Where it is used
- Portfolio project
- Code review practice
- Interview preparation
What you will build
A search feature: users type a keyword, and the app returns matching products, built entirely with bound parameters and a bounded LIKE pattern, never by inserting the keyword into the SQL text.
| Level | Time needed |
|---|---|
| Beginner | 2-3 hours |
What you need (tools and setup)
| Tool | What it is | Why you need it | Cost |
|---|---|---|---|
| Code editor (VS Code or similar) | The program you write code in. | You need somewhere to write and run the example app. | free |
| A language runtime (Node.js, Python, PHP or similar) | Installs the interpreter so your code can run on your computer. | The project examples run as small scripts. | free |
| SQLite (bundled, no install needed) | A tiny file-based database engine. | Every project in this course can be tried with SQLite first, with zero setup. | free |
| Git | Version control: tracks every change you make. | Lets you compare the insecure version and the fixed version of the code. | free |
Step 1: see the problem and the fix in the sandbox
The %Widget% pattern here stands in for a bound parameter whose value is built from the user's keyword plus wildcard characters in application code, never by formatting the keyword directly into the SQL text.
Step by step
- Create a products table and seed it with sample rows.
- Write the search query using a bound LIKE parameter, building the %keyword% pattern in application code before binding it.
- Add an ESCAPE clause and escape any literal % or _ characters in the user's keyword, so a search for a literal percent sign works correctly.
- Add LIMIT and pagination so a very broad search cannot return the entire table at once.
- Write a test that searches for a keyword containing a literal % and confirms it matches only literal percent signs, not a wildcard.
Security checklist before you ship it
| Check | Why it matters | How to verify |
|---|---|---|
| Bound LIKE parameter | Prevents unsafe string-built queries | Review the query-building code for any direct string formatting |
| Wildcard escaping | A literal % or _ in user input should not act as a wildcard | Test a search term containing a literal % character |
| Result limiting | Prevents one query from returning unbounded rows | Confirm LIMIT and pagination are present |
Quick check
1. Where should the %...% wildcard be added to a search keyword?
Build the pattern in code, then bind it as a single value.