Secure Coding & Release Discipline ยท Lesson 3 of 4
Input validation and parameterised queries
Study notesAbout 3 minutes. A full lesson with quick checks is on its way.
In short
Never build database queries by pasting in user input. Check input against what you expect, and use parameterised queries so it's only ever treated as data.
In your work
A search box on a client's member directory builds SQL by joining strings. Typing a quote mark breaks the page, a classic sign of SQL injection. You switch to a parameterised query and add input checks.
What the UK rules say
- UK GDPR requires appropriate security for personal data, which includes protecting databases against well-known attacks such as injection.
- OWASP's guidance is to use parameterised queries, so the database always treats input as data, never as code.
What to do
- Use parameterised queries or a safe ORM method for every query.
- Check input against what you expect: type, length and format.
- Never show raw database errors to users.
- Add tests that try quote marks and other special characters.
Watch out for
- Escaping input by hand instead of using parameters.
- Trusting input because it came from your own front end.
In your organisation
Which secure coding standard does your organisation follow, and is it checked in code review?
Your employer's own policies come first.
Sources
- ICO, A guide to data security (opens in a new tab), checked 6 October 2026.
- OWASP, SQL Injection Prevention Cheat Sheet (opens in a new tab), checked 6 October 2026.
UK law and guidance, explained for learning. Not legal advice.
