Dec 04, 2008, 12:45 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Search via SMF or Google: modx forums all of modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
News:Donate to MODx: Donations
Pages: [1] 2   Go Down
  Print  
Author Topic: Sanitising HTML  (Read 1782 times)
0 Members and 1 Guest are viewing this topic.
tuatara
Support Subscriber
*
Posts: 69


« on: May 14, 2008, 11:22 PM »

I'm intending to allow HTML in my comments, but I'm wary of introducing XSS vulnerabilities. I was planning to use the HTML Purifier library to sanitise the HTML, but I can't see a MODx event that fires when a new comment is posted. Is there any event that will include posting comments? How difficult would it be to add an event into the Jot code?

Thanks for any help ...

Cheers
Matt
Logged
Uncle68
Moderators
*
Posts: 296



« Reply #1 on: May 15, 2008, 04:54 AM »

Sorry, I don't have the answer to you question, but I just wanted to thank you for the tip! Html Purifier solves problems I was struggling with yesterday.

If we have "recommended tools" section on the forum we should put it there.

Logged
Dr. Scotty Delicious
Coding Team
*
Posts: 1,172


Dr. of Fine Pirate Arts


WWW
« Reply #2 on: Jun 12, 2008, 06:06 AM »

I have a modified version of Jot 1.1.3 which uses HTML purifier.
I wrote an extension class for the purifier that also changes <b> tags to <strong>, <i> tags to <em>, and <s>&<strike> tags to <del>.
I set a require for the extension class in jot.class.inc.php and then call the public static function Purify::Clean($_POST['content']);

It uses HTML Purifier 3.1.0, so of course it is PHP 5 only.

I would be happy to share my modifications with you if you are interested.

See it in action at my site: http://scottydelicious.com/

-sD-
Dr. Scotty Delicious, DFPA.
Logged

We pillage, we plunder, we rifle and loot. Drink up me 'earties, Yo Ho!
We kidnap and ravage and don't give a hoot. Drink up me 'earties, Yo Ho!
Yo Ho, Yo Ho! A pirate's life for me.
tuatara
Support Subscriber
*
Posts: 69


« Reply #3 on: Jun 16, 2008, 03:48 AM »

I would be happy to share my modifications with you if you are interested.

Yes please!

Cheers
Matt
Logged
Dr. Scotty Delicious
Coding Team
*
Posts: 1,172


Dr. of Fine Pirate Arts


WWW
« Reply #4 on: Jun 16, 2008, 04:36 AM »

First... Safety!
Make a backup of the folder "/assets/snippets/jot/".
Also, remember that this modification will only work on a server running PHP 5.
PHP 4 will throw fatal errors.

Download my Jot 1.1.3 modifications.

This archive unzips to a folder with the file "jot.class.inc.php". Upload this file to "/assets/snippets/jot/" and overwrite or replace the existing file.
There is also a folder in the archive called "includes". Upload the contents of this folder to "/assets/snippets/jot/includes/".

This is the class I wrote to purify the post as well as the HTML Purifier 3.1.0 library.

I have modified jot.class.inc.php to include my class and use it as a filter. Additionally, I have modified the jot class to send notifications as HTML instead of as plain text. This gives you a greater deal of flexibility in your notification templates.

-sD-
Dr. Scotty Delicious, DFPA.

Logged

We pillage, we plunder, we rifle and loot. Drink up me 'earties, Yo Ho!
We kidnap and ravage and don't give a hoot. Drink up me 'earties, Yo Ho!
Yo Ho, Yo Ho! A pirate's life for me.
davidm
Marketing & Design Team
*
Posts: 6,777


The best way to predict the future is to invent it


WWW
« Reply #5 on: Jun 16, 2008, 08:46 AM »

There is a HTML purifier plugin for MODx, and it has been developped by the author of HTML purifier :
http://htmlpurifier.org/svnroot/htmlpurifier/trunk/plugins/modx.txt

You can also look at this thread :
http://modxcms.com/forums/index.php/topic,6604.0.html

