diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2018-10-24 08:52:51 +0000 |
---|---|---|
committer | Thiago Presa <tpresa@gitlab.com> | 2018-10-24 22:01:03 -0300 |
commit | 6dcb2c78beced3336142a53d54e644ac543c3ead (patch) | |
tree | bb742127048efa796a8ce0e0f233dbd33c7eade7 /lib | |
parent | f9c3e5603280b614f1e231f8e2bbae83c68d4a64 (diff) | |
download | gitlab-ce-6dcb2c78beced3336142a53d54e644ac543c3ead.tar.gz |
Merge branch 'security-redact-links-11-2' into 'security-11-2'
[11.2] Redact unsubscribe links in issuable texts
See merge request gitlab/gitlabhq!2567
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/background_migration/redact_links.rb | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/redact_links.rb b/lib/gitlab/background_migration/redact_links.rb new file mode 100644 index 00000000000..f5d3bcdd517 --- /dev/null +++ b/lib/gitlab/background_migration/redact_links.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true +# rubocop:disable Style/Documentation + +module Gitlab + module BackgroundMigration + class RedactLinks + module Redactable + extend ActiveSupport::Concern + + def redact_field!(field) + self[field].gsub!(%r{/sent_notifications/\h{32}/unsubscribe}, '/sent_notifications/REDACTED/unsubscribe') + + if self.changed? + self.update_columns(field => self[field], + "#{field}_html" => nil) + end + end + end + + class Note < ActiveRecord::Base + include EachBatch + include Redactable + + self.table_name = 'notes' + self.inheritance_column = :_type_disabled + end + + class Issue < ActiveRecord::Base + include EachBatch + include Redactable + + self.table_name = 'issues' + self.inheritance_column = :_type_disabled + end + + class MergeRequest < ActiveRecord::Base + include EachBatch + include Redactable + + self.table_name = 'merge_requests' + self.inheritance_column = :_type_disabled + end + + class Snippet < ActiveRecord::Base + include EachBatch + include Redactable + + self.table_name = 'snippets' + self.inheritance_column = :_type_disabled + end + + def perform(model_name, field, start_id, stop_id) + link_pattern = "%/sent_notifications/" + ("_" * 32) + "/unsubscribe%" + model = "Gitlab::BackgroundMigration::RedactLinks::#{model_name}".constantize + + model.where("#{field} like ?", link_pattern).where(id: start_id..stop_id).each do |resource| + resource.redact_field!(field) + end + end + end + end +end |