liveBook · Manning

SQL injection

As explained in Grokking Software Architecture

SQL injection is an attack technique that inserts crafted input into an application's SQL statements to alter database operations or access data without authorization.

SQL injection occurs when an application treats user input as part of an SQL command instead of as data. An attacker can then alter database operations or access, change, or destroy data. section 8.3.1 section 8.10

When a name becomes a command

In the “Little Bobby Tables” story, a malicious first name contains SQL intended to delete a student database. Poorly written software executes the input as a command rather than saving it as a name. section 8.7

Prevent this by using parameterized queries: give user input a data slot so the database treats even command-like text as a literal value. Avoid concatenating input into query strings, including for internal-facing applications. section 8.7.2

// SAFE: The database treats the input as a harmless string
string query = "SELECT * FROM Students WHERE Name = @Name";
command.Parameters.AddWithValue("@Name", userName);

A parameterized student-name query demonstrates the safe pattern: the input is supplied separately from the SQL command. section 8.7.2

How Grokking Software Architecture covers it

How deep it goes
Explains how input becomes executable SQL and contrasts unsafe concatenation with parameterization, without detailing broader exploit mechanics.
Examples
Uses the Little Bobby Tables attack and a teleprompter analogy to illustrate unsafe input and its safe treatment.
What you can do after
Apply it via parameterized queries that treat user input as data rather than executable SQL.
How it connects
Connects SQL injection to parameterized queries, trust boundaries, and defense in depth.

Also explained in

Compare how 12 books explain SQL injection →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.