Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forcer la whitelist dans le contexte de PolymorphicObjectFinder #1495

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions app/services/polymorphic_object_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PolymorphicObjectFinder
def self.find(params, key:, university:, only: [])
key_id = "#{key}_id".to_sym
key_type = "#{key}_type".to_sym
model_name = self.find_model_name(params, key_type, only)
model_name = self.safe_model_name(params, key_type, only)
return if model_name.nil?

model = model_name.constantize
Expand All @@ -20,12 +20,10 @@ def self.find(params, key:, university:, only: [])

private

def self.find_model_name(params, key_type, only)
if only.any?
# Whitelist user input
only.detect { |item| item == params[key_type] }
else
params[key_type]
end
# Whitelist user input
def self.safe_model_name(params, key_type, only)
only.detect { |item|
item == params[key_type]
}
end
end
Loading