To be 100% safe, use HTMLPurifier twice. Before storing HTML in DB and before its output to the screen.
A huge drawback of this solution is performance. HTMLPurifier is ultraslow when filtering HTML, and you may encounter a lot of processing time for your pages.
You should be fine if you only perform 1-2 filtering before displaying something on the screen, but if you do 10 filters for each request, as we did, we rather decide not to use HTMLPurifier when releasing a lot of texts .
HTMLPurifier took 60% of the processing time for each request, and we wanted to achieve less response time and higher UX.
It depends on your situation. If you can afford to use HTMLPurifier before release, go for it - thatβs better, and you always control the tags you want to allow (for new and even old content stored in your db).
michal kralik
source share