Topic: Sanitising HTML  (Read 4217 times)

Pages: [1]   Go Down

#1: 14-May-2008, 11:22 PM

Support Subscriber

tuatara
Posts: 76

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

#2: 15-May-2008, 04:54 AM

Moderators

Uncle68
Posts: 299

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.

#3: 12-Jun-2008, 06:06 AM

Coding Team

Dr. Scotty Delicious
Posts: 1,192

D.F.P.A.

WWW
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.

#4: 16-Jun-2008, 03:48 AM

Support Subscriber

tuatara
Posts: 76

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

Yes please!

Cheers
Matt

#5: 16-Jun-2008, 04:36 AM

Coding Team

Dr. Scotty Delicious
Posts: 1,192

D.F.P.A.

WWW
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.

#6: 16-Jun-2008, 08:46 AM

Marketing & Design Team

davidm
MODx evangelist
Posts: 7,073

The best way to predict the future is to invent it

WWW
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

.: 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.67 - PHP 5.2.8 | 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

#7: 16-Jun-2008, 04:14 PM

Support Subscriber

tuatara
Posts: 76

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

#8: 16-Jun-2008, 04:16 PM

Support Subscriber

tuatara
Posts: 76

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

#9: 16-Jun-2008, 05:44 PM

Coding Team

Dr. Scotty Delicious
Posts: 1,192

D.F.P.A.

WWW
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.

#10: 16-Jun-2008, 08:35 PM

Ambush Commander
Posts: 20

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

#11: 16-Jun-2008, 10:45 PM

Coding Team

Dr. Scotty Delicious
Posts: 1,192

D.F.P.A.

WWW
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.

#12: 17-Jun-2008, 07:27 AM

Foundation

rthrash
Posts: 11,282

WWW
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
MODx is a content managmeent framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Please help us help you when asking for assistance and read the wiki. Searching the forums from the top level helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.

#13: 17-Jun-2008, 06:42 PM

Coding Team

Dr. Scotty Delicious
Posts: 1,192

D.F.P.A.

WWW
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.

#14: 17-Jun-2008, 07:58 PM

Foundation

rthrash
Posts: 11,282

WWW
Yes indeed: http://svn.modxcms.com/jira/secure/ForgotPassword!default.jspa but you'll have to recall your username.
MODx is a content managmeent framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Please help us help you when asking for assistance and read the wiki. Searching the forums from the top level helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.

#15: 18-Jun-2008, 05:52 AM

Coding Team

Dr. Scotty Delicious
Posts: 1,192

D.F.P.A.

WWW
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.

#16: 18-Jun-2008, 05:56 AM

Marketing & Design Team

davidm
MODx evangelist
Posts: 7,073

The best way to predict the future is to invent it

WWW
Great Scotty !!!

I'll sure have a use for it, combined with FrondEndDocumentManager (a.k.a FDM) and those rich text areas Grin
.: 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.67 - PHP 5.2.8 | 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

#17: 31-Mar-2009, 06:42 PM


rossco
Posts: 919

WWW
I know this is an old post but I'm needing a way to purify text that is submitted by a webuser...

I am allowing users to submit text in a textarea and I want to restrict the code that is allowed in the textarea.  I would like to use this purify plugin but it's not doing anything for me...

I have a textarea and I put <div>TEST</div> in the form and submitted, the code was sent and saved but not purified.  Any idea why that would be and if this plugin is suitable? 

Thanks!

EDIT : How can I stop any HTML elements being input in to forms completely.  Allowing the user to input HTML tags is causing my pages to loose shape if the user input incorrect tags or doesn't close them
« Last Edit: 31-Mar-2009, 08:16 PM by rossco »
Pages: [1]   Go Up
0 Members and 1 Guest are viewing this topic.