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.

In shortBuild dashboard queries with a fixed allowlist for dynamic sorting/filtering.

What's actually going on

Two different things, two different defensesIdentifiers(column/table names)Cannot be bound as parametersMust be checked against afixed allowlistValuesCan always be bound asparametersNever need an allowlist
Two different things, two different defenses

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.

LevelTime needed
Intermediate3-4 hours

What you need (tools and setup)

ToolWhat it isWhy you need itCost
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
GitVersion 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

Dynamic sort column validated against a fixed allowlistSQL: edit and run

'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

  1. List every column the dashboard should allow sorting/filtering on, and store that list as a fixed allowlist in code.
  2. 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.
  3. Build the final query by inserting only the allowlisted, validated identifier into the SQL text, with every value still bound as a parameter.
  4. Add the same allowlist check for any dynamic filter field.
  5. 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

CheckWhy it mattersHow to verify
Column allowlistIdentifiers cannot be bound as parameters, so they must be validated differentlyConfirm every dynamic identifier is checked against a fixed list
Rejection, not silent fallbackA rejected invalid column should error clearly, not default unexpectedlyTest an invalid column name explicitly
Values still boundAllowlisting identifiers doesn't replace binding valuesReview that filter values use bound parameters
Tip:Commit the insecure version and the fixed version as two separate commits, so the diff itself becomes a teaching example.

Test what you just read

1. A user-chosen sort column should be handled by...