Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Chao <mchao@gitlab.com>2019-04-10 06:39:45 +0300
committerMark Chao <mchao@gitlab.com>2019-05-02 22:02:58 +0300
commitd8bddb16624f34600069bb5d3540960b25176381 (patch)
tree6e38172e12eb8d5a5c1645b30cccdda9f7f08809 /app/models/merge_request.rb
parent74ac04a6aa7a9398ed908f47080e64ec40e0dee8 (diff)
Validate MR branch names
Prevents refspec as branch name, which would bypass branch protection when used in conjunction with rebase. HEAD seems to be a special case with lots of occurrence, so it is considered valid for now. Another special case is `refs/head/*`, which can be imported.
Diffstat (limited to 'app/models/merge_request.rb')
-rw-r--r--app/models/merge_request.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 458c57c1dc6..368772a5cf4 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -620,6 +620,8 @@ class MergeRequest < ApplicationRecord
return
end
+ [:source_branch, :target_branch].each { |attr| validate_branch_name(attr) }
+
if opened?
similar_mrs = target_project
.merge_requests
@@ -640,6 +642,16 @@ class MergeRequest < ApplicationRecord
end
end
+ def validate_branch_name(attr)
+ return unless changes_include?(attr)
+
+ branch = read_attribute(attr)
+
+ return unless branch
+
+ errors.add(attr) unless Gitlab::GitRefValidator.validate_merge_request_branch(branch)
+ end
+
def validate_target_project
return true if target_project.merge_requests_enabled?