Sanitized comments in the db

While Brad Choate’s Sanitize plugin works great for keeping unwanted HTML (and PHP, ASP, JSP, and SSI) out of your pages that include comments, as a plugin it only gets to affect your rendered pages: the things you don’t want are still in your database, waiting for you to disable the plugin or decide to directly access the comments in your MySQL database.

Luckily, Brad’s plugin design, having the plugin call a separate Perl module, makes it easy to hack it into Movable Type’s comment post code.

If you have the plugin installed, all you have to do is add two lines to {your MT directory}/lib/MT/App/Comments.pm, replacing

    $comment->text($q->param('text'));

(line 98, for mine anyway), with

    use bradchoate::sanitize;
    $comment->text(bradchoate::sanitize::sanitize_html($q->param('text'),
       "a href,strong,em,blockquote"));

(replacing that abbreviated set of allowed tags and attributes with your own) and any future comments will be sanitized before they even make it to your database.

4 Comments

Comment by Shannon #
2002-11-08 09:01:49

You do realize that this line of code is shoving your sidebar to the bottom of the page, dontcha?

Just sayin’.

 
Comment by Phil Ringnalda #
2002-11-08 14:29:01

Not in a decent browser with a decent idea of default font sizes, it isn’t.

Yeah, I did notice that, in that browser, but then I forgot about moving the <pre> to the extended entry. Thanks for the reminder, sweetie.

 
Comment by Shannon #
2002-11-08 14:51:57

You’re not going to get all Mozilla evangelist on me now, too, are you?

 
Trackback by Jonathon Delacour #
2003-01-04 03:26:54

So far, so good

Happily, the move seems to have worked. I was able to see the new server less than 24 hours after changing the DNS. It’s such a relief to be on a Linux server instead of IIS—the support people at my previous host were excellent but I love being a…

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <del datetime="" cite=""> <dd> <dl> <dt> <em> <i> <ins datetime="" cite=""> <kbd> <li> <ol> <p> <pre> <q cite=""> <samp> <strong> <sub> <sup> <ul> in your comment.