GCSE · Computer Science · Eduqas · Spec C500QS

SQL injection

You press enter on a search box and a database gets asked a question. Who wrote that question: the programmer, or you?

Computer Science · Cybersecurity

Same typed text, very different endings

Start with text typed into the box. Choose a branch at each fork to see how the system's design decides the ending.

Is the input checked? → How is the query built? → Database account rights → What the commands are used for

6 possible endings.

On Text typed into a login or search box. 2 branches to choose from.

Follow text typed into a box through the system. At each fork, pick the design condition and see where it ends up.

Exam line: Name the design condition before the outcome: input not checked and placed directly into the query leads to commands being run; a parameterised query keeps input as data.
Watch out: Least privilege does not appear on the 'stopped' branches. It only shrinks the damage once commands have already run.

Computer Science · Databases

How a search box builds a query

A harmless search, step by step. Watch where the typed word ends up.

A shopper types Mug into a shop's search box. What does the database actually receive?

SELECT name, price
FROM Product
WHERE name = 'Mug'

Result

nameprice
(no rows yet)

Output

 

Step 1: The programmer wrote the start of the query text: SELECT name, price FROM Product WHERE name = and then the system waits for what the shopper types.

1 / 5

Step through with Next and watch the typed word join the fixed query text.

Step 1 of 5: The programmer wrote the start of the query text: SELECT name, price FROM Product WHERE name = and then the system waits for what the shopper types..

Exam line: The system builds its own SQL query using what the user typed, then sends the finished query to the database.
Watch out: This is normal use with a harmless word. The steps are authored; the page does not run the query.

Why injection works

?

Reason it through

Why can text typed into a box make a database run commands?

Link 1 of 4

First link · your turn

A poorly built system takes what you typed. Where does it put that text?

2
Locked — reveal the link above first
3
Locked — reveal the link above first
4
Locked — reveal the link above first

Computer Science · Defences

Three defences, compared

For each defence, tick every property that is true of it, then check your grid.

Input checking
Parameterised queries
Least privilege

Exam line: Parameterised queries prevent it, input checking helps, and least privilege limits the damage if one succeeds.

Computer Science · Cybersecurity

Which idea is closest to yours?

Four students are talking about SQL injection after a lesson.

Which of these is closest to what you think right now?
How sure are you?

Exam line: SQL injection works because the system's own query is built from untrusted typed text.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

How text typed into a box can end up as part of a database query, and the design choices that stop it

What you need to know

  • SQL is a language for searching, adding, changing and deleting data held in a database.
  • Lots of sites build an SQL query from what you type: a login's username and password boxes, or a search box.
  • Have a goSam says: "The word I type in a search box is just something to look for. It never goes anywhere near SQL." What is Sam missing?

    Many sites build an SQL query out of what you type.

    Sam treats the typed text as only a word to look for, but the site uses it to build the query it sends to the database.

  • SQL injection is a cybersecurity threat. The attacker types SQL commands into an input box instead of the expected data.
  • Those commands then become part of the query the system sends to its database.
  • It works when a poorly built system puts typed input straight into the query without checking it.
  • The database can't tell the attacker's commands from the intended query, so it runs them.
  • Have a goA system pastes typed input into its query and checks nothing. Why does the database run an attacker's commands instead of ignoring them?

    It can't tell them apart from the intended query.

    The commands sit inside the query it was sent, so nothing marks them as typed by someone else.

  • A successful attack can expose data, change or delete data, or get past a login without a valid password.
  • Input checking (validation and sanitisation) helps: it checks input first and rejects or removes what doesn't match what's expected.
  • Parameterised queries (prepared statements) prevent it: the query's structure is fixed in advance and input goes in only as data.
  • Have a goInput checking, parameterised queries, least privilege: which one passes input in only as data, so it is never run as a command?

    Parameterised queries.

    Input checking helps by rejecting or removing input, and least privilege only limits the damage. Only parameterised queries fix the query's structure in advance.

  • Least privilege means the database account has only the rights it needs, which limits how much a successful attack could expose or change.

The big picture

SQL injection happens when a poorly built system puts what a user types straight into its own SQL query without checking it, so typed commands become part of the query and the database runs them. A successful attack can expose data, change or delete data, or get past a login. Parameterised queries prevent it, input checking helps, and least privilege limits the damage.

Key points

1SQL injection is typed text becoming part of the system's own query, so the weakness is in how the system was built.
2It works because input goes straight into the query unchecked, so the database can't tell the commands from the intended query and runs them.
3A successful attack can expose data, change or delete data, or get past a login.
4Parameterised queries prevent it, input checking helps, and least privilege only limits the damage.

Worked example

Problem

A school builds a login page. The developer (A) puts what the user types straight into the SQL query, (B) adds no input checking, and (C) lets the page use a database account with every right in the database. Which of A, B and C make an SQL injection possible, which make it worse, and what fixes each?

⚠ Watch out

Saying least privilege stops SQL injection. It doesn't stop the commands running; it only limits how much data a successful attack could expose or change. Parameterised queries are the defence that keeps input as data.

🧠

Memory hook

Fix the query, check the input, shrink the rights: parameterised queries prevent it, input checking helps, and least privilege limits the damage.

✓

Check yourself

Why can text typed into a search box end up run as database commands? Name the design choice behind it and the defence that keeps input as data.

Flashcards

(12)
What is SQL used for?
Searching for, adding, changing and deleting data held in a database.
Name two places where a site might build an SQL query from typed input.
A login form's username and password boxes, and a search box.
What is SQL injection?
A cybersecurity threat where an attacker types SQL commands into an input box instead of the expected data, so the commands become part of the query the system sends to its database.
When does SQL injection succeed?
When a poorly built system places user input directly into an SQL query without checking it, so the database can't tell the commands from the intended query and runs them.
Name three things a successful SQL injection can do.
Expose data the attacker shouldn't see, change or delete stored data, and get past a login without a valid password.
What data might a successful injection expose?
Other users' personal details or stored passwords.
What are the two parts of input checking?
Validation and sanitisation. The system checks input before using it and rejects or removes input that doesn't match what's expected.
What is a parameterised query (prepared statement)?
A safer coding method where the query's structure is fixed in advance and the user's input is passed in only as data.
In SQL injection, who actually builds the query that gets abused?
The system itself. The weakness is that typed text is allowed to become part of its own query.
What is least privilege?
Giving the application's database account only the access rights it needs.
Does least privilege stop an SQL injection happening?
No. It limits how much data an injection could expose or change if one succeeded.
Is SQL injection a virus or a network break-in?
Neither. It is a threat where typed SQL commands become part of the system's own query.

Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.

Learning with Lightbulb is opening soon

You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.

Keep me posted

More Eduqas GCSE Computer Science topics

See the full Eduqas Computer Science curriculum →

How this lesson was checked. This Eduqas GCSE Computer Science (specification C500QS)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 16 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.