I have a utf8mb4 database field which has ended up with htmlspecials such as 's
This is from user entered data via a html form. To display this field in laravel blade I use {{ $profile }}
but that runs through phps htmlspecialschars feature to prevent xss attack (https://laravel.com/docs/6.x/blade#displaying-data) and so the output I get is 's
I know I can display it as unescaped data using {!! $profile !!}
but since this is user entered data there's a risk anything could get output.
Whats the best way to approach this. Is there a way to clean it up at the database layer without losing or corrupting the data. Or is there a better technique at the presentation layer whilst avoiding XSS risks?
Note this is data from a legacy database.
Any help appreciated.
* UPDATE *
I tried using this htmlpurify package: https://github.com/stevebauman/purify
which seems to do the trick similar to using htmlspecialchars($value, ENT_QUOTES,'UTF-8',true);
e.g:
{{ Purify::clean($value) }} or {{ htmlspecialchars($value, ENT_QUOTES,'UTF-8',true) }}
However if I have something like the following in the database:
Jobs & Work
Then using htmlpurify or htmlspecialchars as in the example above still ends up as:
Jobs & Work