开发者

PHP XSS Prevention WhiteListing

开发者 https://www.devze.com 2023-01-03 03:05 出处:网络
My site utilizes a WYSIWYG editor for users to update their accounts,enter comments, and send private messages.

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 othe开发者_如何学Gor 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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消