Skip to content
Snippets Groups Projects
Commit 82a0d826 authored by GitLab Release Tools Bot's avatar GitLab Release Tools Bot
Browse files

Merge branch 'security-33689-post-filter-search-results-ce-12-2' into '12-2-stable'

Filter out search results based on permissions to avoid bugs leaking data

See merge request gitlab/gitlabhq!3494
parents 635e1578 c2c49808
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -16,6 +16,7 @@ class Discussion
:commit_id,
:for_commit?,
:for_merge_request?,
:noteable_ability_name,
:to_ability_name,
:editable?,
:visible_for?,
Loading
Loading
Loading
Loading
@@ -254,6 +254,10 @@ class Milestone < ApplicationRecord
group || project
end
 
def to_ability_name
model_name.singular
end
def group_milestone?
group_id.present?
end
Loading
Loading
Loading
Loading
@@ -353,6 +353,10 @@ class Note < ApplicationRecord
end
 
def to_ability_name
model_name.singular
end
def noteable_ability_name
for_snippet? ? noteable.class.name.underscore : noteable_type.demodulize.underscore
end
 
Loading
Loading
Loading
Loading
@@ -1223,6 +1223,10 @@ class Project < ApplicationRecord
end
end
 
def to_ability_name
model_name.singular
end
# rubocop: disable CodeReuse/ServiceClass
def execute_hooks(data, hooks_scope = :push_hooks)
run_after_commit_or_now do
Loading
Loading
Loading
Loading
@@ -9,7 +9,7 @@ class NotePolicy < BasePolicy
 
condition(:editable, scope: :subject) { @subject.editable? }
 
condition(:can_read_noteable) { can?(:"read_#{@subject.to_ability_name}") }
condition(:can_read_noteable) { can?(:"read_#{@subject.noteable_ability_name}") }
 
condition(:is_visible) { @subject.visible_for?(@user) }
 
Loading
Loading
Loading
Loading
@@ -281,7 +281,7 @@ class NotificationService
end
 
def send_new_note_notifications(note)
notify_method = "note_#{note.to_ability_name}_email".to_sym
notify_method = "note_#{note.noteable_ability_name}_email".to_sym
 
recipients = NotificationRecipientService.build_new_note_recipients(note)
recipients.each do |recipient|
Loading
Loading
Loading
Loading
@@ -206,6 +206,14 @@ describe Milestone do
end
end
 
describe '#to_ability_name' do
it 'returns milestone' do
milestone = build(:milestone)
expect(milestone.to_ability_name).to eq('milestone')
end
end
describe '.search' do
let(:milestone) { create(:milestone, title: 'foo', description: 'bar') }
 
Loading
Loading
Loading
Loading
@@ -539,24 +539,30 @@ describe Note do
end
 
describe '#to_ability_name' do
it 'returns snippet for a project snippet note' do
expect(build(:note_on_project_snippet).to_ability_name).to eq('project_snippet')
it 'returns note' do
expect(build(:note).to_ability_name).to eq('note')
end
end
describe '#noteable_ability_name' do
it 'returns project_snippet for a project snippet note' do
expect(build(:note_on_project_snippet).noteable_ability_name).to eq('project_snippet')
end
 
it 'returns personal_snippet for a personal snippet note' do
expect(build(:note_on_personal_snippet).to_ability_name).to eq('personal_snippet')
expect(build(:note_on_personal_snippet).noteable_ability_name).to eq('personal_snippet')
end
 
it 'returns merge_request for an MR note' do
expect(build(:note_on_merge_request).to_ability_name).to eq('merge_request')
expect(build(:note_on_merge_request).noteable_ability_name).to eq('merge_request')
end
 
it 'returns issue for an issue note' do
expect(build(:note_on_issue).to_ability_name).to eq('issue')
expect(build(:note_on_issue).noteable_ability_name).to eq('issue')
end
 
it 'returns issue for a commit note' do
expect(build(:note_on_commit).to_ability_name).to eq('commit')
it 'returns commit for a commit note' do
expect(build(:note_on_commit).noteable_ability_name).to eq('commit')
end
end
 
Loading
Loading
Loading
Loading
@@ -4334,6 +4334,14 @@ describe Project do
end
end
 
describe '#to_ability_name' do
it 'returns project' do
project = build(:project_empty_repo)
expect(project.to_ability_name).to eq('project')
end
end
describe '#execute_hooks' do
let(:data) { { ref: 'refs/heads/master', data: 'data' } }
it 'executes active projects hooks with the specified scope' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment