Jump to content

Javascript Event Removal


LegosJedi

Recommended Posts

Hey, I'm working with BBCodes, and I'm trying to figure out how to remove Javascript event handlers from BBCodes who have arguments, as in the url BBCode. I know this can be done with Regular Expressions, but I can't find anything on removing the events. There's alot on just taking away the script tags, but no events.

Link to comment
Share on other sites

as you can add spaces/returns to the word script and it will still run, i have tried to also block that..

 

requires testing

 

try this

<?php
$text = '
hello all
<script language="javascript">
alert("Goto www.phpfreaks.com");
</script>';

//test2
$text = '
hello all
<script language="javascript">
alert("Goto www.phpfreaks.com");
</scr
ipt>';


$$text = preg_replace('%<s\s*c\s*r\s*i\s*p\s*t\s*[^>]*>.*(?=\s</s\s*c\s*r\s*i\s*p\s*t\s*[^>]*>)\s</s\s*c\s*r\s*i\s*p\s*t\s*[^>]*>%sim', '', $text);
?>

Link to comment
Share on other sites

Okay, so I have a BBCode parser. Currently, if a user posts something like 'javascript:alert('hacked!')' in the url of a url BBCode, when you click on it, it will execute the javascript. I want to have a way to check to see if javascript is found in the url of the url BBCode, and then take them out. Then, you can also hack it by closing off the url tag with a quote, and adding other attributes, like javascript event handlers. I want to be able to take those out, too.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.