diff options
Diffstat (limited to 'app/controllers/projects/git_http_controller.rb')
-rw-r--r-- | app/controllers/projects/git_http_controller.rb | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/app/controllers/projects/git_http_controller.rb b/app/controllers/projects/git_http_controller.rb index be73a4c0d2c..a10dca6afaf 100644 --- a/app/controllers/projects/git_http_controller.rb +++ b/app/controllers/projects/git_http_controller.rb @@ -9,9 +9,9 @@ class Projects::GitHttpController < Projects::GitHttpClientController elsif receive_pack? && receive_pack_allowed? render_ok elsif http_blocked? - render_not_allowed + render_http_not_allowed else - render_not_found + render_denied end end @@ -20,7 +20,7 @@ class Projects::GitHttpController < Projects::GitHttpClientController if upload_pack? && upload_pack_allowed? render_ok else - render_not_found + render_denied end end @@ -29,7 +29,7 @@ class Projects::GitHttpController < Projects::GitHttpClientController if receive_pack? && receive_pack_allowed? render_ok else - render_not_found + render_denied end end @@ -59,30 +59,41 @@ class Projects::GitHttpController < Projects::GitHttpClientController render json: Gitlab::Workhorse.git_http_ok(repository, user) end - def render_not_allowed - render plain: download_access.message, status: :forbidden + def render_not_found + render plain: 'Not Found', status: :not_found + end + + def render_http_not_allowed + render plain: access_check.message, status: :forbidden + end + + def render_denied + if user && user.can?(:read_project, project) + render plain: 'Access denied', status: :forbidden + else + # Do not leak information about project existence + render_not_found + end end def upload_pack_allowed? return false unless Gitlab.config.gitlab_shell.upload_pack if user - download_access.allowed? + access_check.allowed? else ci? || project.public? end end def access - return @access if defined?(@access) - - @access = Gitlab::GitAccess.new(user, project, 'http') + @access ||= Gitlab::GitAccess.new(user, project, 'http') end - def download_access - return @download_access if defined?(@download_access) - - @download_access = access.check('git-upload-pack') + def access_check + # Use the magic string '_any' to indicate we do not know what the + # changes are. This is also what gitlab-shell does. + @access_check ||= access.check(git_command, '_any') end def http_blocked? @@ -92,8 +103,6 @@ class Projects::GitHttpController < Projects::GitHttpClientController def receive_pack_allowed? return false unless Gitlab.config.gitlab_shell.receive_pack - # Skip user authorization on upload request. - # It will be done by the pre-receive hook in the repository. - user.present? + access_check.allowed? end end |