Review main Merged

51737[TASK] Compare password hashes in constant time

Christian Futterlieb CR +2 V +2 Normal +111 −3 updated 02/23/17, 17:21

Commit message

In order to avoid time-based hash-based attacks, the native
PHP security functions are used instead of simple string
comparisons, when comparing passwords with hashes.

Review

  • Code review CR +2
    • Markus Klein +2
    • Mads Lønne Jensen +1
    • Helmut Hummel +1
  • Verified V +2
    • Markus Klein +2
    • Helmut Hummel +1
    • TYPO3com +1 CI

Issues 2

Files 7

Review log 4050

Show 2125 earlier messages
  1. Christian Futterlieb uploaded patch set 1 02/18/17, 10:52

  2. TYPO3com voted on patch set 1 V +1 02/18/17, 10:57 Completed build in 04m 51s on Sat, 18 Feb, 11:57 AM Test Summary: 56289 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8213

  3. Oliver Klee updated the commit message in patch set 2 02/18/17, 11:59

  4. TYPO3com voted on patch set 2 V +1 02/18/17, 12:04 Completed build in 04m 59s on Sat, 18 Feb, 01:04 PM Test Summary: 56289 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8214

  5. Thomas Hohn voted on patch set 2 CR +1 02/19/17, 19:50

  6. Andreas Kienast commented on patch set 2 CR -1 02/19/17, 20:00

    I have to give a -1 here for multiple reasons: - A ReST document describing the feature is missing (although I rather think it's a task) - Features are not backported to releases branches (in this case 7.6)
  7. Andreas Kienast commented on patch set 2 02/19/17, 20:04

    I see, we can't backport the patch to 7.6 anyway. The function hash_equals requires PHP 5.6, the minimum supported PHP version for TYPO3 7.6 is 5.5
  8. Christian Futterlieb commented on patch set 2 02/19/17, 20:57

    I thought we'd use for ex. symfony/polyfill-php56 for the backport. It's not a polyfill in the expected way, we would use Symfony\Polyfill\Php56::hash_equals(). Just a little piece of code for the purpose of better security imo. Besides that: should I just change commit message to "[TASK].."?
  9. Mathias Brodala commented on patch set 2 02/20/17, 08:21

    > I thought we'd use for ex. symfony/polyfill-php56 for the backport. > It's not a polyfill in the expected way, we would use > Symfony\Polyfill\Php56::hash_equals(). Just a little piece of code > for the purpose of better security imo. I'd recommend https://github.com/ircmaxell/password_compat which provides a polyfill for password_verify() and is also resistant to timing attacks. > Besides that: should I just change commit message to "[TASK].."? It should be a BUGFIX actually and thus should be backported to v7 in any case.
  10. Christian Futterlieb commented on patch set 2 02/20/17, 09:09

    > I'd recommend https://github.com/ircmaxell/password_compat which > provides a polyfill for password_verify() and is also resistant to > timing attacks. That is an awesome script indeed, but does not fit our needs here (as the native password_* functions wouldn't either): it handles crypt()-compatible hashes only. Say: it wouldn't fit for PhpassSalt and Pbkdf2Salt, which leaves us with having to include two polyfills then. > It should be a BUGFIX actually and thus should be backported to v7 > in any case. Ok, thanks, I'll change the subject
  11. Christian Futterlieb uploaded patch set 3 02/20/17, 09:13

  12. TYPO3com voted on patch set 3 V +1 02/20/17, 09:21 Completed build in 07m 59s on Mon, 20 Feb, 10:21 AM Test Summary: 56376 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8294

  13. Philipp Gampe commented on patch set 3 CR +1 02/21/17, 17:41

    please get Release Manager approval for this change
  14. Christian Futterlieb commented on patch set 3 02/21/17, 18:27

    > please get Release Manager approval for this change Sorry, I'm not yet familiar with your processes, can you please tell me to whom I have to show this? Thanks.
  15. Benni Mack commented on patch set 3 02/22/17, 19:04

    Personally, I'd do a PHP version check for the 7.6 backport and keep the versoin as is for master. "If you want the enhanced security, go with PHP 5.6", but let's also check with the security team for that.
  16. Benni Mack updated the commit message in patch set 4 02/22/17, 19:05

  17. TYPO3com voted on patch set 4 V +1 02/22/17, 19:15 Completed build in 09m 45s on Wed, 22 Feb, 08:15 PM Test Summary: 56387 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8381

  18. Philipp Gampe voted on patch set 4 CR +1 02/22/17, 22:08

  19. Helmut Hummel commented on patch set 4 CR -1 02/22/17, 22:22

    -1 for a backport to 7.6
  20. Helmut Hummel commented on patch set 4 02/22/17, 22:26

    I'm happy to learn new stuff. but unless someone really proves to me that a timing attack is feasible over the wire (HTTP request), I don't believe this can really be exploited So I'm fine with a change in master of course but would abstain from changing anything in 7.6 in that area (btw. there are tons of hash compares in the code base in other places)
  21. Christian Futterlieb commented on patch set 4 02/23/17, 00:15

    > I'm happy to learn new stuff. but unless someone really proves to > me that a timing attack is feasible over the wire (HTTP request), I > don't believe this can really be exploited It would probably not be an easy attack, and the username must be known to the attacker in advance. Given that, she can learn about the hash stored in the database (or the install tool password) by passing prepared strings and measuring the response time. Assuming, that the used salt is md5, you know, that the input to the hash function is a 12 char (96 bit) salt and the password. Further assuming the length of the password is 8 chars (64 bit), md5 padding is a '1', appended by 287 '0' bits an then the initial message (salt+password) length (as a 64 bit low-byte-first number). So there is a lot of knowledge of the input to md5 which can be used when constructing the input. And with every bit more, that could be learned with the timing attack, it gets easier to find a collision (which could be done offline). Surely the other (non md5 based) salts are more expensive or even unfeasible to find collisions for. But as phpass (based on md5) is the default salting method, as an atttacker, I'd try that first. I'm not an expert in cryptoanalysis. Most likely there are different and more efficient ways to run such an attack. But I hope this could help to convince you for having constant time comparison in 7.6 as well. Besides, symfony/polyfill-php56 is very lightweight. Or we could even implement an equivalent method ourselves without having to require anything. > (btw. there are tons of hash compares in the code base in other > places) That is true. I'd love to help to locate and fix them too (in both branches ;-)).
  22. Christian Futterlieb commented on patch set 4 02/23/17, 00:19

  23. Markus Klein commented on patch set 4 CR -1 02/23/17, 00:43

    PhpassSalt.php:128

    the user supplied hash must be second argument according to docs!
  24. Helmut Hummel commented on patch set 4 02/23/17, 01:11

    > I'd love to help to locate and fix them too (in both branches ;-)). What I want to say is that fixing this now is good as it might prevent *future* exploitations. Exploitation over the internet is impossible nowadays (at least that is what I understood from http://web.archive.org/web/20160126070339/http://blog.astrumfutura.com/2010/10/nanosecond-scale-remote-timing-attacks-on-php-applications-time-to-take-them-seriously/ ) therefore it is great to fix it in master, but please don't do any efforts to fix it in released branches. the chances to break something are much higher than a potential theoretical gain can ever be.
  25. Christian Futterlieb commented on patch set 4 02/23/17, 10:04

    PhpassSalt.php:128 Reply

    The output of cryptPassword() should be treated as the 'known string' input, because we can rely on having a valid hash there. See also: https://github.com/ircmaxell/password_compat/blob/v1.0.4/lib/password.php#L235,L242
  1. Christian Futterlieb commented on patch set 4 02/23/17, 10:23

    > What I want to say is that fixing this now is good as it might > prevent *future* exploitations. > > Exploitation over the internet is impossible nowadays (at least > that is what I understood from http://web.archive.org/web/20160126070339/http://blog.astrumfutura.com/2010/10/nanosecond-scale-remote-timing-attacks-on-php-applications-time-to-take-them-seriously/ > ) One could argue that the article is from 2010 and today we live in the postulated *future*. ;-) Plus: 7.6 will be officially supported even longer. > therefore it is great to fix it in master, but please don't do any > efforts to fix it in released branches. the chances to break > something are much higher than a potential theoretical gain can > ever be. I understand your standpoint well, although I disagree. But I do not insist anymore, there's lots of other stuff to put energy in :-) Therefore: the title must be changed to '[SECURITY][TASK]...', right?
  2. Helmut Hummel voted on patch set 4 CR 0 02/23/17, 11:00

  3. Helmut Hummel commented on patch set 4 02/23/17, 11:07

    > I understand your standpoint well, although I disagree I'm really interested in some proof of concept exploit in that area, using TYPO3 in the current version and testing against localhost > But I do not insist anymore Me neither. I just wanted to point out that this security improvement is no strict requirement for older branches from my pov. But if the risk to break stuff is low enough, why not. I will be the last one to block this.
  4. Helmut Hummel commented on patch set 4 02/23/17, 11:26

    PhpassSalt.php:128 Reply

    $hash is the hash generated with provided user input and $saltedHashPW what we "know" from the database, the provided input must be checked against. So I absolutely get Markus' point here. However, in our case here it does not really matter, because both strings will have the same length (unless the DB value is broken). And, since it is indeed the case, that result of cryptPassword will have the desired length, whereas the DB value could indeed be broken (for various reasons), I'm fine keeping it like that.
  5. Helmut Hummel updated the commit message in patch set 5 02/23/17, 11:27

  6. Helmut Hummel commented on patch set 5 02/23/17, 11:28

    I removed the backport in the commit message, to put this change on a level of agreement. we all agree that this change is good for master. once this is merged, we can open a different change for the backport (which will be very different anyway) and discuss whether and how this can go in there I will now check the tests
  7. TYPO3com voted on patch set 5 V +1 02/23/17, 11:34 Completed build in 07m 29s on Thu, 23 Feb, 12:34 PM Test Summary: 56409 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8394

  8. Helmut Hummel uploaded patch set 6 02/23/17, 11:52

  9. Helmut Hummel uploaded patch set 7 02/23/17, 11:54

  10. TYPO3com voted on patch set 6 V -1 02/23/17, 11:59 Completed build in 07m 03s on Thu, 23 Feb, 12:59 PM Test Summary: 56457 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8398

  11. Helmut Hummel commented on patch set 7 CR +1 V +1 02/23/17, 12:00

    I added some additional tests (just to be sure) and verified, that everything still works like expected by executing the test suit For me, this is good to go now. As I said, this does not mean it can be backported to 7.6, it is just that I don't want to hold back this nice improvement for master
  12. Christian Futterlieb commented on patch set 7 02/23/17, 12:01

    > I added some additional tests (just to be sure) and verified, that > everything still works like expected by executing the test suit > > For me, this is good to go now. As I said, this does not mean it > can be backported to 7.6, it is just that I don't want to hold back > this nice improvement for master Cool, thanks!
  13. Helmut Hummel updated the commit message in patch set 8 02/23/17, 12:02

  14. Helmut Hummel voted on patch set 8 CR +1 V +1 02/23/17, 12:03

  15. Christian Futterlieb commented on patch set 8 02/23/17, 12:03

    As we're in the topic.. can you please take a look at https://review.typo3.org/51740
  16. TYPO3com voted on patch set 7 V -1 02/23/17, 12:03 Completed build in 08m 59s on Thu, 23 Feb, 01:03 PM Test Summary: 56457 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8399

  17. TYPO3com voted on patch set 8 V -1 02/23/17, 12:10 Completed build in 07m 54s on Thu, 23 Feb, 01:10 PM Test Summary: 56457 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8400

  18. Helmut Hummel uploaded patch set 9 02/23/17, 12:49

  19. Helmut Hummel updated the commit message in patch set 10 02/23/17, 12:50

  20. Helmut Hummel commented on patch set 10 CR +1 V +1 02/23/17, 12:50

    Fixed CGL in the tests
  21. TYPO3com voted on patch set 9 V +1 02/23/17, 12:56 Completed build in 07m 21s on Thu, 23 Feb, 01:56 PM Test Summary: 56457 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8404

  22. TYPO3com voted on patch set 10 V +1 02/23/17, 13:01 Completed build in 10m 52s on Thu, 23 Feb, 02:01 PM Test Summary: 56457 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8405

  23. Mads Lønne Jensen voted on patch set 10 CR +1 02/23/17, 13:12

  24. Markus Klein voted on patch set 10 CR +2 V +2 02/23/17, 17:21

  25. Gerrit merged patch set 10 02/23/17, 17:21