Skip to content
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

Limit size of password sent to zxcvbn to prevent lock ups #7712

Closed
smason opened this issue Mar 29, 2022 · 11 comments · Fixed by #7748
Closed

Limit size of password sent to zxcvbn to prevent lock ups #7712

smason opened this issue Mar 29, 2022 · 11 comments · Fixed by #7748
Labels

Comments

@smason
Copy link

smason commented Mar 29, 2022

Overview

I enabled "secret service" integration, and some users of this service seem to store some very long JSON objects as their "password". this makes all interactions incredibly slow when the strength meter is enabled.

Steps to Reproduce

create a "password" containing an 8kib password

this causes the UI to hang for a minute or so which doesn't seem great!

Context

can reproduce under Linux (wayland) I've just built from develop branch. issue goes away with:

diff --git a/src/zxcvbn/zxcvbn.c b/src/zxcvbn/zxcvbn.c
index 23792b4d..0d2c9893 100644
--- a/src/zxcvbn/zxcvbn.c
+++ b/src/zxcvbn/zxcvbn.c
@@ -1577,6 +1577,11 @@ double ZxcvbnMatch(const char *Pwd, const char *UserDict[], ZxcMatch_t **Info)
     i = Cardinality(Passwd, Len);
     e = log((double)i);
 
