A Printable Planner for Making a Small App Injection-Proof

SQL injection is easy to prevent, but only if every query is checked. In a small app, you can list them all. This planner walks you through doing exactly that. Print it or copy the tables into a document.

Step 1: list every place data comes in

Anything a user, a file or another program can send to your app is an input.

InputWhere it appears (page, form, URL, file)Example value

Common inputs in a beginner app: login forms, search boxes, URL parts such as /posts/42, sorting choices, uploaded spreadsheets.

Step 2: list every query

Search your code for SQL keywords like SELECT, INSERT, UPDATE and DELETE, and for your ORM's raw SQL functions.

File and lineWhat the query doesInputs it uses

Step 3: check how each input reaches the query

For every row in Step 2, tick one box.

QueryPlaceholder or ORM filterAllow-listGlued into the string

Step 4: fix the glued ones

For each query marked "glued", write the fix:

QueryFix

Typical fixes:

# before
cur.execute("SELECT * FROM posts WHERE id = " + post_id)
# after
cur.execute("SELECT * FROM posts WHERE id = ?", (post_id,))

Step 5: test

TestResult
Type a single quote ' into each text input. Does the app show a database error?
Type ' OR '1'='1 into the login form on your practice copy. Does it log you in?
Try an unexpected sort value in the URL. Is it rejected or replaced by a default?

A database error message from a quote is a strong hint that something is glued. Only test your own app, on a practice copy.

Step 6: keep it fixed

Instructions

Work through the steps in order, in one sitting if possible. For a small app with a handful of pages, this usually takes an afternoon. Do not skip Step 1; queries are only dangerous because of the inputs that reach them.

For background, see SQL injection: short questions, plain answers and the comparison of five ways people try to stop SQL injection.

A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.