Skip to content

Several Cryptography Flaws in Magento 2 #5701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
paragonie-scott opened this issue Jul 19, 2016 · 28 comments
Closed

Several Cryptography Flaws in Magento 2 #5701

paragonie-scott opened this issue Jul 19, 2016 · 28 comments
Labels
bug report Event: distributed-cd Distributed Contribution Day Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@paragonie-scott
Copy link

See http://www.openwall.com/lists/oss-security/2016/07/19/3 for details

@piotrekkaminski
Copy link
Contributor

piotrekkaminski commented Jul 19, 2016

Thanks. We are aware of the mcrypt issues and have plans to replace mcrypt with more modern library (phpseclib? libsodium?) pretty soon.

@piotrekkaminski piotrekkaminski added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development improvement labels Jul 19, 2016
@piotrekkaminski piotrekkaminski self-assigned this Jul 19, 2016
@paragonie-scott
Copy link
Author

In the initial comment, you said Magento is not encrypting credit card data, but it was edited before I could reply.

I do want to point out, for the record, that Magento does appear to be decrypting credit card data here.

@piotrekkaminski
Copy link
Contributor

@paragonie-scott to be exact, none of the payment methods included with Magento stores card data.

@paragonie-scott
Copy link
Author

OK, that's good to know. I hope no plugins are using this for that purpose.

@paragonie-scott
Copy link
Author

(phpseclib? libsodium?)

Libsodium is available as a PHP extension, so if you can't require your users to install it from PECL, that's probably not an option.

For symmetric-key encryption, you have a few good choices:

Last I checked (which, admittedly, was ages ago, so it could have changed), phpseclib didn't offer a simple and easy-to-use authenticated encryption interface like defuse does. Unauthenticated encryption, though correctly implemented, doesn't fix the sensitivity to CPAs or CCAs.

If you need public-key encryption and/or digital signatures, give EasyRSA a gander. I wrote about its benefits in response to a Drupal thread about implementing automatic security updates.

https://www.drupal.org/node/2367319#comment-11415297

@piotrekkaminski
Copy link
Contributor

Internal ticket ID MAGETWO-39838

@ghost
Copy link

ghost commented Sep 15, 2016

I just ran into this issue on production :/ when do you plan to fix this?

@unfunco
Copy link
Member

unfunco commented Oct 26, 2016

Since ext-openssl is already a requirement of Magento, would it not make more sense to use that instead? PHP 7.1 will be throwing E_DEPRECATED for the use of ext-mcrypt, and it will either be moved to PECL in 7.2 or 8.0. Usage (ignoring vendors) is contained within Framework/Encryption and it shouldn't be too complicated to migrate (code) – migrating existing data might be more involved.

On my PHP 7.0.12 installation, the OpenSSL extension has 190 cipher methods available, it should be suitable without requiring an additional library or extension.

@paragonie-scott
Copy link
Author

defuse/php-encryption uses OpenSSL, but more importantly it offers simple and easy-to-use authenticated encryption.

You want authenticated encryption.

@unfunco
Copy link
Member

unfunco commented Oct 27, 2016

An easy-to-use abstraction over OpenSSL is fine. For simplicity's sake, I'd rather not have to compile an additional extension or use PECL, which could also be curtains shortly... hence my recommendation of OpenSSL since it's already a requirement, an additional entry in the requires object of my composer.json is a 👍 from me.

@paragonie-scott
Copy link
Author

Understood.

We are in agreement that OpenSSL is preferable to mcrypt. I just wanted to emphasize the use of a secure abstraction instead of lower-level primitives. :)

@maxbucknell
Copy link
Contributor

I just checked my installation of 2.1.2, and the develop branch, and we can see that use of the mcrypt_* is still alive and well:

See Magento\Framework\Encryption\Crypt

<?php

