Skip to content

Update secure_tools.rst #4787

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
wants to merge 3 commits into from
Closed

Update secure_tools.rst #4787

wants to merge 3 commits into from

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Jan 6, 2015

Q A
Doc fix? yes
New docs? no
Applies to 2.3

Fix a critical mistake in the secure_tools doc that can lead to security vulnerabilities.
Using StringUtils::equals() with strings of different lengths can lead to critical timing attacks.

See the following PR for the technical background:
php/php-src#792
symfony/symfony#11822

@stof
Copy link
Member

stof commented Jan 7, 2015

See php/php-src#792 (comment)

This method can still be used to protect the information about the content of strings when comparing them, even though it does not protect the length. Your update of the title will let people think they should compared the length first, which is not the case (and will also leak information).

@dunglas
Copy link
Member Author

dunglas commented Jan 7, 2015

What about changing the title to "comparing hash" (like the PHP functions). Hashes have by definition the same length.

@dunglas
Copy link
Member Author

dunglas commented Jan 7, 2015

Or we can copy the statement of PHP.net/hash_equals:

Note:
Both arguments must be of the same length to be compared successfully. When arguments of differing length are supplied, FALSE is returned immediately and the length of the known string may be leaked in case of a timing attack.

@dunglas
Copy link
Member Author

dunglas commented Mar 11, 2015

Updated the wording according to @stof comments and copied warning from php.net.

@@ -18,13 +18,18 @@ algorithm; you can use the same strategy in your own code thanks to the

use Symfony\Component\Security\Core\Util\StringUtils;

// is some known string (e.g. password) equal to some user input?
$bool = StringUtils::equals($knownString, $userInput);
// is some known string (e.g. password hash) equal to another string (e.g. hash of some user input)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please wrap the comment on two lines?

@dunglas
Copy link
Member Author

dunglas commented Mar 12, 2015

done

// is some known string (e.g. password) equal to some user input?
$bool = StringUtils::equals($knownString, $userInput);
// is some known string (e.g. password hash) equal to another string
// (e.g. hash ofsome user input)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a typo here: "ofsome" should probably be "of some"

@xabbuh
Copy link
Member

xabbuh commented Mar 25, 2015

ping @sarciszewski @ircmaxell It would be nice if you could have a look here.

@ircmaxell
Copy link

Using StringUtils::equals() with strings of different lengths can lead to critical timing attacks.

^^ That's not true. No timing attack exists on the content of the strings. The length leak isn't really anything to worry about because the length is leaked *anyway.

If length is critical to security, there's another problem in your setup. Because you can never depend on length not being leaked (in the general case at least).

@wouterj
Copy link
Member

wouterj commented Mar 25, 2015

@ircmaxell thanks for your comment. If I understand you correctly, you would propose to remove "[...] and the length of the known string may be leaked in case of a timing attack."?

@xabbuh
Copy link
Member

xabbuh commented May 23, 2015

@ircmaxell Can you confirm that we properly understood your suggestion?

@wouterj
Copy link
Member

wouterj commented Aug 22, 2015

@ircmaxell I'm sorry to ping you again on this issue, but can you please confirm if we understood your comment? I don't want to merge something that's wrong according to the security experts :)

@ircmaxell
Copy link

I question the entire premise of the PR? Initially it was to document that different lengths leak timing info. When shown that was not the case, what is this PR intending to do? The original PR's description is incorrect.

And hashing things isn't a magical fix. The hash operations are dependent upon the length, and as such the length will be leaked.

Hence what's the point of this PR?

@dunglas
Copy link
Member Author

dunglas commented Aug 22, 2015

Don't mind this PR I'll close it. But is the current doc OK?

@ircmaxell
Copy link

I don't see any issues about it.

@dunglas dunglas closed this Aug 22, 2015
@dunglas
Copy link
Member Author

dunglas commented Aug 22, 2015

Thank you @ircmaxell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants