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

Update PasswordEncoder Minimums #10506

Closed
jzheaux opened this issue Nov 15, 2021 · 10 comments · Fixed by #11904
Closed

Update PasswordEncoder Minimums #10506

jzheaux opened this issue Nov 15, 2021 · 10 comments · Fixed by #11904
Assignees
Labels
in: crypto An issue in spring-security-crypto type: enhancement A general enhancement
Milestone

Comments

@jzheaux
Copy link
Contributor

jzheaux commented Nov 15, 2021

Based on #10447 (comment), Argon2PasswordEncoder, ScryptPasswordEncoder, and Pbkdf2PasswordEncoder should have their minimums updated.

Please also see gh-7411 gh-4788

@jzheaux jzheaux added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement in: crypto An issue in spring-security-crypto and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 15, 2021
@jzheaux jzheaux added this to the 6.0.0-M1 milestone Nov 15, 2021
@larsgrefer
Copy link
Contributor

see also #7411 (comment)

@ioanadinuit
Copy link

Hi, did someone take this issue? I would like to contribuite.

@marcusdacoregio marcusdacoregio modified the milestones: 6.0.0-M1, 6.x, 6.0.0-M2 Jan 17, 2022
@jzheaux
Copy link
Contributor Author

jzheaux commented Jan 22, 2022

@ioanadinuit, thanks for volunteering! The ticket is yours.

One thing we need to keep in mind is what will happen to folks when they upgrade to Spring Security 6.

Ideally, existing hashes will still work which is not as simple with Pbkdf2PasswordEncoder, which does not support upgrading. It may be necessary to implement #9833 before changing PBKDF2 default settings.

@jzheaux
Copy link
Contributor Author

jzheaux commented Jan 31, 2022

@Sc00bz, I'd prefer to go off of the recommendations on the OWASP cheat sheet. They vary just slightly from your recommendations in your comment. Do you have any concerns with going with the recommendations from the cheat sheet?

@rwinch
Copy link
Member

rwinch commented Jun 7, 2022

Please also see gh-7411

@Sc00bz
Copy link

Sc00bz commented Jun 8, 2022

@jzheaux That OWASP cheat sheet is based on my recommendations.

The four changes I suggested to this project's defaults:


Argon2's setting are m=4 MiB, t=3, p=1 either set it to 10 MiB or 7 iterations.

OWASP cheat sheet has for Argon2:

m=37 MiB, t=1, p=1
m=15 MiB, t=2, p=1

The curator trimmed the list at the first two. Numbers came from these formulas:
Argon2i: m≥74219/(3*t-1)*α, t≥3, p=1
Argon2{id,d}: m≥74219/(3*t-1)*α, t≥1, p=1

m≥36.24 MiB, t=1, p=1
m≥14.50 MiB, t=2, p=1
m≥9.06 MiB, t=3, p=1 ****
...
m≥4.26 MiB, t=6, p=1
m≥3.62 MiB, t=7, p=1 ****


scrypt's settings are N=2^14, r=8, p=1 (16 MiB) either set N to 2^16 (64 MiB) or p to 4.

OWASP cheat sheet has for scrypt:

N=2^16 (64 MiB), r=8 (1024 bytes), p=1 ****
N=2^15 (32 MiB), r=8 (1024 bytes), p=2
N=2^14 (16 MiB), r=8 (1024 bytes), p=4 ****
...


PBKDF2 settings are SHA1, 185k iterations, 256 bits of output. This should be changed to SHA512 and 120k iterations.

OWASP cheat sheet has for PBKDF2:

PBKDF2-HMAC-SHA1: 720,000 iterations
PBKDF2-HMAC-SHA256: 310,000 iterations
PBKDF2-HMAC-SHA512: 120,000 iterations ****

Note using SHA512 is better than the others if the one calculating it has a 64 bit CPU. SHA1 and SHA256 are better if the one calculating it has CPU instructions for them.


bcrypt setting is cost 10. Cost 9 is actually quite strong and is similar to PBKDF2-SHA512 with 230k iterations in strength.

It was a hard fought battle to get the recommended down to cost 10. Note cost "8.1" is the minimum for bcrypt, but it's an integer so 9.


P.S. A new GPU came out since those recommendations. It's ~3% faster compute and 20% more memory bandwidth.

Argon2 m=4 MiB, t=7, p=1 is now m=4 MiB, t=8, p=1.
Argon2 m=10 MiB, t=3, p=1 is now m=11 MiB, t=3, p=1.
scrypt N=2^16 (64 MiB), r=8 (1024 bytes), p=1 is now N=2^17 (128 MiB), r=8 (1024 bytes), p=1
scrypt N=2^14 (16 MiB), r=8 (1024 bytes), p=4 is now N=2^14 (16 MiB), r=8 (1024 bytes), p=5
PBKDF2-HMAC-SHA512 120,000 iterations is now 130,000 iterations.
bcrypt is still cost 9.

