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.
What's actually going on
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).
| 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 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
- Create a comments table with a bound-parameter insert for the body text.
- Enforce a maximum length on the body in application code before insert, to keep storage and queries predictable.
- Write the listing query scoped to item_id with a bound parameter and a LIMIT.
- 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.
- 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
| Check | Why it matters | How to verify |
|---|---|---|
| Bound insert | Keeps arbitrary text safe regardless of its punctuation | Confirm the insert uses a bound parameter, not string building |
| Length limit | Keeps storage and display predictable | Test submitting an overlong body is rejected or truncated as designed |
| Output encoding at render time | Storage safety and display safety are separate concerns | Confirm the rendering layer escapes stored text as HTML |
Test what you just read
1. Storage safety and display safety for stored text are...
Binding protects storage; escaping protects display.