![]() |
Clean User Input HTML using HTML::Scrubber
Most modern day websites take inputs from user in the form of comments, reviews, PMs etc. and it's needed to control the HTML tags in the users' content to prevent XSS attacks, spamming with URLs, embedding videos - which might attract copyright problems - and similar problems. Many sites list some allowed HTML tags which can be used, and strip out the rest or show an error message to the user.
It's best to strip out the tags because many users may not be aware of the tags present or may not know how to fix them. In this article we'll explore the Perl module HTML::Scrubber which is highly configurable and we'll use it to strip unwanted HTML tags, write validation rules to strip tags based on certain conditions. Basic UsageIn the following code example we'll see the basic usage of HTML scrubber, we'll allow only the following tags: B, I, BR ; so, all other tags except for these will be stripped off. Code: Perl
Output: Code:
Hi,<br> Check out WhatAnIndianRecipe for <b>delicious</b> dishes from <i>India</i>.Advanced UsageIn more advanced use we can control what attributes of certain tags we would like to allow, or if we would like to set default rules like not allowing onmouseover attribute at all, etc. Have a look at the example code below, this is would help you understand the idea behind the package. Code: Perl
Referenceshttp://search.cpan.org/dist/HTML-Scrubber/ |
Re: Clean User Input HTML using HTML::Scrubber
Great Post!I like this blog very much.I knew many important info from this blog.
Keep up the good work |
Re: Clean User Input HTML using HTML::Scrubber
Very interesting, I think I will learn Perl more!
|
| All times are GMT +5.5. The time now is 16:23. |