diff options
author | Markus Koller <mkoller@gitlab.com> | 2019-05-31 18:18:09 +0200 |
---|---|---|
committer | Markus Koller <mkoller@gitlab.com> | 2019-06-06 09:32:18 +0200 |
commit | 12d7b3937fa97048d5bd6c09769e837052ebb3db (patch) | |
tree | 87e7c57422d777e764f646cde551884ba70cca59 /app/controllers/snippets | |
parent | 11bb3b53bcd2b50cb3fe243ac3b778354849cdde (diff) | |
download | gitlab-ce-12d7b3937fa97048d5bd6c09769e837052ebb3db.tar.gz |
Correctly check permissions when creating snippet notes
In the Snippets::NotesController the noteable was resolved and
authorized through the :snippet_id, so by passing a :target_id for a
different snippet it was possible to create a note on a snippet
where the user would be unauthorized to do so otherwise.
This fixes the problem by ignoring the :target_id and :target_type from
the request, and using the same noteable for creation and authorization.
Diffstat (limited to 'app/controllers/snippets')
-rw-r--r-- | app/controllers/snippets/notes_controller.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/app/controllers/snippets/notes_controller.rb b/app/controllers/snippets/notes_controller.rb index eee14b0faf4..612897f27e6 100644 --- a/app/controllers/snippets/notes_controller.rb +++ b/app/controllers/snippets/notes_controller.rb @@ -5,8 +5,8 @@ class Snippets::NotesController < ApplicationController include ToggleAwardEmoji skip_before_action :authenticate_user!, only: [:index] - before_action :snippet - before_action :authorize_read_snippet!, only: [:show, :index, :create] + before_action :authorize_read_snippet!, only: [:show, :index] + before_action :authorize_create_note!, only: [:create] private @@ -33,4 +33,8 @@ class Snippets::NotesController < ApplicationController def authorize_read_snippet! return render_404 unless can?(current_user, :read_personal_snippet, snippet) end + + def authorize_create_note! + access_denied! unless can?(current_user, :create_note, noteable) + end end |