Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Regex: Strip <script> tags?

by hacker (Priest)
on Sep 02, 2007 at 14:37 UTC ( #636604=note: print w/ replies, xml ) Need Help??


in reply to Regex: Strip <script> tags?

I use the following in a piece of code here:

# Strip <script [..]>..</script> and <style>..</style> $content =~ s!<(s(?:cript|tyle))[^>]*>.*?</\1>!!gis;

backtracking++


Comment on Re: Regex: Strip <script> tags?
Download Code
Re^2: Regex: Strip <script> tags?
by clinton (Priest) on Sep 02, 2007 at 14:49 UTC
    There are plenty of things that will be missed with your regex. For instance, all of the onclick/focus/load/etc events.

    Have a look at HTML::StripScripts::Parser, which allows you to customise the HTML / CSS that you would like to allow, while removing XSS attacks.

    Clint

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://636604]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2015-07-04 04:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls