Commit 182aa19e26cbc77b3cc7f10f0c228ea4aa2d7c77
1 parent
3f3b202c
Exists in
master
and in
4 other branches
Parse all refs when do push via HTTP and check permissions for all of them
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
1 changed file
with
14 additions
and
10 deletions
Show diff stats
lib/gitlab/backend/grack_auth.rb
@@ -82,13 +82,17 @@ module Grack | @@ -82,13 +82,17 @@ module Grack | ||
82 | when 'git-upload-pack' | 82 | when 'git-upload-pack' |
83 | project.public || can?(user, :download_code, project) | 83 | project.public || can?(user, :download_code, project) |
84 | when'git-receive-pack' | 84 | when'git-receive-pack' |
85 | - action = if project.protected_branch?(ref) | ||
86 | - :push_code_to_protected_branches | ||
87 | - else | ||
88 | - :push_code | ||
89 | - end | 85 | + refs.each do |ref| |
86 | + action = if project.protected_branch?(ref) | ||
87 | + :push_code_to_protected_branches | ||
88 | + else | ||
89 | + :push_code | ||
90 | + end | ||
91 | + | ||
92 | + return false unless can?(user, action, project) | ||
93 | + end | ||
90 | 94 | ||
91 | - can?(user, action, project) | 95 | + true |
92 | else | 96 | else |
93 | false | 97 | false |
94 | end | 98 | end |
@@ -108,11 +112,11 @@ module Grack | @@ -108,11 +112,11 @@ module Grack | ||
108 | @project ||= project_by_path(@request.path_info) | 112 | @project ||= project_by_path(@request.path_info) |
109 | end | 113 | end |
110 | 114 | ||
111 | - def ref | ||
112 | - @ref ||= parse_ref | 115 | + def refs |
116 | + @refs ||= parse_refs | ||
113 | end | 117 | end |
114 | 118 | ||
115 | - def parse_ref | 119 | + def parse_refs |
116 | input = if @env["HTTP_CONTENT_ENCODING"] =~ /gzip/ | 120 | input = if @env["HTTP_CONTENT_ENCODING"] =~ /gzip/ |
117 | Zlib::GzipReader.new(@request.body).read | 121 | Zlib::GzipReader.new(@request.body).read |
118 | else | 122 | else |
@@ -121,7 +125,7 @@ module Grack | @@ -121,7 +125,7 @@ module Grack | ||
121 | 125 | ||
122 | # Need to reset seek point | 126 | # Need to reset seek point |
123 | @request.body.rewind | 127 | @request.body.rewind |
124 | - /refs\/heads\/([\/\w\.-]+)/n.match(input.force_encoding('ascii-8bit')).to_a.last | 128 | + input.force_encoding('ascii-8bit').scan(/refs\/heads\/([\/\w\.-]+)/n).flatten.compact |
125 | end | 129 | end |
126 | end | 130 | end |
127 | end | 131 | end |