+       if (Len > 64) {
+               fprintf(stderr, "not checking strength password, length=%i\n", Len);
+               return e;
+       }
+
     /* Do matching for all parts of the password */
     for(i = 0; i < Len; ++i)
     {
@smason smason added the bug label Mar 29, 2022
@droidmonkey
Copy link
Member

Agree that we should just truncate that input to zxcvbn at some length (probably 999).

This requires explanation:

some users of this service seem to store some very long JSON objects as their "password"

@droidmonkey droidmonkey changed the title password strength meter makes UI unresponsive Limit size of password sent to zxcvbn to prevent lock ups Mar 29, 2022
@smason
Copy link
Author

smason commented Mar 29, 2022

Agree that we should just truncate that input to zxcvbn at some length (probably 999).

why is it even worth bothering to calculate entropy of anything that long? i.e. how is any attacker going go about "guessing" 1 kilobyte of text? the authors of zxcvbn suggest 100 characters:

To bound runtime latency for really long passwords, consider sending zxcvbn() only the first 100 characters or so of user input.

not sure why it doesn't just bail itself and return entropy as something as log2(ndistinct) * Len, where ndistinct is the number of distinct code points seen in the password.

This requires explanation:

some users of this service seem to store some very long JSON objects as their "password"

not sure what explanation you want... some arbitrary program (I think it's minecraft) uses the freedesktop Secrets API to store multiple values in a manner as suggested by the spec:

Applications wishing to store multiple values as part of a single secret, may choose to use a textual format to combine these values into one. For example, the 'desktop' key file format, or XML or another form of markup.

in practice it's using JSON to encode these values, and maybe pushing the spec a bit far by wanting to store that much, but otherwise it seems OK

@droidmonkey
Copy link
Member

why is it even worth bothering to calculate entropy of anything that long? i.e. how is any attacker going go about "guessing" 1 kilobyte of text? the authors of zxcvbn suggest 100 characters:

It's not worth it, but trust me when I say some of our users are... excessive... and VERY vocal about it. Why do you think we even allow passwords with length 999? That was a very dramatic conversation between multiple parties demanding passwords of length greater than 128 characters.

@smason
Copy link
Author

smason commented Mar 29, 2022

you should certainly allow password entries of arbitrary length, not sure why you think I don't like that

it's just estimating entropy of long passwords via the zxcvbn library that takes a very long time. it's only the entropy estimation I'm talking about!

@phoerious
Copy link
Member

phoerious commented Mar 29, 2022

you should certainly allow password entries of arbitrary length, not sure why you think I don't like that

Passwords of that length are useless. Anything that has a larger keyspace than the hash derived from it is a waste of space and computing time.

@smason
Copy link
Author

smason commented Mar 29, 2022

@phoerious yup, wanting more than 256 bits of entropy in your secret seems to be considered meaningless, hence why it's the highest security target of sane cryptographic systems at the moment.

but these entries aren't passwords in any conventional sense, but they should be considered sensitive and hence it makes sense to look after them, just not calculate entropy

@droidmonkey I've have had a quick play, and the following Python code can be used generate a password that can take many seconds to calculate:

base64.b64encode(random.randbytes(num_bytes))

setting num_bytes to 5000 takes my laptop ~17 seconds, while 8000 unencoded bytes takes ~75 seconds.

estimating entropy via the code I gave above in Python, i.e.:

math.log2(len(set(pwd))) * len(pwd)

gives a good approximation to zxcvbn, for example:

input  entropy via
bytes python zxcvbn
8000   64246  59629
5000   40157  37374
3000   24000  22222
1000    8045   7426
 500    4022   3737
 200    1613   1478
 100     789    733

note that these are random bytes, so there will be some variance, but they track each other pretty well hence it seems reasonable to use this for "long" passwords

@phoerious
Copy link
Member

If you store things that are not passwords in KeePassXC, I would suggest using appropriately named custom string fields instead.

@droidmonkey
Copy link
Member

Or attachments or notes

@smason
Copy link
Author

smason commented Mar 29, 2022

I'm not setting them myself, they're coming from other programs via your "secret service" integration.

I've had a look in your source code, and it looks like FdoSecrets::setEntrySecret is the method that gets called, maybe it could be doing something else when it gets passed a long "secret"?

@smason
Copy link
Author

smason commented Mar 29, 2022

that said, the UI shouldn't lock up for a minute if the user accidentally copy/pastes a long value into a field...

@smason
Copy link
Author

smason commented Apr 7, 2022

the upstream package tsyrogit/zxcvbn-c#28 made a change that returns results in milliseconds now, it might be easier to just pull in the latest version of their code

droidmonkey pushed a commit to libklein/keepassxc that referenced this issue May 28, 2022
Limit the use of zxcvbn based password entropy estimation to 256 bytes. After this threshold, the average per-byte entropy from the zxcvbn calculation is added for each additional byte. In practice, this produces a slightly higher entropy calculation for purely randomized passwords than zxcvbn would normally calculate. However, the time to calculate is capped leading to a much better user experience and removing unnecessary calculations.

Fixes keepassxreboot#7712
droidmonkey pushed a commit to libklein/keepassxc that referenced this issue May 28, 2022
Limit the use of zxcvbn based password entropy estimation to 256 bytes. After this threshold, the average per-byte entropy from the zxcvbn calculation is added for each additional byte. In practice, this produces a slightly higher entropy calculation for purely randomized passwords than zxcvbn would normally calculate. However, the time to calculate is capped leading to a much better user experience and removing unnecessary calculations.

Fixes keepassxreboot#7712
droidmonkey pushed a commit that referenced this issue May 30, 2022
Limit the use of zxcvbn based password entropy estimation to 256 bytes. After this threshold, the average per-byte entropy from the zxcvbn calculation is added for each additional byte. In practice, this produces a slightly higher entropy calculation for purely randomized passwords than zxcvbn would normally calculate. However, the time to calculate is capped leading to a much better user experience and removing unnecessary calculations.

Fixes #7712
pull bot pushed a commit to tigerwill90/keepassxc that referenced this issue May 30, 2022
Limit the use of zxcvbn based password entropy estimation to 256 bytes. After this threshold, the average per-byte entropy from the zxcvbn calculation is added for each additional byte. In practice, this produces a slightly higher entropy calculation for purely randomized passwords than zxcvbn would normally calculate. However, the time to calculate is capped leading to a much better user experience and removing unnecessary calculations.

Fixes keepassxreboot#7712
pull bot pushed a commit to soitun/keepassxc that referenced this issue May 30, 2022
Limit the use of zxcvbn based password entropy estimation to 256 bytes. After this threshold, the average per-byte entropy from the zxcvbn calculation is added for each additional byte. In practice, this produces a slightly higher entropy calculation for purely randomized passwords than zxcvbn would normally calculate. However, the time to calculate is capped leading to a much better user experience and removing unnecessary calculations.

Fixes keepassxreboot#7712
droidmonkey pushed a commit that referenced this issue Jun 27, 2022
Limit the use of zxcvbn based password entropy estimation to 256 bytes. After this threshold, the average per-byte entropy from the zxcvbn calculation is added for each additional byte. In practice, this produces a slightly higher entropy calculation for purely randomized passwords than zxcvbn would normally calculate. However, the time to calculate is capped leading to a much better user experience and removing unnecessary calculations.

Fixes #7712
t-h-e pushed a commit to t-h-e/keepassxc that referenced this issue Sep 8, 2022
Limit the use of zxcvbn based password entropy estimation to 256 bytes. After this threshold, the average per-byte entropy from the zxcvbn calculation is added for each additional byte. In practice, this produces a slightly higher entropy calculation for purely randomized passwords than zxcvbn would normally calculate. However, the time to calculate is capped leading to a much better user experience and removing unnecessary calculations.

Fixes keepassxreboot#7712
droidmonkey pushed a commit that referenced this issue Sep 22, 2022
Limit the use of zxcvbn based password entropy estimation to 256 bytes. After this threshold, the average per-byte entropy from the zxcvbn calculation is added for each additional byte. In practice, this produces a slightly higher entropy calculation for purely randomized passwords than zxcvbn would normally calculate. However, the time to calculate is capped leading to a much better user experience and removing unnecessary calculations.

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

Successfully merging a pull request may close this issue.

3 participants