Skip to content

Commit

Permalink
Limit assigned attributes when creating and updating Notes
Browse files Browse the repository at this point in the history
Using #permit! is unsafe and not necessary, since we have a fixed set of
attributes used in the notes form. Use #permit with a list of attribute
names instead.
  • Loading branch information
mvz committed Oct 13, 2024
1 parent b9c0316 commit 402f970
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/controllers/admin/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create
note = new_note

note.state = "published"
note.attributes = params[:note].permit!
note.assign_attributes(note_params)
note.text_filter ||= default_text_filter
note.published_at ||= Time.zone.now
if note.save
Expand All @@ -41,7 +41,7 @@ def create
end

def update
@note.attributes = params[:note].permit!
@note.assign_attributes(note_params)
@note.save
redirect_to admin_notes_url
end
Expand All @@ -54,6 +54,15 @@ def destroy

private

def note_params
params.require(:note).permit(:text_filter_name,
:body,
:push_to_twitter,
:in_reply_to_status_id,
:permalink,
:published_at)
end

def load_existing_notes
@notes = Note.page(params[:page]).per(this_blog.limit_article_display)
end
Expand Down

0 comments on commit 402f970

Please sign in to comment.