Home / Learn Secure SQL / Project: Secure Admin Dashboard Queries
Project: Secure Admin Dashboard Queries
Build dashboard queries with a fixed allowlist for dynamic sorting/filtering.
What's actually going on
Definition
An admin dashboard that lets a user choose a sort column and a filter field from dropdowns; the project builds the query so the chosen column name is checked against a fixed allowlist rather than inserted into the SQL text directly.
Why you need this
Real projects are where secure patterns become habits instead of theory.
How it works
Work through the steps in order; do not skip the checklist.
Where you'll see this
- Portfolio project
- Code review practice
- Interview preparation
What you will build
An admin dashboard that lets a user choose a sort column and a filter field from dropdowns; the project builds the query so the chosen column name is checked against a fixed allowlist rather than inserted into the SQL text directly.
| Level | Time needed |
|---|---|
| Intermediate | 3-4 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 |
| A static analysis tool (e.g. Semgrep, Bandit, PHPStan, ESLint security plugin) | Scans source code for risky patterns automatically. | Catches a risky query before it reaches code review. | free tier available |
Step 1: see the problem and the fix in the sandbox
'total' here is one of a small, fixed set of allowed sort columns checked in application code; a column name requested by the user that is not on that allowlist is rejected before the query is built, never inserted as-is.
Step by step
- List every column the dashboard should allow sorting/filtering on, and store that list as a fixed allowlist in code.
- When a request names a sort column, look it up in the allowlist and reject the request if it is not present, rather than passing the name through.
- Build the final query by inserting only the allowlisted, validated identifier into the SQL text, with every value still bound as a parameter.
- Add the same allowlist check for any dynamic filter field.
- Write a test that submits a sort column not on the allowlist and asserts the request is rejected, not silently ignored or passed through.
Security checklist before you ship it
| Check | Why it matters | How to verify |
|---|---|---|
| Column allowlist | Identifiers cannot be bound as parameters, so they must be validated differently | Confirm every dynamic identifier is checked against a fixed list |
| Rejection, not silent fallback | A rejected invalid column should error clearly, not default unexpectedly | Test an invalid column name explicitly |
| Values still bound | Allowlisting identifiers doesn't replace binding values | Review that filter values use bound parameters |
Test what you just read
1. A user-chosen sort column should be handled by...
Identifiers need an allowlist, not parameter binding.