Skip to content

Interview question · Application & API Security

What do SQL injection, command injection and template injection have in common, and why does parameterisation fix SQL injection?

Three bugs, one cause. The answer that scores names the cause, explains why parameters are structural, and lands on why prompts have no parameters.

easyEssentialNewPreparation tags: Amazon, Google, MetaUpdated Nov 2026

TL;DR: All three are untrusted data crossing into an interpreter in the same channel as code, so the interpreter parses part of the data as instructions. Parameterisation fixes SQL injection structurally: the database parses the statement before the values arrive, so values can never change the statement's shape. The equivalents elsewhere are argument arrays without a shell for commands and rendering data into fixed templates. Prompt injection belongs to the same class but has no parameter mechanism, which is why its defences focus on limiting impact.

How to approach it

Name the common cause in one sentence, then show the structural fix for each interpreter. Explain why parameterisation works at the level of parsing, contrast it with escaping, and finish with the connection to prompt injection.

A strong answer

FIG · INJECTION AS A CLASS · DATA IN THE CODE CHANNEL
Parameterisation separates the channels for SQL

String-built query

Query text + user value

one string

Parser reads value as code

structure changes

Also shell and templates

Outcome, unsafe: Injection

Same root cause everywhere

Parameterised query

Statement parsed first

placeholders only

Values bound later

never parsed

Structure fixed

Outcome, safe: Structurally safe

Values cannot become code

The common cause. An application builds input for an interpreter (SQL engine, shell, template engine) by combining its own code with data, and the boundary between them is decided by parsing that combined text. Data that contains the interpreter's syntax changes the code.

InterpreterVulnerable patternStructural fix
SQLf"... WHERE name = '{name}'"Placeholders: "... WHERE name = ?", values passed separately
Shellos.system(f"convert {path} out.png")subprocess.run(["convert", path, "out.png"]), no shell
Template engineTemplate(user_text).render()Template("Hello {{ name }}").render(name=user_text), sandboxed engine

Why parameterisation works. With a prepared statement, the database receives the SQL text with placeholders, parses and plans it, and only then binds values into the slots. The parse tree is fixed before any untrusted byte arrives, so a value containing ' OR '1'='1 is compared as a string literal. Escaping instead tries to transform data so it cannot break out of a context; it depends on the exact database, character set and context, and fails in places like numeric fields or identifiers.

Where parameters do not apply. Table and column names, sort directions and other identifiers cannot be placeholders. Map user choices to an allowlist of known identifiers in code.

Second layer. A least-privilege database account and no shell access for the application user limit what a missed injection can do.

The bridge to AI. A language model receives instructions and data as one token sequence with no parameter slot, so data can always act as instructions. That is why prompt injection defences focus on what the model can reach (scoped tools, authorization in code, output handling, egress control) rather than on making text inert. And model output fed into SQL or shells is untrusted input, so it gets the same parameterisation and argument-array treatment.

What interviewers probe next

  • "Do ORMs prevent SQL injection?" For their normal query builders, yes; raw query methods and string-built filters reintroduce it.
  • "How would you find injection in a codebase?" Search for string-built queries and shell calls, use static analysis rules, and review every sink that takes model or user output.
  • "Is stored procedure use a fix?" Only if the procedure itself does not build dynamic SQL from its parameters.

What if?

What if · interview follow-ups

Hold your answer as the constraints change

A search endpoint builds a SQL query by concatenating the user's search term into the WHERE clause, and the same team is adding an LLM feature that summarises results.

  1. Start here

    What do SQL, command and template injection have in common?

How it's scored

Weak: Lists the three bugs without a common cause, or recommends escaping as the primary fix.

Hire: Names the shared root cause and gives the structural fix per interpreter, explaining parse-before-bind.

Strong Hire: Covers identifiers and allowlists, least privilege as a second layer, and connects the class to prompt injection and model output correctly.

Common mistakes

  • Calling input validation alone a fix for SQL injection.
  • Using shell=True with "sanitised" strings.
  • Assuming ORMs make every query safe.
  • Claiming prompt injection can be fixed with escaping.
You just read a free answer. Every topic opens its first 5 answers to anyone. Sign in and the count per topic goes to 10, and we keep track of how far you get in every topic.Google sign-in · free · no payment details
HOW DID IT GO?
0
READING SIGNED OUT

Signing in doubles your free answers, from 5 to 10 per topic, and the site starts remembering you: mastery per topic, bookmarks, and a next-focus recommendation. Free, no card.

Sign in free
UP NEXT ON YOUR JOURNEY
DISCUSSION · 0

No comments yet. Share a correction or a different way to answer it.