Skip to content

Commit

Permalink
Restrict uninvited signups from configured domains
Browse files Browse the repository at this point in the history
  • Loading branch information
nid90 committed Oct 10, 2023
1 parent 9f251b1 commit 1e281e6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ BILLING_URL=https://billing.stripe.com/p/login
SENTRY_SECURITY_HEADER_ENDPOINT=
SESSION_TIMEOUT_IN_MINUTES=7200
JUNE_ANALYTICS_KEY=
DISALLOWED_SIGN_UP_DOMAINS=
16 changes: 16 additions & 0 deletions app/models/accounts/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,28 @@ class Accounts::User < ApplicationRecord

accepts_nested_attributes_for :organizations

def self.valid_email_domain?(user)
return false if user.email.blank?
begin
disallowed_domains = ENV["DISALLOWED_SIGN_UP_DOMAINS"].split(",")
parsed_email = Mail::Address.new(user.email)
disallowed_domains.include?(parsed_email.domain)

This comment has been minimized.

Copy link
@tachyons

tachyons Oct 10, 2023

Contributor
      disallowed_domains.include?(parsed_email.domain.downcase)

@nid90 Ignoring case insenstive nature of email can cause security issues. Here the user can bypass this restriction by using Gmail.com instead of gmail.com

rescue
false
end
end

def self.onboard(user)
if find_by(email: user.email)
user.errors.add(:account_exists, "you already have an account with tramline!")
return user
end

if valid_email_domain?(user)
user.errors.add(:email, :invalid_domain)
return
end

new_organization = user.organizations.first
new_membership = user.memberships.first
new_organization.status = Accounts::Organization.statuses[:active]
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ en:
not_blank: "The email can't be blank"
already_taken: "This email has already been taken"
too_long: "The email is too long (maximum is 105 characters)"
invalid_domain: "This email domain is invite-only. Please use a different address or contact support!"
accounts/invite:
attributes:
role:
Expand Down

0 comments on commit 1e281e6

Please sign in to comment.