diff options
author | Go MAEDA <maeda@farend.jp> | 2021-04-23 00:46:45 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2021-04-23 00:46:45 +0000 |
commit | 1cf427ee6380045c8f93216b80f63890926508af (patch) | |
tree | ad85acd7660d2b30d9a3bdb30c75715d1d6b0eee /app/controllers/repositories_controller.rb | |
parent | ccd00df71ca30e8f10c8642b7a16763a6e19f6f2 (diff) | |
download | redmine-1cf427ee6380045c8f93216b80f63890926508af.tar.gz redmine-1cf427ee6380045c8f93216b80f63890926508af.zip |
Stricter validation of given revisions of repositories (#35085).
Patch by Holger Just.
git-svn-id: http://svn.redmine.org/redmine/trunk@20962 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/repositories_controller.rb')
-rw-r--r-- | app/controllers/repositories_controller.rb | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index dfa96cc0e..45e969ba4 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -330,7 +330,7 @@ class RepositoriesController < ApplicationController render_404 end - REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i + REV_PARAM_RE = %r{\A[a-f0-9]*\z}i def find_project_repository @project = Project.find(params[:id]) @@ -341,14 +341,12 @@ class RepositoriesController < ApplicationController end (render_404; return false) unless @repository @path = params[:path].is_a?(Array) ? params[:path].join('/') : params[:path].to_s - @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].to_s.strip - @rev_to = params[:rev_to] - unless REV_PARAM_RE.match?(@rev.to_s) && REV_PARAM_RE.match?(@rev_to.to_s) - if @repository.branches.blank? - raise InvalidRevisionParam - end - end + @rev = params[:rev].to_s.strip.presence || @repository.default_branch + raise InvalidRevisionParam unless valid_name?(@rev) + + @rev_to = params[:rev_to].to_s.strip.presence + raise InvalidRevisionParam unless valid_name?(@rev_to) rescue ActiveRecord::RecordNotFound render_404 rescue InvalidRevisionParam @@ -433,4 +431,11 @@ class RepositoriesController < ApplicationController 'attachment' end end + + def valid_name?(rev) + return true if rev.nil? + return true if REV_PARAM_RE.match?(rev) + + @repository ? @repository.valid_name?(rev) : true + end end |