Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

Input validation and output escaping

Treat every input as untrusted and every output as needing escape - casting and allow lists in PHP, validating view parameters and posts, wash in templates for HTML and attributes, URLs, JSON and SQL, and the common…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/creators/app-creators/input-validation-and-escaping.md

On this page

Input validation and output escaping

This page is for application creators who handle data from requests, imports or APIs. Two rules prevent most security bugs: validate input where it enters, escape output where it leaves, in the format of the place it goes.

Contents

  1. Validating input
  2. Escaping output
  3. Contexts and their escaping
  4. Common mistakes

Validating input

InputValidate
IDs and numbers(int), then a range check (max( 1, min( 100, (int)$limit ) ))
Choicesan allow list: in_array( $sort, array( 'name', 'published' ), true )
Textlength limits, trim, the characters allowed for the field
E-mail, URLthe datatype or filter_var() validation; for URLs also the scheme (https only)
Filestype by content and size, stored through the kernel
Redirect targetsonly addresses of the site (Safe redirects)

View parameters ($Params) and unordered parameters are strings from the address, as untrusted as POST data.

Escaping output

In templates, every value from users or the database goes through |wash:

<h1>{$item.title|wash}</h1>
<a href={$item.url|ezurl} title="{$item.title|wash}">...</a>
<div data-conf="{json_encode( hash( 'id', $item.id ) )|wash}"></div>

Exceptions are values that are already safe HTML by design: $module_result.content, the output of attribute_view_gui and of rich text rendering.

Contexts and their escaping

Output goes intoEscape with
HTML text and attributes|wash (templates), htmlspecialchars( $v, ENT_QUOTES, 'UTF-8' ) (PHP)
URLs in templates|ezurl for site paths; rawurlencode() for parts of a URL (Templates and design, part 10)
JSONjson_encode(); inside a <script type="application/json"> also replace < and >
SQLcasts and $db->escapeString(), or eZPersistentObject conditions
Shell commandsavoid; otherwise escapeshellarg()
CSV for spreadsheetsprefix values starting with =, +, -, @ (the kernel's CSV export does)
Log linesstrip line breaks; never log secrets

Common mistakes

  • {$value} without |wash because "it is only a number": a later change makes it text.
  • Trusting a hidden form field.
  • Building a redirect from $_SERVER['HTTP_REFERER'].
  • Escaping on input instead of on output (double escaping, or none in a new output).
  • A JSON value printed into an inline script: use a data block or attribute instead.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x