Note this is how minimums work. Normally every year a new GPU comes out that's 20%+ faster. Last few years have been abnormal. If I were to guess, I'd guess there's going to be a jump in minimums around October.

@rwinch
Copy link
Member

rwinch commented Jun 8, 2022

Please see gh-4788

@rwinch
Copy link
Member

rwinch commented Jun 8, 2022

@Sc00bz Thanks for the updated numbers. The trouble is that we don't know what hardware users are leveraging to run their servers and minimums are a tradeoff. The attackers will always have better optimized hardware for cracking than the defenders will for validating passwords because the defenders need to do more than passwords and it is unlikely they will leverage GPUs. It's all about trade offs. Using a workfactor that is too large will potentially cause a DoS for the application servers.

The best we can do is follow the guidance for now and ensure we can support upgrading in the future. This is why we are also looking to implement gh-9833

@Sc00bz
Copy link

Sc00bz commented Jun 8, 2022

... the defenders need to do more than passwords and it is unlikely they will leverage GPUs.

Argon2, bcrypt, PBKDF2, and scrypt can't run on a GPU for the defender. Well they could but it would be very slow. Minimums are set to prevent attackers from getting >10 kH/s/GPU.

Using a workfactor that is too large will potentially cause a DoS for the application servers.

Note bcrypt cost 9 is super fast because it is a good algorithm. PBKDF2-HMAC-SHA512 with 130,000 iterations is slow because PBKDF2 is a bad algorithm. If bad algorithms are causing DoS issues, then you should deprecate those algorithms.

@jzheaux jzheaux self-assigned this Jun 21, 2022
@jgrandja jgrandja added type: breaks-passivity A change that breaks passivity with the previous release and removed type: enhancement A general enhancement labels Sep 26, 2022
@jgrandja jgrandja added type: bug A general bug and removed type: breaks-passivity A change that breaks passivity with the previous release labels Oct 3, 2022
jgrandja added a commit to jgrandja/spring-security that referenced this issue Oct 4, 2022
The recommended minimums for Argon2, as per OWASP Cheat Sheet Series (https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html), are:
Use Argon2id with a minimum configuration of 15 MiB of memory, an iteration count of 2, and 1 degree of parallelism.

Previous default configuration:
memory=4, iterations=3, parallelism=1

New default configuration:
memory=16, iterations=2, parallelism=1

Issue spring-projectsgh-10506
jgrandja added a commit to jgrandja/spring-security that referenced this issue Oct 4, 2022
The recommended minimums for scrypt, as per OWASP Cheat Sheet Series (https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html), are:
Use scrypt with a minimum CPU/memory cost parameter of (2^16), a minimum block size of 8 (1024 bytes), and a parallelization parameter of 1.

Previous default configuration:
cpuCost=16384, memoryCost=8, parallelism=1

New default configuration:
cpuCost=65536, memoryCost=8, parallelism=1

The default salt length was also updated from 64 to 16.

Issue spring-projectsgh-10506
jgrandja added a commit to jgrandja/spring-security that referenced this issue Oct 4, 2022
The recommended minimums for PBKDF2, as per OWASP Cheat Sheet Series (https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html), are:
If FIPS-140 compliance is required, use PBKDF2 with a work factor of 310,000 or more and set with an internal hash function of HMAC-SHA-256.

Previous default configuration:
algorithm=SHA1, iterations=185000, hashLength=256

New default configuration:
algorithm=SHA256, iterations=310000, hashLength=256

The default salt length was also updated from 8 to 16.

Issue spring-projectsgh-10506
@jgrandja jgrandja modified the milestones: 6.0.0-RC1, 5.8.0-RC1 Oct 5, 2022
@jgrandja jgrandja added type: enhancement A general enhancement and removed type: bug A general bug labels Oct 12, 2022
jgrandja added a commit to jgrandja/spring-security that referenced this issue Oct 12, 2022
The recommended minimums for Argon2, as per OWASP Cheat Sheet Series (https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html), are:
Use Argon2id with a minimum configuration of 15 MiB of memory, an iteration count of 2, and 1 degree of parallelism.

Previous default configuration:
memory=4, iterations=3, parallelism=1

New default configuration:
memory=16, iterations=2, parallelism=1

Issue spring-projectsgh-10506
jgrandja added a commit to jgrandja/spring-security that referenced this issue Oct 12, 2022
The recommended minimums for scrypt, as per OWASP Cheat Sheet Series (https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html), are:
Use scrypt with a minimum CPU/memory cost parameter of (2^16), a minimum block size of 8 (1024 bytes), and a parallelization parameter of 1.

Previous default configuration:
cpuCost=16384, memoryCost=8, parallelism=1

New default configuration:
cpuCost=65536, memoryCost=8, parallelism=1

The default salt length was also updated from 64 to 16.

Issue spring-projectsgh-10506
jgrandja added a commit that referenced this issue Oct 12, 2022
jzheaux added a commit that referenced this issue Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: crypto An issue in spring-security-crypto type: enhancement A general enhancement
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

8 participants