And more recently :
http://htmlpurifier.org/phorum/read.php?3,1866

Logged

.: nodeo.net : Pour un web libre, moderne et ouvert ! :: david-molliere.net : Suivez en "live" mes expérimentations et billets sur les CMS et autres applications web :.

*** Forums modxcms.fr Participez à l'élaboration du site MODx francophone ! ***

! Nouveau !  En live, ne manquez pas les news de modxcms.fr sur Twitter   ! Nouveau !

MODx est l'outil idéal pour les developpeurs et webdesigners qui cherchent un framework de gestion de contenu hautement flexible et performant, tout en étant simple d'accès pour les utilisateurs finaux.

Config : Apache 2.2.8 - MySQL 5.0.45 - PHP 5.2.6 | Debian 4.0 (Etch)

Réalisations sous MODx : | pargade-notaires.fr | soleil.info | gican.asso.fr | michelez-notaires.com | amadom.gerondicap.com | jocelyne-violet.net
tuatara
Support Subscriber
*
Posts: 69


« Reply #6 on: Jun 16, 2008, 04:14 PM »

There is a HTML purifier plugin for MODx, and it has been developped by the author of HTML purifier :

Yeah, I tried that. But the plugin works on content edited in the manager, and I'm not at all concerned about what is done in the manager. It's specifically comments that concern me, and the plugin won't do anything to those. (Will it? ... unless I'm missing something?)

Cheers
Matt
Logged
tuatara
Support Subscriber
*
Posts: 69


« Reply #7 on: Jun 16, 2008, 04:16 PM »

I have modified jot.class.inc.php to include my class and use it as a filter. Additionally, I have modified the jot class to send notifications as HTML instead of as plain text. This gives you a greater deal of flexibility in your notification templates.

Thanks Scotty ;-). I have some modifications of my own to Jot so I'll need to merge the two; it'll take me a week or so (I'm taking a break) but I shall report back!

Cheers
Matt
Logged
Dr. Scotty Delicious
Coding Team
*
Posts: 1,172


Dr. of Fine Pirate Arts


WWW
« Reply #8 on: Jun 16, 2008, 05:44 PM »

There is a HTML purifier plugin for MODx, and it has been developped by the author of HTML purifier [...]

That's true, but it only fires on OnBeforeDocFormSave.
The trouble is, the appropriate events for purifying HTML only seem to be fired in the Manager
I guess what I should try is invoking OnBeforeDocFormSave from Jot.

Thanks Scotty ;-). I have some modifications of my own to Jot so I'll need to merge the two; it'll take me a week or so (I'm taking a break) but I shall report back!

Cheers
Matt
No problem Matt. I put this together when I was redesigning my site. I thought I was going to provide a WYSIWYG RTE for comments, but I find that HTML Purifiers AutoFormat.AutoParagraph and AutoFormat.Linkify work great, so at this point I am on the fence about adding an RTE.

-sD-
Dr. Scotty Delicious, DFPA.
Logged

We pillage, we plunder, we rifle and loot. Drink up me 'earties, Yo Ho!
We kidnap and ravage and don't give a hoot. Drink up me 'earties, Yo Ho!
Yo Ho, Yo Ho! A pirate's life for me.
Ambush Commander
Jr. Member
*
Posts: 20


« Reply #9 on: Jun 16, 2008, 08:35 PM »

Hello Dr. Scotty Delicious,

It's great to see that someone else has stepped up to the plate to have an updated plugin of HTML Purifier for Modx. There is a plugin, but it's somewhat untested as I don't use Modx, and it has problems with HTML Purifier 3.1 (I've got an updated version pending for that).

Would you like me to link to your plugin for Jot on the HTML Purifier home page?

Cheers,
Edward
Logged
Dr. Scotty Delicious
Coding Team
*
Posts: 1,172


Dr. of Fine Pirate Arts


WWW
« Reply #10 on: Jun 16, 2008, 10:45 PM »