// ....
public function __construct($key, $cipher = MCRYPT_BLOWFISH, $mode = MCRYPT_MODE_ECB, $initVector = false)
{
    $this->_cipher = $cipher;
    $this->_mode = $mode;
    $this->_handle = mcrypt_module_open($cipher, '', $mode, '');
    try {
        $maxKeySize = mcrypt_enc_get_key_size($this->_handle);
    
    // ...

Since it's not reasonably possible to say that PHP 7.1 is supported without this, and given that PHP 7.1 is now out, can we have a status update on this ticket MAGETWO-39838?

@ktomk
Copy link
Contributor

ktomk commented Dec 4, 2016

For cross-reference: In Magerun 2 we've added PHP 7.1 support now and do see the various reported issues with Magento 2 now as well as they became blatantly obvious. We're tracking this downstream at netz98/n98-magerun2#256.

Issues I could spot so far within the Magento 2 Github Tracker are:

I suggest to add 7.1 to the Travis build and allow it to fail. That should make it easier to progress and keep track of things.

ktomk added a commit to ktomk/magento2 that referenced this issue Dec 6, 2016
This change is for forward compatibility with PHP 7.1.

Add PHP 7.1 (currently PHP 7.1-RC6 on Travis) to the Travis build. Allow
failures with it as failures are expected.

To get it to work, for PHP 7.1 composer ignores platform requirements.

Refs:

- magento#5701
@ktomk
Copy link
Contributor

ktomk commented Jan 23, 2017

In the light of the recent security report with the remote code execution issue on sending mails (#6146, ZF2016-04), I would suggest Magento to run checks with RIPS which is able to find injection flaws of such kind (e.g. in Roundcube, published Dec 6 2016). Just commenting for reference /cc @piotrekkaminski

@ktomk
Copy link
Contributor

ktomk commented May 3, 2017

X-Ref:

This can be now closed as PHP 7.1 became a part of Travis CI builds officially: https://github.com/magento/magento2/blob/develop/.travis.yml#L13

via: #7688 (comment)

@paragonie-scott
Copy link
Author

One possible solution to the cryptography flaws laid out here is sodium_compat, but it's not yet known if it's safe to use yet. Only a cryptography audit will tell.

@markshust
Copy link
Contributor

What's the TAT on a release for PHP 7.1 compatibility?

@paragonie-scott
Copy link
Author

sodium_compat v1.0 is out if the Magento team wants to switch to more secure cryptography

@SharkWipf
Copy link

Libsodium has just been merged into PHP 7.2 so, from 7.2 onwards, it's no longer dependent on an extension.

@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-66161

@magento-team magento-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report develop labels Jul 31, 2017
@magento-engcom-team magento-engcom-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report develop Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Sep 11, 2017
@barryvdh
Copy link
Contributor

So given the state of M2.2, it will never work on PHP7.2? If M2.3 will use Sodium, does that mean it will only work with PHP7.2 and above, or will the compat module be included (or suggested for lower versions)?

@magento-engcom-team
Copy link
Contributor

@paragonie-scott, thank you for your report.
We've created internal ticket(s) MAGETWO-39838 to track progress on the issue.

@magento-engcom-team magento-engcom-team added 2.2.x Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release and removed 2.2.x labels Dec 7, 2017
@magento-engcom-team magento-engcom-team added the Event: distributed-cd Distributed Contribution Day label Mar 19, 2018
@ishakhsuvarov
Copy link
Contributor

Implementation for 2.3 is currently in progress in the scope of magento-engcom/php-7.2-support project

@peterjaap
Copy link
Contributor

@ishakhsuvarov judging from the composer.json in that branch, M2.3.1 will still be using a polyfill for mcrypt. Can you confirm there is an initiative underway to actually implement libsodium along with sodium_compat instead of mcrypt, phpseclib and mcrypt_compat?

@paragonie-scott
Copy link
Author

I can answer this one, as I've been involved in the migration strategy and protocol review.

The gameplan is to switch to libsodium (with sodium_compat as a fallback when ext/sodium isn't available).

However, for the sake of decrypting existing ciphertexts after the M2 upgrade, mcrypt_compat was included as well. Its purpose is to enable seamless migrations to better encryption, not to keep Magento in the dark ages of cryptography.

@peterjaap
Copy link
Contributor

@paragonie-scott thanks for the explanation! Just listened to you on the Roundtable ep 71 (and 73) yesterday, great work on libsodium w/ PHP7.2 👍

@ihor-sviziev
Copy link
Contributor

Hi @paragonie-scott,
Magento 2.3.x supports libsodium together with php 7.2, so looks like this issue was already fixed. Wasn't it?

@paragonie-scott
Copy link
Author

Yep!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Event: distributed-cd Distributed Contribution Day Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests