Study guide · XSS, Fluid and content security policy

Preventing XSS with Fluid, TypoScript and a content security policy

As of November 22, 2026 · TYPO3 14.3 LTS with Fluid 5 · about 22 min read

Cross-site scripting, XSS for short, is one of the most common holes in websites. An attacker gets their own JavaScript code into a page, and the victim's browser runs it. You learn how Fluid protects you by itself, how that protection gets bypassed and where TypoScript sets traps. After that comes the content security policy as a second layer, and foreign scripts. The running example is the website of a sports club with a guestbook and a search field.

What XSS is and what it does

With XSS, foreign code ends up in the HTML of your page. There are two basic forms:

  • With reflected XSS, the code is in the URL. The page sends it straight back in the response. So the victim must open a prepared link.
  • With stored XSS, the code is permanently on the server, for example in a guestbook entry. It hits everyone who opens the page.

The script runs in the victim's browser and uses their session. It can read data and CSRF tokens and perform actions on behalf of the victim, up to taking over the session. XSS does not directly change anything on the server, such as files or the database. But if the script hits an administrator, it can lead to a takeover of the whole installation through the admin's actions.

The cookie attribute HttpOnly only helps partly. It prevents a script from reading and stealing the session cookie through document.cookie. It does not close the hole. In the backend, for example, an injected script cannot read the cookie be_typo_user. But it can act on behalf of the logged-in user and read everything the backend displays. For the admin tools, TYPO3 also requires sudo mode, that is, entering the password again. The script does not know that password, and it does not know the Install Tool password either.

Fluid encodes by itself

When you output a variable in a Fluid template, such as the text of a guestbook entry, Fluid converts the HTML special characters. The angle bracket of a script tag becomes the entity for “less than”. The browser displays the text instead of running it. This automatic encoding is the most important protection against XSS. So the rule is: use the default output with escaping.

In Fluid 5, escaping does not depend on the file extension. The escape interceptor is always active, also in a mail template ending in txt or in a JSON output. You can only switch it off on purpose: for a single element with the ViewHelper f:format.raw, or for a whole template with an instruction at the very beginning.

{escaping off}
Code example. The first line of a template switches off escaping for the whole template with the instruction escaping off in curly braces.

That only makes sense if no value from an unsafe source ends up in the template. A JSON template with this line outputs all variables raw, including user input. Then you must correctly JSON-encode every value yourself. If the server also delivers the response with the wrong content type text/html, the browser interprets it as HTML. Injected markup then still takes effect.

Raw output and safe alternatives

The ViewHelper f:format.raw outputs content without any encoding. It must never receive user input, so nothing from forms, URLs or foreign sources. Only output raw HTML if it comes from a trusted source or has been sanitised beforehand. For the two typical cases there are safe ways:

  • HTML from the rich text editor is output with f:format.html. The ViewHelper passes the content through parseFunc, by default through lib.parseFunc_RTE. Along the way, TYPO3 resolves internal links with the t3 scheme and filters unwanted markup.
  • Other HTML with allowed formatting is output with f:sanitize.html. It filters the HTML with the package typo3/html-sanitizer. Only allowed tags, attributes and values remain. An attribute such as onmouseover is dropped.

By default, the class DefaultSanitizerBuilder in the namespace TYPO3, CMS, Core, Html defines which tags and attributes are allowed. With the option build you specify a custom builder, for example for additional allowed tags.

parseFunc protects as well: the setting htmlSanitize is active in TYPO3 14 unless something else is set. Setting it to 0 switches off the sanitizer.

If a template outputs the bodytext of a content element with f:format.raw instead of f:format.html, it bypasses parseFunc's HTML sanitizer. Injected scripts end up on the page unchecked, and internal links with the t3 scheme stay unresolved.

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. Custom ViewHelpers and the output context
  2. Traps in TypoScript
  3. Content security policy: the second layer
  4. Directives and mutations
  5. Nonces and hashes
  6. Reporting and evaluating violations
  7. Foreign scripts and further headers
  8. Key points

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

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

Sources:

  • TYPO3 Explained 14.3, chapter Security (guidelines for integrators, extension developers and administrators)
  • TYPO3 Explained 14.3, chapter Content Security Policy
  • TypoScript Reference 14.3, stdWrap (htmlSpecialChars, insertData), getData, parseFunc and page.includeJS
  • Fluid ViewHelper Reference 14.3 (f:format.raw, f:format.html, f:sanitize.html, f:security.nonce, f:asset.script)
  • Changelog TYPO3 14.2, Feature 100887 (hash values instead of nonces) and Feature 109187 (Subresource Integrity)
  • TYPO3 Security Advisory TYPO3-CORE-SA-2023-001 (CVE-2023-24814)
  • Source code TYPO3 14.3 and Fluid 5, checked for escaping independent of the file extension

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