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

fix: unreliable HIBP caching strategy #2468

Merged
merged 1 commit into from
May 16, 2022
Merged

fix: unreliable HIBP caching strategy #2468

merged 1 commit into from
May 16, 2022

Conversation

zepatrik
Copy link
Member

No description provided.

@zepatrik zepatrik requested a review from aeneasr as a code owner May 13, 2022 15:47
@@ -107,20 +111,20 @@ func lcsLength(a, b string) int {
return greatestLength
}

func (s *DefaultPasswordValidator) fetch(hpw []byte, apiDNSName string) error {
func (s *DefaultPasswordValidator) fetch(hpw []byte, apiDNSName string) (int64, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Returning the count here does not rely on the cache having the value in the recursive run.

})

// verify the fetch was done, i.e. channel is empty
Copy link
Member Author

Choose a reason for hiding this comment

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

We had some fishy cases, therefore we ensure here the fetch was done.
Especially the first two cases had the same password, therefore cache hit.

@codecov
Copy link

codecov bot commented May 13, 2022

Codecov Report

Merging #2468 (a2277eb) into master (50bdba9) will increase coverage by 0.00%.
The diff coverage is 97.22%.

❗ Current head a2277eb differs from pull request most recent head 1f0cf06. Consider uploading reports for the commit 1f0cf06 to get more accurate results

@@           Coverage Diff           @@
##           master    #2468   +/-   ##
=======================================
  Coverage   76.52%   76.53%           
=======================================
  Files         316      316           
  Lines       17596    17603    +7     
=======================================
+ Hits        13465    13472    +7     
  Misses       3197     3197           
  Partials      934      934           
Impacted Files Coverage Δ
selfservice/flow/login/handler.go 80.83% <ø> (ø)
selfservice/strategy/password/validator.go 92.77% <92.30%> (+0.27%) ⬆️
courier/smtp.go 75.00% <100.00%> (+0.42%) ⬆️
driver/config/config.go 82.05% <100.00%> (+0.05%) ⬆️
ui/node/attributes.go 60.86% <100.00%> (ø)
ui/node/node.go 90.65% <100.00%> (ø)
persistence/sql/persister_courier.go 89.70% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9a969fd...1f0cf06. Read the comment docs.

}
}

s.hashes.SetWithTTL(prefix+result[0], count, 1, hashCacheItemTTL)
if prefix+result[0] == b20(hpw) {
Copy link
Member

Choose a reason for hiding this comment

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

What is this check good for?

Copy link
Member Author

Choose a reason for hiding this comment

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

thisCount is the count of the actual password. We fetch a whole range of password hashes and add it to the cache. It could be that there is not a hit at all. In that case we want to return zero. But in case of a hit, we want to update thisCount before returning, which this if does.

@aeneasr aeneasr merged commit 93bf1e2 into master May 16, 2022
@aeneasr aeneasr deleted the fix/pw-hash-cache branch May 16, 2022 16:03
peturgeorgievv pushed a commit to senteca/kratos-fork that referenced this pull request Jun 30, 2023
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.

None yet

2 participants