Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implement rate limiting for e-mail verifications#8419

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
LawnGnome wants to merge1 commit intorust-lang:main
base:main
Choose a base branch
Loading
fromLawnGnome:e-mail-throttling

Conversation

LawnGnome
Copy link
Contributor

This applies a burst of 3 and a refill time of 30 minutes by default per user. (Not that I can imagine a scenario where we'd ever override this for a user, but using the same machinery as other user actions is obviously much simpler.)

I don't love that this ends up essentially prop-drilling the rate limiter into a bunch of new places, but I don't see an alternative other than prop-drilling the whole app struct through, which would be worse.

This doesn't address (sorry) per-address rate limiting, but is at least a reasonable starting point.

This applies a burst of 3 and a refill time of 30 minutes by defaultper user. (Not that I can imagine a scenario where we'd ever overridethis for a user, but using the same machinery as other user actions isobviously much simpler.)I don't love that this ends up essentially prop-drilling the ratelimiter into a bunch of new places, but I don't see an alternative otherthan prop-drilling the whole app struct through, which would be worse.This doesn't address (sorry) per-address rate limiting, but is at leasta reasonable starting point.
@LawnGnomeLawnGnome added C-enhancement ✨Category: Adding new behavior or a change to the way an existing feature works A-backend ⚙️ labelsApr 9, 2024
@LawnGnomeLawnGnome requested a review froma teamApril 9, 2024 00:42
@codecovCodecov
Copy link

codecovbot commentedApr 9, 2024
edited
Loading

Codecov Report

Attention: Patch coverage is89.61039% with16 lines in your changes missing coverage. Please review.

Project coverage is 87.63%. Comparing base(61c0870) to head(27637ae).
Report is 3963 commits behind head on main.

Files with missing linesPatch %Lines
src/controllers/user/me.rs74.07%7 Missing⚠️
src/controllers/user/session.rs41.66%7 Missing⚠️
src/rate_limiter.rs94.87%2 Missing⚠️
Additional details and impacted files
@@            Coverage Diff             @@##             main    #8419      +/-   ##==========================================+ Coverage   87.62%   87.63%   +0.01%==========================================  Files         272      272                Lines       26333    26426      +93     ==========================================+ Hits        23073    23158      +85- Misses       3260     3268       +8

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

🚀 New features to boost your workflow:
  • ❄️Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Turbo87
Copy link
Member

I don't love that this ends up essentially prop-drilling the rate limiter into a bunch of new places, but I don't see an alternative other than prop-drilling the whole app struct through, which would be worse.

I think the root cause of this is that the model layer is currently sending emails, which IMHO is a bit questionable, especially because we're using this code path in a couple of places in the test suite too. It might be better to decouple these things first before introducing the rate limiting.

@LawnGnome
Copy link
ContributorAuthor

I think the root cause of this is that the model layer is currently sending emails, which IMHO is a bit questionable, especially because we're using this code path in a couple of places in the test suite too. It might be better to decouple these things first before introducing the rate limiting.

Yeah, I went back and forth on this yesterday — decoupling the e-mail sending out of the model layer is better from an architectural perspective, but it means theNewUser::create_or_update API is easier to misuse as it stands, since it now comes with an implicit need to figure out if the e-mail address needs verification after and action that.

The e-mail upsert code could be extracted into something that returns that state, but being in the same transaction as the user upsert is obviously a nice quality that would be bad to lose.

I'm sorta wondering if we end up with something like this (treat names as placeholders):

let new_user =NewUser::new(...);let updater = new_user.create_or_update(&conn)?;// returns some intermediate type holding a transactionlet verification_required = updater.set_email(&email)?;// needs to be optional since not all updates might touch the e-mail?updater.commit()?;// consumes updater// Has to be after the commit;if verification_required{// send verification e-mail}

Another, simpler option would obviously be to return something else fromcreate_or_update than just theUser — a struct enclosing theUser along with abool field indicating if verification is required.

Now I've typed this out, I probably have a slight preference for the second option (return something enclosingUser and whatever other state we need), but I'm interested in what you think.

@bors
Copy link
Contributor

☔ The latest upstream changes (presumably77d55e9) made this pull request unmergeable. Pleaseresolve the merge conflicts.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
A-backend ⚙️C-enhancement ✨Category: Adding new behavior or a change to the way an existing feature works
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@LawnGnome@Turbo87@bors

[8]ページ先頭

©2009-2025 Movatter.jp