Skip to content

Commit 1165ee6

Browse files
committed
refactor(member): migrate details to params.expect, fix mixed access
- Convert member_params to params.expect with nested array syntax - Remove direct params[:member] access (was security issue) - Refactor how_you_found_us validation to accept params hash - Fix validation order: validate before clearing other_reason - Call member_params only once (performance improvement) Security fix: Previously mixed permitted params with raw params access, allowing potential bypass of strong parameters. Now all access goes through params.expect. Bug fix: Validation now properly checks before modifying attributes.
1 parent 7d479d9 commit 1165ee6

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

app/controllers/concerns/member_concerns.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ module InstanceMethods
99
private
1010

1111
def member_params
12-
params.require(:member).permit(
12+
params.expect(member: [
1313
:pronouns, :name, :surname, :email, :mobile, :about_you, :skill_list, :newsletter, :other_dietary_restrictions, :how_you_found_us,
14-
:how_you_found_us_other_reason, dietary_restrictions: []
15-
).tap do |params|
14+
:how_you_found_us_other_reason, { dietary_restrictions: [] }
15+
]).tap do |permitted_params|
1616
# We want to keep Rails' hidden blank field in the form so that all dietary restrictions for a member can be
1717
# removed by submitting the form with all check boxes unticked. However, we want to remove the blank value
1818
# before setting the dietary restrictions attribute on the model.
1919
# See Gotcha section here:
2020
# https://api.rubyonrails.org/v7.1/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_check_boxes
21-
params[:dietary_restrictions] = params[:dietary_restrictions].reject(&:blank?) if params[:dietary_restrictions]
21+
if permitted_params[:dietary_restrictions]
22+
permitted_params[:dietary_restrictions] = permitted_params[:dietary_restrictions].reject(&:blank?)
23+
end
2224
end
2325
end
2426

0 commit comments

Comments
 (0)