Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sanitize a string without losing HTML and removing JS /SQL

I am using Rich Text Editor for accepting input data which has HTML content from client side.

On the server side, I am using PHP based server and sanitize the incoming data.

Is there a builtin PHP functionality, which retains the HTML code and removes the presence of Javascript for XSS + SQL injection codes.

like image 367
Faiz Mohamed Haneef Avatar asked Dec 11 '22 22:12

Faiz Mohamed Haneef


1 Answers

As far as I know, there is no existence of such a built in functionality.

The sanitize filters from http://php.net/manual/en/filter.filters.sanitize.php doesn't look to cover your request. You may take a look at http://php.net/manual/en/book.filter.php, but no filter is there set to filter HTML.

I know you don't ask for an external library, but this is the one I think that may help you with the issue you're facing: http://htmlpurifier.org/

like image 199
Federico J. Avatar answered Dec 28 '22 09:12

Federico J.