Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl regular exp prevent cross site scripting

Status
Not open for further replies.

rakeshou

Programmer
Aug 15, 2006
17
US
Hi gurus,

What can be the perl regular expression that replaces the <script></sript> tags and anything between them with blank space
currently I am doing soemthing like this,

$comments =~ s!<script||javascript||vbscript||(../)||</script>!!ig;

but this just removes the <script tags

Thank you
 
see how this works:

Code:
$comments =~ s/(<[\s\/]*)(script\b[^>]*>)/$1XXX$2/gi;
while ($comments =~ s/(<[^>]*?)\b(on\w+\s*=)/$1XXX$2/gi) {}

it doesn't remove the scripting stuff but it should disable it by putting 'XXX' before the tagname/attribute. So:

<script language="javascript>

would become:

<XXXscript language="javascript>

and

<img src="frog.jp" onMouseOver="alert('JUMP YOU GREEN FROG!')">

should become:

<img src="frog.jp" XXXonMouseOver="alert('JUMP YOU GREEN FROG!')">

- Kevin, perl coder unexceptional!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top