Commit 2788383b authored by Sean McGivern's avatar Sean McGivern Committed by James Edwards-Jones

Merge branch '33303-8-17-security-fix' into 'security-8-17'

[8-17 security fix] Renders 404 if given project is not readable by the user on Todos dashboard

See merge request !2136
parent 632aa1d4
class Dashboard::TodosController < Dashboard::ApplicationController class Dashboard::TodosController < Dashboard::ApplicationController
include ActionView::Helpers::NumberHelper
before_action :authorize_read_project!, only: :index
before_action :find_todos, only: [:index, :destroy_all] before_action :find_todos, only: [:index, :destroy_all]
def index def index
...@@ -31,6 +34,15 @@ class Dashboard::TodosController < Dashboard::ApplicationController ...@@ -31,6 +34,15 @@ class Dashboard::TodosController < Dashboard::ApplicationController
private private
def authorize_read_project!
project_id = params[:project_id]
if project_id.present?
project = Project.find(project_id)
render_404 unless can?(current_user, :read_project, project)
end
end
def find_todos def find_todos
@todos ||= TodosFinder.new(current_user, params).execute @todos ||= TodosFinder.new(current_user, params).execute
end end
......
---
title: Renders 404 if given project is not readable by the user on Todos dashboard
merge_request:
author:
...@@ -11,6 +11,30 @@ describe Dashboard::TodosController do ...@@ -11,6 +11,30 @@ describe Dashboard::TodosController do
project.team << [user, :developer] project.team << [user, :developer]
end end
context 'project authorization' do
it 'renders 404 when user does not have read access on given project' do
unauthorized_project = create(:empty_project, :private)
get :index, project_id: unauthorized_project.id
expect(response).to have_http_status(404)
end
it 'renders 200 when filtering for "any project" todos' do
get :index, project_id: ''
expect(response).to have_http_status(200)
end
it 'renders 200 when user has access on given project' do
authorized_project = create(:empty_project, :public)
get :index, project_id: authorized_project.id
expect(response).to have_http_status(200)
end
end
context 'when using pagination' do context 'when using pagination' do
let(:last_page) { user.todos.page.total_pages } let(:last_page) { user.todos.page.total_pages }
let!(:issues) { create_list(:issue, 2, project: project, assignee: user) } let!(:issues) { create_list(:issue, 2, project: project, assignee: user) }
......
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