Tag Archives: XSS

Magento Version 1.3.2.4 Security Update - XSS Vulnerability Fix

Magento Version 1.3.2.4 has been released in response to a major security issue that has been identified in all prior versions of Magento. The issue affects the customer account registration page, if you’re reluctant to upgrade, or if you’ve written to core files (shame on you), there are a couple of solutions:

Edit file (app/code/core/Mage/Customer/Model/Customer.php) as below:

?Download Customer.php
674
675
676
if (!Zend_Validate::is($this->getEmail(), 'EmailAddress')) {
            $errors[] = Mage::helper('customer')->__('Invalid email address "%s"', htmlentities($this->getEmail()));
}

Alternatively if you don’t want to edit core files, add the following to your .htaccess file:

RewriteCond %{REQUEST_METHOD} ^(HEAD|TRACE|DELETE|TRACK) [NC,OR]
RewriteCond %{THE_REQUEST} ^.*(\\r|\\n|
|
).* [NC,OR]
RewriteCond %{HTTP_REFERER} ^(.*)(<|>|’|&#x0A;|&#x0D;|&#x27;|&#x3C;|&#x3E;|&#x00;).* [NC,OR]
RewriteCond %{HTTP_COOKIE} ^.*(<|>|’|&#x0A;|&#x0D;|&#x27;|&#x3C;|&#x3E;|&#x00;).* [NC,OR]
RewriteCond %{REQUEST_URI} ^/(,|;|:|<|>|”>|”<|/|\\\.\.\\).{0,9999}.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^(java|curl|wget).* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(winhttp|HTTrack|clshttp|archiver|loader|email|harvest|extract|grab|miner).* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(libwww-perl|curl|wget|python|nikto|scan).* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(<|>|’|&#x0A;|&#x0D;|&#x27;|&#x3C;|&#x3E;|&#x00;).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(;|<|>|’|”|\)|&#x0A;|&#x0D;|&#x22;|&#x27;|&#x3C;|&#x3E;|&#x00;).*(/\*|union|select|insert|cast|set|declare|drop$).* [NC]
RewriteCond %{QUERY_STRING} ^.*(localhost|loopback|127\.0\.0\.1).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*\.[A-Za-z0-9].* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(<|>|’|&#x0A;|&#x0D;|&#x27;|&#x3C;|&#x3E;|&#x00;).* [NC]
RewriteRule ^(.*)$ badrequest.php

Change badrequest.php to the URL of your choice.

Panic over! :D

Source: http://www.magentocommerce.com/boards/viewthread/51795/P0/

Magento CSRF Vulnerability

Yesterday, Varien publicly acknowledged the existence of a serious vulnerability in Magento, the original blog post details the methodology for this exploit.

Update: the above blog post has been taken down temporarily and the methodology will not be repeated here to protect Magento site owners. Needless to say the main exploit allowed access and execution to certain admin panel URLs without authentication and all too simply.

Varien, have suggested merely changing the URL for the admin panel, however, as others have noted this solution is merely “security through obscurity” and not a real solution. For the moment though, it is better than nothing.

Further to this there is an unofficial patch on a French Magento forum (summarised below) for the XSS vulnerabilities relating to the admin panel.

This outlines 3 key XSS vulnerabilities:

  1. Login page vulnerability. Enter: "username": "> <script> alert (123) </script> into the username box and any password to demonstrate this
  2. Vulnerability on forgot password page. Enter: "> <script> alert (123) </script> on the forgot username/password page
  3. The most dangerous of the three XSS vulnerabilities found to date, navigate here in your Magento store: yourmagentosite.com/download/?return=%22%3Cscript%3Ealert (123)%3C/script%3E

The returning of 123 may seem innocuous however, it is this ability to replace ‘123′ with server side calls that poses a threat to the security of your Magento store. Particularly the third example, what follows is a hypothetical example put forward on a French blog and translated here:

For example, a simple fakemail (identity theft) will allow the attacker to send a link bomb, containing harmful and adapted Javascript, which will control the next action to be performed. The idea is simple, the mail has a link back to normal, the link actually contains XSS and therefore listening Javascript keyboard (for example) and then you logged … Lost.

Write fakemail is paragraph 1 of Chapter 1 of the handbook of the pirate. You can even do it by changing your name in outlook, it is declarative … I can send you a mail from neil.amstrong @ lune.org in 10 seconds. So if a hacker pretends to be the boss of the box and request by email to the person in charge of the back to connect (link in the mail) and to monitor sales, you think it will do what the person question?

It is a very simple attack to carry out very dangerous and there, the script kiddie can take control of your backoffice.

Translation from Wikigento Post [FR].

First and foremost, move your admin panel by editing:

?Download local.xml
1
2
3
4
5
6
7
8
9
<admin>
        <routers>
            <adminhtml>
                <args>
                    <frontName><![CDATA[somethingelse]]></frontName>
                </args>
            </adminhtml>
        </routers>
     </admin>

If you cannot find this XML tree in your local.xml (as I could not for one of my clients) nest the above inside the <config> tags (the same level as <global>.

Delete your cache, easiest way is it open up var/cache/ and delete all the contents of the folder. Then use the new login URL and you should be done! This will protect you from the main CSRF vulnerability uncovered by Artisan System mentioned above.

To protect against the 3 XSS vulnerabilities above make the following changes:

downloader\Mage\Model\Session.php
Line 58

?Download Session.php
1
2
3
if (!empty($_GET['return'])) {
$this->set('return_url', htmlentities($_GET['return']));
}

app\design\adminhtml\default\_your_theme_name\template\login.phtml
Line 54

?Download login.phtml
1
value="<?php echo htmlentities($username) ?>"

app\design\adminhtml\default\_your_theme_name\template\forgotpassword.phtml
Line 57

1
value="<?php echo htmlentities($email) ?>"

And you’re done! Another Magento disaster temporarily averted!

For the moment, any worried Magento administrators who would like this temporary solution applied to their store, are welcome to get in contact.