summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Release Tools Bot <robert+release-tools@gitlab.com>2019-08-26 07:42:26 +0000
committerGitLab Release Tools Bot <robert+release-tools@gitlab.com>2019-08-26 07:42:26 +0000
commitcfe2f8999dde3a227828770e127a0692ffb6b2fd (patch)
tree235dda61ad2458f9477fe5bfc213eea8c44d9271
parent1a8e7e629e3fe7698c67f4fe8e8b7f86474ac956 (diff)
parent8f6ce48d8e40c85f78942551c511ec0d2ae2ada9 (diff)
downloadgitlab-ce-cfe2f8999dde3a227828770e127a0692ffb6b2fd.tar.gz
Merge branch 'security-epic-notes-api-reveals-historical-info-ce-12-0' into '12-0-stable'
Filter out old system notes for epics in notes api endpoint response See merge request gitlab/gitlabhq!3242
-rw-r--r--app/controllers/concerns/issuable_actions.rb2
-rw-r--r--app/controllers/concerns/notes_actions.rb2
-rw-r--r--app/models/note.rb4
-rw-r--r--changelogs/unreleased/security-epic-notes-api-reveals-historical-info-ce-master.yml5
-rw-r--r--lib/api/discussions.rb4
-rw-r--r--lib/api/helpers/notes_helpers.rb8
-rw-r--r--lib/api/notes.rb2
7 files changed, 20 insertions, 7 deletions
diff --git a/app/controllers/concerns/issuable_actions.rb b/app/controllers/concerns/issuable_actions.rb
index 065d2d3a4ec..97e1a346103 100644
--- a/app/controllers/concerns/issuable_actions.rb
+++ b/app/controllers/concerns/issuable_actions.rb
@@ -111,7 +111,7 @@ module IssuableActions
end
notes = prepare_notes_for_rendering(notes)
- notes = notes.reject { |n| n.cross_reference_not_visible_for?(current_user) }
+ notes = notes.select { |n| n.visible_for?(current_user) }
discussions = Discussion.build_collection(notes, issuable)
diff --git a/app/controllers/concerns/notes_actions.rb b/app/controllers/concerns/notes_actions.rb
index 0098c4cdf4c..52c3a34ffe4 100644
--- a/app/controllers/concerns/notes_actions.rb
+++ b/app/controllers/concerns/notes_actions.rb
@@ -29,7 +29,7 @@ module NotesActions
end
notes = prepare_notes_for_rendering(notes)
- notes = notes.reject { |n| n.cross_reference_not_visible_for?(current_user) }
+ notes = notes.select { |n| n.visible_for?(current_user) }
notes_json[:notes] =
if use_note_serializer?
diff --git a/app/models/note.rb b/app/models/note.rb
index 246536853cb..774a8cb9094 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -326,6 +326,10 @@ class Note < ApplicationRecord
cross_reference? && !all_referenced_mentionables_allowed?(user)
end
+ def visible_for?(user)
+ !cross_reference_not_visible_for?(user)
+ end
+
def award_emoji?
can_be_award_emoji? && contains_emoji_only?
end
diff --git a/changelogs/unreleased/security-epic-notes-api-reveals-historical-info-ce-master.yml b/changelogs/unreleased/security-epic-notes-api-reveals-historical-info-ce-master.yml
new file mode 100644
index 00000000000..c639098721e
--- /dev/null
+++ b/changelogs/unreleased/security-epic-notes-api-reveals-historical-info-ce-master.yml
@@ -0,0 +1,5 @@
+---
+title: Filter out old system notes for epics in notes api endpoint response
+merge_request:
+author:
+type: security
diff --git a/lib/api/discussions.rb b/lib/api/discussions.rb
index 693172b7d08..ca7942c5f56 100644
--- a/lib/api/discussions.rb
+++ b/lib/api/discussions.rb
@@ -32,7 +32,7 @@ module API
.includes(:noteable)
.fresh
- notes = notes.reject { |n| n.cross_reference_not_visible_for?(current_user) }
+ notes = notes.select { |n| n.visible_for?(current_user) }
discussions = Kaminari.paginate_array(Discussion.build_collection(notes, noteable))
present paginate(discussions), with: Entities::Discussion
@@ -233,7 +233,7 @@ module API
.includes(:noteable)
.fresh
- notes.reject { |n| n.cross_reference_not_visible_for?(current_user) }
+ notes.select { |n| n.visible_for?(current_user) }
end
# rubocop: enable CodeReuse/ActiveRecord
end
diff --git a/lib/api/helpers/notes_helpers.rb b/lib/api/helpers/notes_helpers.rb
index a068de4361c..924c763ed03 100644
--- a/lib/api/helpers/notes_helpers.rb
+++ b/lib/api/helpers/notes_helpers.rb
@@ -10,7 +10,7 @@ module API
end
def update_note(noteable, note_id)
- note = noteable.notes.find(params[:note_id])
+ note = noteable.notes.find(note_id)
authorize! :admin_note, note
@@ -60,7 +60,7 @@ module API
def get_note(noteable, note_id)
note = noteable.notes.with_metadata.find(params[:note_id])
- can_read_note = !note.cross_reference_not_visible_for?(current_user)
+ can_read_note = note.visible_for?(current_user)
if can_read_note
present note, with: Entities::Note
@@ -69,6 +69,10 @@ module API
end
end
+ def reject_note?(noteable_type, noteable, parent_type, parent_id, note)
+ note.cross_reference_not_visible_for?(current_user)
+ end
+
def noteable_read_ability_name(noteable)
"read_#{noteable.class.to_s.underscore}".to_sym
end
diff --git a/lib/api/notes.rb b/lib/api/notes.rb
index 416cf39d3ec..5cc3b4bb648 100644
--- a/lib/api/notes.rb
+++ b/lib/api/notes.rb
@@ -43,7 +43,7 @@ module API
# mismatch between the pagination headers info and the actual notes
# array returned, but this is really a edge-case.
paginate(raw_notes)
- .reject { |n| n.cross_reference_not_visible_for?(current_user) }
+ .select { |note| note.visible_for?(current_user) }
present notes, with: Entities::Note
end
# rubocop: enable CodeReuse/ActiveRecord