Study guide · SQL injection and template injection

Data stays data: SQL injection and template injection in TYPO3

As of November 22, 2026 · TYPO3 14.3 LTS · about 20 min read

Injection is one of the oldest and most dangerous holes on the web. On this page you learn how SQL injection and server-side template injection arise, how an attacker finds and exploits them, and how to prevent them cleanly in TYPO3. At the end you also know their relatives, command injection and object injection.

The core: keep data and code apart

Every injection has the same cause. Input ends up in a place where a program reads it not as a value but as an instruction. In SQL injection that place is the SQL string of a database query. In template injection it is the source of a template. In command injection it is a shell command.

That is why there is one shared principle: input goes in as data, never as code. In SQL you achieve this with bound parameters. In a template you pass user values as variables. Both separate the data from the executable part.

Everything the client sends counts as unsafe. That includes GET and POST parameters, cookies and HTTP headers. Constants from your own versioned code and fixed values from the extension configuration, on the other hand, are controlled by you as the operator.

The example on this page is an extension for events. It has a search, a sortable list, and it sends confirmation mails to visitors who register.

How SQL injection arises

SQL injection arises when you concatenate input into the SQL string. Then an attacker can close the text literal with a single quote and append SQL of their own.

$sql = "SELECT * FROM tx_myevents_event WHERE title LIKE '%" . $q . "%'";
Unsafe code. The search term from the request is put straight into the SQL string with the dot operator, right between two single quotes.

A prepared statement works differently. The database first receives the structure of the query with placeholders. The values arrive separately afterwards. So a value can no longer change the structure. A quote then simply stays a character in the search term.

Concatenation Parameter Input ' UNION SELECT … One SQL string … LIKE '%' UNION SELECT … --%' Database Runs foreign SQL Input ' UNION SELECT … Query LIKE :q Value just text Database Searches for the text Sent separately, the value cannot change the query.
Concatenation versus bound parameter.

Neither addslashes nor htmlspecialchars is reliable protection. The first function does not know the character set of the connection. The second one encodes for HTML, not for SQL.

How an attacker proceeds

The first test is often a single quote in the search field. If the query aborts with an SQL error, the input is evidently being inserted into the SQL string. If the page even shows the error message, it reveals tables and queries. With that the attacker works out the number of columns, for example. That is why SQL errors on the live site belong in the log and not in the output.

If the results appear on the page, for example in a search, the attacker uses UNION SELECT. UNION combines two result sets. This lets them append rows of a foreign table to the visible list. The appended query must return the same number of columns as the original, and the types must match. Otherwise the database aborts.

' UNION SELECT username, password FROM be_users --
A typical input for the search field. A quote closes the literal, UNION SELECT reads user name and password from the table be_users, and two dashes at the end turn the rest into a comment.

The two dashes at the end start an SQL comment. So the rest of the original query no longer gets in the way, for example a closing quote. The injected query stays valid. Bound parameters prevent this attack. The input then stays a value and cannot append a second query.

A popular target is the table be_users. It contains the user names and password hashes of the backend logins. Hashes cannot be reversed, but weak passwords can be cracked offline.

If the page shows no results, the attacker turns to blind SQL injection. They ask yes or no questions and conclude the answer from the behaviour of the page. In the time-based variant they delay the query only when a condition is true. If a search page always shows the same message but responds measurably slower to certain inputs, that is a clear warning sign. The input influences the query. Data can be read this way bit by bit, more slowly, but just as dangerously.

What an injection can do in the worst case depends on the query and on the rights of the database user. In a SELECT the attacker can usually only read. With further options they can change and delete data, create admin accounts or access files.

Read on

You can read the introduction and the first 3 of 11 sections here for free. There are two ways to get the whole learning page:

Free with a confirmed e-mail address

Sign up with your e-mail address and confirm it. You can then unlock the learning pages of one set of your choice completely, once, in the browser or in the app.

Unlock for free

Buy the course

The course includes all its questions and the whole learning page.

View the course
These 8 sections are still missing
  1. Querying safely with the QueryBuilder
  2. Restrictions and Extbase repositories
  3. SQL in TypoScript
  4. Limiting the damage
  5. Template injection in Fluid
  6. When user data becomes configuration
  7. Command injection and unsafe deserialisation
  8. Key points

Qwissit is also available as an app for iPhone and Android:

As of: November 22, 2026 (TYPO3 14.3 LTS)

Sources:

  • TYPO3 Explained 14.3, chapters Security Guidelines for Extension Development and Types of Security Threats
  • TYPO3 Explained 14.3, chapter Database (Doctrine DBAL), QueryBuilder, Restrictions and Connection
  • TypoScript Reference 14.3, content object CONTENT and function select with markers
  • Source code TYPO3 14.3 (typo3/cms-core), DefaultRestrictionContainer and Connection parameter types
  • TYPO3-CORE-SA-2022-015 (CVE-2022-23503), Arbitrary Code Execution via Form Framework
  • OWASP Top 10 2025, category A05 Injection
  • PHP manual, functions unserialize and escapeshellarg

This study guide was written with AI and compared with the sources.

Certifications & exams

Which exam comes next?

You can already practise for 60 exams, and 7 are up for a vote. See all certifications with their official information, cast your vote or suggest your exam.

See all certifications