diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-18 15:09:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-18 15:09:15 +0300 |
commit | 0637ba1e6e9024f35b2cbf561d9002ec17350bb3 (patch) | |
tree | 960cebf0e892710c1b40f25e249d04aaf8f9b868 /lib | |
parent | 4720b569f0fcbb47e9f1a60e95172ae63b6f065a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/email/attachment_uploader.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/regex.rb | 6 |
2 files changed, 22 insertions, 2 deletions
diff --git a/lib/gitlab/email/attachment_uploader.rb b/lib/gitlab/email/attachment_uploader.rb index 0a14a909e31..d8962ec0d20 100644 --- a/lib/gitlab/email/attachment_uploader.rb +++ b/lib/gitlab/email/attachment_uploader.rb @@ -12,7 +12,7 @@ module Gitlab def execute(upload_parent:, uploader_class:) attachments = [] - message.attachments.each do |attachment| + filter_signature_attachments(message).each do |attachment| tmp = Tempfile.new("gitlab-email-attachment") begin File.open(tmp.path, "w+b") { |f| f.write attachment.body.decoded } @@ -32,6 +32,22 @@ module Gitlab attachments end + + private + + # If this is a signed message (e.g. S/MIME or PGP), remove the signature + # from the uploaded attachments + def filter_signature_attachments(message) + attachments = message.attachments + + if message.content_type&.starts_with?('multipart/signed') + signature_protocol = message.content_type_parameters[:protocol] + + attachments.delete_if { |attachment| attachment.content_type.starts_with?(signature_protocol) } if signature_protocol.present? + end + + attachments + end end end end diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb index fd6e24a96d8..38281fb1c91 100644 --- a/lib/gitlab/regex.rb +++ b/lib/gitlab/regex.rb @@ -112,7 +112,7 @@ module Gitlab # Based on Jira's project key format # https://confluence.atlassian.com/adminjiraserver073/changing-the-project-key-format-861253229.html def jira_issue_key_regex - @jira_issue_key_regex ||= /[A-Z][A-Z_0-9]+-\d+/ + @jira_issue_key_regex ||= /[A-Z][A-Z_0-9]+-\d+\b/ end def jira_transition_id_regex @@ -144,6 +144,10 @@ module Gitlab def utc_date_regex @utc_date_regex ||= /\A[0-9]{4}-[0-9]{2}-[0-9]{2}\z/.freeze end + + def issue + @issue ||= /(?<issue>\d+\b)/ + end end end |