# Data Sanitization

The `Sanitize` class is deprecated as of 2.4 and does not exist in CakePHP 3.0
and later. Instead of using the Sanitize class you can accomplish the same tasks using
other parts of CakePHP, native PHP functions, or other libraries.

## Input filtering

Instead of using the destructive input filtering features of Sanitize class you
should instead apply more thorough [Data Validation](https://pieceofcake2.github.io/docs/models/data-validation.md) to the user
data your application accepts. By rejecting invalid input you can often remove the
need to destructively modify user data. You might also want to look at
[PHP's filter extension](https://www.php.net/filter) in situations you need to
modify user input.

## Accepting user submitted HTML

Often input filtering is used when accepting user-submitted HTML. Instead,
escape output with `h()` and pass user-submitted HTML through a maintained HTML
sanitizer, such as Symfony HtmlSanitizer or HTML Purifier. See
[Output Escaping and HTML Sanitization](https://pieceofcake2.github.io/docs/security/escaping-and-sanitizing-html.md).

## SQL Escaping

CakePHP handles SQL escaping on associated array values provided to
`Model::find()` and `Model::save()`. In the rare case you
need to construct SQL by hand using user input you should use
[Prepared Statements](https://pieceofcake2.github.io/docs/models/retrieving-your-data.md#prepared-statements).
