How can typing a quote mark into a login box break a website?
A website once trusted a stranger's typing so much that the typing became part of its own instructions.
▶ Start the storyA quote mark can break a website because many sites build their questions by gluing text together, and a quote mark is the character that tells the database where a piece of text ends. If a stranger's typing is glued straight into the question, the stranger gets to decide where the text stops, and anything after that point is read as instructions. This is called SQL injection.
Here is the idea without any code. A login page might ask its something like: find the person whose name is, then it pastes in whatever you typed, then finishes the sentence. The programmer imagined you would type a name. The database cannot tell the difference between the parts the programmer wrote and the part you typed, because it receives it all as one long sentence. SQL statements mix data with commands, and that mixing is the weakness. When specially crafted input leaves the data zone and enters the command zone, the attacker can change what the question means.
The damage can be large. Attackers can pretend to be someone else, change or destroy stored data, read everything in the , or even become of the database server. In 2009 US prosecutors charged three people with stealing 130 million credit card numbers using this technique. In 2015 it was used to steal the details of 156,959 customers of the British telecom company TalkTalk through an old web page.
The cure is old and simple: never let typed text become part of the instructions. Programmers send the question and the typed value separately, using , so the treats whatever you type purely as a value, however strange it looks. It is so well known that a famous comic made the flaw a joke, and people still call it Bobby Tables.
Glued together (unsafe)
- Question and typed text become one long sentence
- The cannot tell data from commands
- Crafted input can change what the question means
With placeholders (safe)
- Question is sent with an empty slot
- Typed value is passed separately as plain data
- Strange input is just a strange value
1998
Discussed in an article in Phrack Magazine
2009
Charges over the theft of 130 million card numbers
2013
Ranked the most critical web vulnerability by
2015
156,959 TalkTalk customers' details stolen via a legacy portal
Quiz me
0/3
Recap
Never glue what a stranger typed into your instructions: send the command and the value separately with placeholders.
💡 A trick to remember it · Fill-in-the-blank, not copy-and-paste: a form with a blank for the name, never a note that anyone can scribble orders onto.
Surprising fact · A 2009 case charged three people with stealing 130 million credit card numbers using SQL injection.
Sources (2)
No source, no claim. Every fact in this lesson (18 claims) cites at least one of these.