Hello Dr. Scotty Delicious,

It's great to see that someone else has stepped up to the plate to have an updated plugin of HTML Purifier for Modx. There is a plugin, but it's somewhat untested as I don't use Modx, and it has problems with HTML Purifier 3.1 (I've got an updated version pending for that).

Would you like me to link to your plugin for Jot on the HTML Purifier home page?

Cheers,
Edward

Sure, but it would be good to specifically note that it is not a system wide plugin, but merely a modification of the Jot snippet with a class for purifying the HTML that is passed in by Jot's $comment['content'] variable.

I think what I may do is make another modification of the jot.class.inc.php file to invoke the OnBeforeDocFormSave system event so that a plugin   like yours will work with comments. I might also try to put together a plugin that can purify any form submitted on the front end. That might be better for the Jot upgrade path and also a bit more universal so it can be used with the eForm snippet (or any form in the front end).

-sD-
Dr. Scotty Delicious, DFPA.
Logged

We pillage, we plunder, we rifle and loot. Drink up me 'earties, Yo Ho!
We kidnap and ravage and don't give a hoot. Drink up me 'earties, Yo Ho!
Yo Ho, Yo Ho! A pirate's life for me.
rthrash
Foundation
*
Posts: 9,575



WWW
« Reply #11 on: Jun 17, 2008, 07:27 AM »

Feel free to modify Jot to your heart's content. Armand is letting the community take over the 096x release and making it more functional for the tens of thousands of sites that will still be running that version will be greatly appreciated. You might want to head on over to the JIRA install and start committing to the project itself, too, once you get it sorted to your liking. Smiley
Logged

MODx is a framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Community participation and questions are encouraged, especially when you help us help you, read the wiki, and review snippet parameters – even if you have to look at the source. Searching the forums helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
Dr. Scotty Delicious
Coding Team
*
Posts: 1,172


Dr. of Fine Pirate Arts


WWW
« Reply #12 on: Jun 17, 2008, 06:42 PM »

Feel free to modify Jot to your heart's content. Armand is letting the community take over the 096x release and making it more functional for the tens of thousands of sites that will still be running that version will be greatly appreciated. You might want to head on over to the JIRA install and start committing to the project itself, too, once you get it sorted to your liking. Smiley
Yeah, no problem.

Well... small problem. I got my Crucible and Fisheye username and password a long time ago. I don't have a clue what it is. can it be reset?

-sD-
Dr. Scotty Delicious, DFPA.
Logged

We pillage, we plunder, we rifle and loot. Drink up me 'earties, Yo Ho!
We kidnap and ravage and don't give a hoot. Drink up me 'earties, Yo Ho!
Yo Ho, Yo Ho! A pirate's life for me.
rthrash
Foundation
*
Posts: 9,575



WWW
« Reply #13 on: Jun 17, 2008, 07:58 PM »

Yes indeed: http://svn.modxcms.com/jira/secure/ForgotPassword!default.jspa but you'll have to recall your username.
Logged

MODx is a framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Community participation and questions are encouraged, especially when you help us help you, read the wiki, and review snippet parameters – even if you have to look at the source. Searching the forums helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
Dr. Scotty Delicious
Coding Team
*
Posts: 1,172


Dr. of Fine Pirate Arts


WWW
« Reply #14 on: Jun 18, 2008, 05:52 AM »

I posted a full featured plugin here: http://modxcms.com/HTML-Purifier-for-Forms-Plugin-2096.html

No Jot hackery needed.

-sD-
Dr. Scotty Delicious, DFPA.
Logged

We pillage, we plunder, we rifle and loot. Drink up me 'earties, Yo Ho!
We kidnap and ravage and don't give a hoot. Drink up me 'earties, Yo Ho!
Yo Ho, Yo Ho! A pirate's life for me.
Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP

Copyright © 2005-2008 MODxCMS, All rights reserved. Contact Us
Styles by ziworks.com

Powered by SMF 1.1.4 | SMF © 2005, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!