Skip to content

Commit

Permalink
SECURITY: don't allow re-using the current password during password r…
Browse files Browse the repository at this point in the history
…eset
  • Loading branch information
nlalonde committed Aug 24, 2016
1 parent 79245a2 commit 7a81669
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ en:
common: "is one of the 10000 most common passwords. Please use a more secure password."
same_as_username: "is the same as your username. Please use a more secure password."
same_as_email: "is the same as your email. Please use a more secure password."
same_as_current: "is the same as your current password."
ip_address:
signup_not_allowed: "Signup is not allowed from this account."
color_scheme_color:
Expand Down
2 changes: 2 additions & 0 deletions lib/validators/password_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def validate_each(record, attribute, value)
record.errors.add(attribute, :same_as_username)
elsif record.email.present? && value == record.email
record.errors.add(attribute, :same_as_email)
elsif record.confirm_password?(value)
record.errors.add(attribute, :same_as_current)
elsif SiteSetting.block_common_passwords && CommonPasswords.common_password?(value)
record.errors.add(attribute, :common)
end
Expand Down
9 changes: 9 additions & 0 deletions spec/components/validators/password_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@
validate
expect(record.errors[:password]).to be_present
end

it "adds an error when new password is same as current password" do
@password = "mypetsname"
record.save!
record.reload
record.password = @password
validate
expect(record.errors[:password]).to be_present
end
end

context "password not required" do
Expand Down

0 comments on commit 7a81669

Please sign in to comment.