Add comprehensive email validation for blocked users#8
Conversation
… many times each email address is blocked, and last time it was blocked. Move email validation out of User model and into EmailValidator. Signup form remembers which email addresses have failed and shows validation error on email field.
Codoki PR ReviewSummary: Make blocked email lookup case-insensitive, prevent bypass Issues (Critical & High only)
Showing top 1 issues. Critical: 0, High: 1. See inline suggestions for more. Key Feedback (click to expand)
Confidence: 3/5 — Needs work before merge (1 high · status: Requires changes) Sequence DiagramsequenceDiagram
participant UserModel
participant EmailValidator
participant BlockedEmail
UserModel->>EmailValidator: validate_each(record, :email, value)
alt whitelist present
EmailValidator-->>UserModel: add :not_allowed error if not matched
else blacklist present
EmailValidator-->>UserModel: add :not_allowed error if matched
end
alt no prior errors
EmailValidator->>BlockedEmail: should_block?(value)
alt blocked
EmailValidator-->>UserModel: add :blocked error
else not blocked
EmailValidator-->>UserModel: no error
end
end
React with 👍 or 👎 if you found this review useful. |
| end | ||
|
|
||
| def self.should_block?(email) | ||
| record = BlockedEmail.where(email: email).first |
There was a problem hiding this comment.
| record = BlockedEmail.where(email: email).first | |
| record = BlockedEmail.where('lower(email) = ?', email.to_s.downcase).first |
|
|
||
| def email_in_restriction_setting?(setting, value) | ||
| domains = setting.gsub('.', '\.') | ||
| regexp = Regexp.new("@(#{domains})", true) |
There was a problem hiding this comment.
🔷 Medium: Use explicit Regexp options for clarity and future compatibility; passing true is non-idiomatic and may be brittle across Ruby versions. Also consider guarding against nil by matching on value.to_s to avoid surprises.
| regexp = Regexp.new("@(#{domains})", true) | |
| regexp = Regexp.new("@(#{domains})", Regexp::IGNORECASE) |
No description provided.