I want to safely display a text coming from the user (by blocking scripts tags), but I need to accept html markups (b, p, li, ul, etc.).
It’s need to be bullet proof against cross-site scripting attack.
Thank you!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you have a simple tag whitelist and you don’t need to worry about attacks at or below the encoding level (as is the case from within browser-side JavaScript), you can do the following:
which can be used like
If you need more configurability, like the ability to allow attributes on tags, see the Caja HTML sanitizer.
As others have pointed out, your server should not trust the result coming from the client so you should re-sanitize on the server before embedding the result into server-generated markup.