Commit 69d9bf58 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Use strong_parameters for RefsController

* Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/351520
* Sentry error: https://sentry.gitlab.net/gitlab/gitlabcom/issues/3182017

Changelog: fixed
parent d088bff9
...@@ -18,7 +18,7 @@ class Projects::RefsController < Projects::ApplicationController ...@@ -18,7 +18,7 @@ class Projects::RefsController < Projects::ApplicationController
respond_to do |format| respond_to do |format|
format.html do format.html do
new_path = new_path =
case params[:destination] case permitted_params[:destination]
when "tree" when "tree"
project_tree_path(@project, @id) project_tree_path(@project, @id)
when "blob" when "blob"
...@@ -45,7 +45,7 @@ class Projects::RefsController < Projects::ApplicationController ...@@ -45,7 +45,7 @@ class Projects::RefsController < Projects::ApplicationController
def logs_tree def logs_tree
tree_summary = ::Gitlab::TreeSummary.new( tree_summary = ::Gitlab::TreeSummary.new(
@commit, @project, current_user, @commit, @project, current_user,
path: @path, offset: params[:offset], limit: 25) path: @path, offset: permitted_params[:offset], limit: 25)
respond_to do |format| respond_to do |format|
format.html { render_404 } format.html { render_404 }
...@@ -62,6 +62,10 @@ class Projects::RefsController < Projects::ApplicationController ...@@ -62,6 +62,10 @@ class Projects::RefsController < Projects::ApplicationController
private private
def validate_ref_id def validate_ref_id
return not_found if params[:id].present? && params[:id] !~ Gitlab::PathRegex.git_reference_regex return not_found if permitted_params[:id].present? && permitted_params[:id] !~ Gitlab::PathRegex.git_reference_regex
end
def permitted_params
params.permit(:id, :offset, :destination)
end end
end end
...@@ -55,6 +55,15 @@ RSpec.describe Projects::RefsController do ...@@ -55,6 +55,15 @@ RSpec.describe Projects::RefsController do
end end
end end
context 'when offset has an invalid format' do
it 'renders JSON' do
xhr_get(:json, offset: { wrong: :format })
expect(response).to be_successful
expect(json_response).to be_kind_of(Array)
end
end
context 'when json is requested' do context 'when json is requested' do
it 'renders JSON' do it 'renders JSON' do
expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment