Skip to content

Commit 402f970

Browse files
committed
Limit assigned attributes when creating and updating Notes
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.
1 parent b9c0316 commit 402f970

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

app/controllers/admin/notes_controller.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def create
2323
note = new_note
2424

2525
note.state = "published"
26-
note.attributes = params[:note].permit!
26+
note.assign_attributes(note_params)
2727
note.text_filter ||= default_text_filter
2828
note.published_at ||= Time.zone.now
2929
if note.save
@@ -41,7 +41,7 @@ def create
4141
end
4242

4343
def update
44-
@note.attributes = params[:note].permit!
44+
@note.assign_attributes(note_params)
4545
@note.save
4646
redirect_to admin_notes_url
4747
end
@@ -54,6 +54,15 @@ def destroy
5454

5555
private
5656

57+
def note_params
58+
params.require(:note).permit(:text_filter_name,
59+
:body,
60+
:push_to_twitter,
61+
:in_reply_to_status_id,
62+
:permalink,
63+
:published_at)
64+
end
65+
5766
def load_existing_notes
5867
@notes = Note.page(params[:page]).per(this_blog.limit_article_display)
5968
end

0 commit comments

Comments
 (0)