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

raise bcrypt cost factor lower bound to x/crypto/bcrypt default #321

Merged
merged 1 commit into from
Oct 25, 2018

Conversation

adamdecaf
Copy link
Contributor

Proposed changes

Users of this library could easily create the following:

hasher := fosite.BCrypt{}
hasher.Hash(..)

This is a problem because WorkFactor will default to 0 and x/crypto/bcrypt will default that to 4 (See https://godoc.org/golang.org/x/crypto/bcrypt). Instead this should be some higher cost factor.

I didn't use config.GetHashCost() because that's in another package.

Callers who need a lower WorkFactor can still lower the cost, if needed.

Checklist

  • I have read the contributing guidelines
  • I confirm that this pull request does not address a security vulnerability. If this pull request addresses a security
    vulnerability, I confirm that I got green light (please contact [email protected]) from the maintainers to push the changes.
  • I signed the Developer's Certificate of Origin
    by signing my commit(s). You can amend your signature to the most recent commit by using git commit --amend -s. If you
    amend the commit, you might need to force push using git push --force HEAD:<branch>. Please be very careful when using
    force push.
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation within the code base (if appropriate)

@adamdecaf
Copy link
Contributor Author

FYI I already emailed the security contact about this.

@adamdecaf adamdecaf force-pushed the bcrypt-default-cost-factor branch from d1e7cd1 to 3388bed Compare October 25, 2018 19:15
hash_bcrypt.go Outdated
@@ -34,6 +34,9 @@ type BCrypt struct {
}

func (b *BCrypt) Hash(ctx context.Context, data []byte) ([]byte, error) {
if b.WorkFactor == 0 {
b.WorkFactor = bcrypt.DefaultCost
Copy link
Member

Choose a reason for hiding this comment

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

Since we're defaulting to 12 I think this should also be 12. Potentially as a shared const

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking of that too. Where should that live?

Copy link
Member

Choose a reason for hiding this comment

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

Hm, in the hasher package?

Users of this library can easily create the following:

hasher := fosite.BCrypt{}
hasher.Hash(..)

This is a problem because WorkFactor will default to 0 and x/crypto/bcrypt will default that to 4 (See https://godoc.org/golang.org/x/crypto/bcrypt).

Instead this should be some higher cost factor. Callers who need a lower WorkFactor can still lower the cost, if needed.

Signed-off-by: Adam Shannon <[email protected]>
@adamdecaf adamdecaf force-pushed the bcrypt-default-cost-factor branch from 3388bed to 33fcf9c Compare October 25, 2018 19:29
@aeneasr
Copy link
Member

aeneasr commented Oct 25, 2018

Thanks!

@aeneasr aeneasr merged commit 799fc70 into ory:master Oct 25, 2018
@adamdecaf adamdecaf deleted the bcrypt-default-cost-factor branch October 25, 2018 20:50
budougumi0617 added a commit to budougumi0617/fosite that referenced this pull request May 10, 2019
Users of this library can easily create the following:

hasher := fosite.BCrypt{}
hasher.Hash(..)

This is a problem because WorkFactor will default to 0 and x/crypto/bcrypt will default that to 4 (See https://godoc.org/golang.org/x/crypto/bcrypt).

Instead this should be some higher cost factor. Callers who need a lower WorkFactor can still lower the cost, if needed.

Signed-off-by: Adam Shannon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants