boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Fix for possible html/javascript attacks in comments

 
Post new topic   Reply to topic    boardom Forum Index -> Announcements
View previous topic :: View next topic  
Author Message
michel v
Site Admin


Joined: 25 Jan 2002
Posts: 799
Location: Corsica

PostPosted: Mon Jun 23, 2003 1:57 am    Post subject: Fix for possible html/javascript attacks in comments Reply with quote

Allowing visitors to use HTML in their comments can have nasty side-effects, such as javascript code being executed through onMouseOver events, iframes being loaded, tags being positionned with style/id attributes (this was fixed a while ago), etc.


So here's a fix that prevents such attacks:

Open b2functions.php, and look for these lines:
[php:1:27ed9f8a87]function balanceTags($text, $is_comment = 0) {
global $use_balanceTags;
if ($use_balanceTags == 0) {
return($text);
}[/php:1:27ed9f8a87]

Copy the following code, and put it right after the previous lines:
[php:1:27ed9f8a87] if ($is_comment) {
// sanitise HTML attributes, remove frame/applet tags
$text = preg_replace('#( on[a-z]{1,}|style|class|id)="(.*?)"#i', '', $text);
$text = preg_replace('#( on[a-z]{1,}|style|class|id)=\'(.*?)\'#i', '', $text);
$text = preg_replace('#([a-z]{1,})="(( |\t)*?)(javascript|vbscript|about):(.*?)"#i', '$1=""', $text);
$text = preg_replace('#([a-z]{1,})=\'(( |\t)*?)(javascript|vbscript|about):(.*?)\'#i', '$1=""', $text);
$text = preg_replace('#\<(\/{0,1})([a-z]{0,2})(frame|applet)(.*?)\>#i', '', $text);
}[/php:1:27ed9f8a87]

This fix will be committed to the CVS and in later releases.


What this fix does:
It removes all style/id/class/on* attributes (on* matches all known javascript-inducing attributes), removes URLs starting with javascript/vbscript/about, and finally removes all *frame* and applet tags.

If you know about other possible attacks via HTML in comments, please email/PM me and other b2-based products developers (WordPress, b2evolution, b2++, etc).
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
Candle



Joined: 23 Dec 2002
Posts: 547

PostPosted: Mon Jun 23, 2003 6:16 am    Post subject: ........ Reply with quote

Thanks michel for the heads up on that .
_________________
My Game Forum
Back to top
View user's profile Send private message
Mister44



Joined: 31 Oct 2002
Posts: 237
Location: Philadelphia, PA, USA

PostPosted: Mon Jun 23, 2003 6:43 pm    Post subject: Re: Fix for possible html/javascript attacks in comments Reply with quote

michel v wrote:
and put it right after the previous lines


Shouldn't it actually go between lines 2 and 3? Otherwise, if balanceTags is disabled, the comment won't get sanitized... Also if you don't entirely trust the people with posting access, you can remove the if_comment test and scrub all posts. This would not be an altogether bad thing.

Fixed in LjUpdate/YABBOB.
Back to top
View user's profile Send private message Visit poster's website
GamerZ



Joined: 15 May 2002
Posts: 537
Location: Singapore

PostPosted: Tue Jun 24, 2003 5:34 am    Post subject: Reply with quote

y not just use striptags in comments and use bbcode instead?
_________________

++ GamerZ.Per.Sg - Complex Simplicity
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
fplanque



Joined: 22 Dec 2002
Posts: 53
Location: Montpellier, South of France

PostPosted: Wed Jun 25, 2003 1:53 am    Post subject: Reply with quote

Michel,

Have you actually tested this patch in the place it is?

My main concern is that the comment text is escaped with addslashes() before it gets any chance to have attributes filtered out. So, as far I have tested it, it just won't filter out any evil javascript attribute...

I have addressed this and a few lower level issues here:

http://b2evolution.net/forums/viewtopic.php?p=164#164
_________________
-François
Check out : a blogtool for bloggers who want more!
Back to top
View user's profile Send private message Visit poster's website
sakichan



Joined: 14 Jul 2003
Posts: 1
Location: Kawasaki, Japan

PostPosted: Mon Jul 14, 2003 8:04 pm    Post subject: Reply with quote

I'll go to the full disclosure mode because b2evolution 0.8.2rc2 is made public.

Michel's fix is not complete, because web browsers accept HTML attributes with a unquoted value, and because such attributes are not checked with that fix.

That problem is fixed in b2evolution 0.8.2rc2 and newer versions, at least when XHTML validating checker is used (that is default in 0.8.2rc2, but Fplanque does not decide yet whether it is default for newer versions). He also adopted this checker not only for comments but also for blog posts, becuase malicious guest bloggers may try to escalate their rights exploiting this vulnerability.

b2evolution 0.8.2rc2 (or newer versions) can be downloaded from
http://b2evolution.net/downloads/index.html
_________________
Nobuo Sakiyama
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Announcements All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group