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

feat: rework the OTP code submit count mechanism #4251

Merged
merged 5 commits into from
Dec 23, 2024

Conversation

alnr
Copy link
Contributor

@alnr alnr commented Dec 19, 2024

Unlike what the previous comment suggested, incrementing and checking the submit count inside the database transaction is not actually optimal peformance- or security-wise.

We now check atomically increment and check the submit count as the first part of the operation, and abort as early as possible if we detect brute-forcing. This prevents a situation where the check works only on certain transaction isolation levels.

@alnr alnr self-assigned this Dec 19, 2024
Copy link

codecov bot commented Dec 19, 2024

Codecov Report

Attention: Patch coverage is 88.23529% with 6 lines in your changes missing coverage. Please review.

Project coverage is 78.62%. Comparing base (d9f6f75) to head (b094bdc).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
persistence/sql/persister_code.go 89.65% 2 Missing and 1 partial ⚠️
selfservice/strategy/code/test/persistence.go 87.50% 1 Missing and 1 partial ⚠️
identity/extension_verification.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4251   +/-   ##
=======================================
  Coverage   78.61%   78.62%           
=======================================
  Files         381      381           
  Lines       27318    27344   +26     
=======================================
+ Hits        21476    21498   +22     
- Misses       4223     4227    +4     
  Partials     1619     1619           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alnr alnr force-pushed the alnr/otp-code-submit-count branch 2 times, most recently from 7c1bba6 to b52a09c Compare December 19, 2024 16:54
alnr added 3 commits December 20, 2024 11:00
Unlike what the previous comment suggested, incrementing and checking the submit count inside the
database transaction is not actually optimal peformance- or security-wise.

We now check atomically increment and check the submit count as the first part of the operation,
and abort as early as possible if we detect brute-forcing. This prevents a situation where the
check works only on certain transaction isolation levels.
@alnr alnr force-pushed the alnr/otp-code-submit-count branch from b52a09c to 5600b49 Compare December 20, 2024 10:00
persistence/sql/persister_code.go Outdated Show resolved Hide resolved
@alnr alnr force-pushed the alnr/otp-code-submit-count branch from 2c6dc15 to e70ecf3 Compare December 23, 2024 10:23
@alnr alnr enabled auto-merge (squash) December 23, 2024 11:47
@alnr alnr merged commit 4ca4d79 into master Dec 23, 2024
29 checks passed
@alnr alnr deleted the alnr/otp-code-submit-count branch December 23, 2024 12:37
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