Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Cleaning "harmful" HTML
Well, any time I try to post a topic in the "PHP group", it never shows
up, so here's a repost in this group,

Can anyone help me out with cleaning up submitted HTML documents?  I
allow a user to submit what ever HTML they way, but I then have to
clean out certain stuff to make sure the HTML isn't harmful to my
members.  I am trying to remove any type of scripting that I can from
the submit HTML and frames.

So far I got:

# This will clean HTML up so that we can save it (removes scripting,
iframes, ect)
function Clean_HTML($str, $replace_br=TRUE) {

$str = $str.'<';

$str = preg_replace("/<[^>]*script[^>]*>/i", '', $str);
$str = preg_replace("/<[^>]*script[^>]*</i", '', $str);
$str = preg_replace("/<[^>]*iframe[^>]*>/i", '', $str);
$str = preg_replace("/<[^>]*iframe[^>]*</i", '', $str);
$str = preg_replace("/<[^>]*iframe[^>]*</i", '', $str);
$str = preg_replace("/(<[^>]*) on[a-zA-Z]*[^=]*(=[^>]*> )/i", "$1
noscripts$2", $str);
if ($replace_br==TRUE) { $str = str_replace("\r\n", "<br>", $str);
};
$str = substr($str,0,-1);
return $str;

}

It works good for what I coded in but I also know that the CSS tag
"@import" and "moz-binding: " can be used to include harmful scripting.
I am also sure there has to be alto of other ways to include harmful
scripting too.

If you have a function to clean the HTML already, I would truly
appreciate it.  If you also know of more ways people can include
harmful HTML, please let me know.

Thanks for anything in advance,

Anthony F Greco.


Report this thread to moderator Post Follow-up to this message
Old Post
ChillAxen
09-28-06 11:56 PM


Re: Cleaning "harmful" HTML
ChillAxen wrote:

>
> Can anyone help me out with cleaning up submitted HTML documents?  I
> allow a user to submit what ever HTML they way, but I then have to
> clean out certain stuff to make sure the HTML isn't harmful to my
> members.  I am trying to remove any type of scripting that I can from
> the submit HTML and frames.
>

strip_tags() ?
(http://uk2.php.net/strip_tags)

C.

Report this thread to moderator Post Follow-up to this message
Old Post
Colin McKinnon
09-28-06 11:56 PM


Re: Cleaning "harmful" HTML
On Thu, 28 Sep 2006 12:54:41 -0700, ChillAxen wrote:

> Well, any time I try to post a topic in the "PHP group", it never shows
> up, so here's a repost in this group,
>
> Can anyone help me out with cleaning up submitted HTML documents?  I
> allow a user to submit what ever HTML they way, but I then have to
> clean out certain stuff to make sure the HTML isn't harmful to my
> members.  I am trying to remove any type of scripting that I can from
> the submit HTML and frames.
>
> So far I got:
>
> snip
>
> It works good for what I coded in but I also know that the CSS tag
> "@import" and "moz-binding: " can be used to include harmful scripting.
>  I am also sure there has to be alto of other ways to include harmful
> scripting too.
>
> If you have a function to clean the HTML already, I would truly
> appreciate it.  If you also know of more ways people can include
> harmful HTML, please let me know.
>
> Thanks for anything in advance,
>
> Anthony F Greco.

I'd recommend not re-inventing the wheel. There are probably dozens of
functions and classes available to do such things.

Here's one I'm fond of:
http://cyberai.com/inputfilter/

--
Schluppy




Report this thread to moderator Post Follow-up to this message
Old Post
Schluppy
09-29-06 02:56 AM


Re: Cleaning "harmful" HTML
Thank you =].  What I wanted was an already coded class, just couldnt
find one =].  Thank you so much.

Schluppy wrote:
> On Thu, 28 Sep 2006 12:54:41 -0700, ChillAxen wrote:
> 
>
> I'd recommend not re-inventing the wheel. There are probably dozens of
> functions and classes available to do such things.
>
> Here's one I'm fond of:
> http://cyberai.com/inputfilter/
>
> --
> Schluppy


Report this thread to moderator Post Follow-up to this message
Old Post
ChillAxen
09-29-06 11:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:14 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.