diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-02-02 19:18:12 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-02-02 19:18:12 +0000 |
commit | a58f8c32c62bcf5824d1fe1d0de53e9bda974d65 (patch) | |
tree | 724ed641bc437c9f6133d5555c9766647d8682e3 /app/models/key.rb | |
parent | cd5d75c362cdf06efb8174eddfbd0f4b65687dec (diff) | |
parent | 972f564dcd897ee66799c19f96ed22df588f8a18 (diff) | |
download | gitlab-ce-a58f8c32c62bcf5824d1fe1d0de53e9bda974d65.tar.gz |
Merge branch 'rd-40552-gitlab-should-check-if-keys-are-valid-before-saving' into 'master'
Sanitize extra blank spaces used when uploading a SSH key
Closes #40552
See merge request gitlab-org/gitlab-ce!16821
Diffstat (limited to 'app/models/key.rb')
-rw-r--r-- | app/models/key.rb | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/app/models/key.rb b/app/models/key.rb index 7406c98c99e..ae5769c0627 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -33,9 +33,8 @@ class Key < ActiveRecord::Base after_destroy :refresh_user_cache def key=(value) - value&.delete!("\n\r") - value.strip! unless value.blank? - write_attribute(:key, value) + write_attribute(:key, value.present? ? Gitlab::SSHPublicKey.sanitize(value) : nil) + @public_key = nil end @@ -97,7 +96,7 @@ class Key < ActiveRecord::Base def generate_fingerprint self.fingerprint = nil - return unless self.key.present? + return unless public_key.valid? self.fingerprint = public_key.fingerprint end |