PHP XSS Prevention WhiteListing

天大地大妈咪最大 提交于 2019-12-11 02:08:53

问题


My site utilizes a WYSIWYG editor for users to update their accounts,enter comments, and send private messages.

The editor (CKEditor) is great for only allowing users to enter valid input, but I worry about injection through TamperData or other means.

How can I control this on the server side?

I need to whitelist specific tags: <b><ul><ol><a><img><br>, will this be a SAFE approach to preventing XSS?


回答1:


Use HTML Purifier:

HTML Purifier is a standards-compliant HTML filter library written in PHP. HTML Purifier will not only remove all malicious code (better known as XSS) with a thoroughly audited, secure yet permissive whitelist.




回答2:


strip_tags is going to be your friend. The second parameter lets you pass in an array of allowed tags strip_tags



来源:https://stackoverflow.com/questions/2992674/php-xss-prevention-whitelisting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!