 |
boardom b2 message board
|
View previous topic :: View next topic |
Author |
Message |
michel v Site Admin
Joined: 25 Jan 2002 Posts: 799 Location: Corsica
|
Posted: Mon Jun 23, 2003 1:57 am Post subject: Fix for possible html/javascript attacks in comments |
|
|
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 |
|
 |
Candle
Joined: 23 Dec 2002 Posts: 547
|
Posted: Mon Jun 23, 2003 6:16 am Post subject: ........ |
|
|
Thanks michel for the heads up on that . _________________ My Game Forum
 |
|
Back to top |
|
 |
Mister44

Joined: 31 Oct 2002 Posts: 237 Location: Philadelphia, PA, USA
|
Posted: Mon Jun 23, 2003 6:43 pm Post subject: Re: Fix for possible html/javascript attacks in comments |
|
|
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 |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Tue Jun 24, 2003 5:34 am Post subject: |
|
|
y not just use striptags in comments and use bbcode instead? _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
fplanque
Joined: 22 Dec 2002 Posts: 53 Location: Montpellier, South of France
|
Posted: Wed Jun 25, 2003 1:53 am Post subject: |
|
|
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 |
|
 |
sakichan
Joined: 14 Jul 2003 Posts: 1 Location: Kawasaki, Japan
|
Posted: Mon Jul 14, 2003 8:04 pm Post subject: |
|
|
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 |
|
 |
|
|
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
|