Home / Learn Secure SQL / Project: Secure Comments and Reviews Feature

Project: Secure Comments and Reviews Feature

Store user-submitted text safely and display it safely.

In shortStore user-submitted text safely and display it safely.

What's actually going on

Comment text pathfree text submittedbound-parameterinsert (storage…stored exactly assubmittedHTML-escaped atrender time (display…
Comment text path

Definition

A comments/reviews feature accepts free-text content from users, stores it with a bound parameter, and associates it with an author and a target item — the project also covers safe display of that stored text later (output encoding, covered in the input-validation group, applies when rendering it as HTML).

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

A comments/reviews feature accepts free-text content from users, stores it with a bound parameter, and associates it with an author and a target item — the project also covers safe display of that stored text later (output encoding, covered in the input-validation group, applies when rendering it as HTML).

LevelTime needed
Beginner2-3 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

Step 1: see the problem and the fix in the sandbox

Comment storage with bound text and length validationSQL: edit and run

The comment body is bound as a single parameter regardless of its content (quotes, punctuation, or anything else); a SQL string is only ever at risk when a value is concatenated into SQL text instead of bound.

Step by step

  1. Create a comments table with a bound-parameter insert for the body text.
  2. Enforce a maximum length on the body in application code before insert, to keep storage and queries predictable.
  3. Write the listing query scoped to item_id with a bound parameter and a LIMIT.
  4. Note (in comments or docs) that when this stored text is later rendered as HTML, it must be output-encoded at render time — a separate concern from how it is stored.
  5. Write a test inserting a comment body containing quotes and SQL-special characters, and confirm it stores and retrieves exactly as submitted.

Security checklist before you ship it

CheckWhy it mattersHow to verify
Bound insertKeeps arbitrary text safe regardless of its punctuationConfirm the insert uses a bound parameter, not string building
Length limitKeeps storage and display predictableTest submitting an overlong body is rejected or truncated as designed
Output encoding at render timeStorage safety and display safety are separate concernsConfirm the rendering layer escapes stored text as HTML
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. Storage safety and display safety for stored text are...