-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
feature: eject controllers #3377
Conversation
Code Climate has analyzed commit 2650bca and detected 0 issues on this pull request. View more on Code Climate. |
def set_related_record | ||
association_name = BaseResource.valid_association_name(@record, params[:related_name]) | ||
@related_record = if @field.is_a? Avo::Fields::HasOneField | ||
@record.send association_name |
Check failure
Code scanning / CodeQL
Code injection Critical
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 4 months ago
To fix the problem, we need to ensure that the value of association_name
is safe before using it in the send
method. This can be achieved by explicitly validating that association_name
is one of the expected method names. This way, we can prevent any arbitrary method execution based on user input.
We will modify the set_related_record
method to include a whitelist of valid association names and check if association_name
is included in this list before calling send
.
-
Copy modified lines R158-R165 -
Copy modified line R167
@@ -157,8 +157,13 @@ | ||
association_name = BaseResource.valid_association_name(@record, params[:related_name]) | ||
@related_record = if @field.is_a? Avo::Fields::HasOneField | ||
@record.send association_name | ||
valid_associations = @record.class.reflect_on_all_associations.map(&:name).map(&:to_s) | ||
if valid_associations.include?(association_name) | ||
@related_record = if @field.is_a? Avo::Fields::HasOneField | ||
@record.send association_name | ||
else | ||
@related_resource.find_record params[:related_id], query: @record.send(association_name), params: params | ||
end | ||
@related_resource.hydrate(record: @related_record) | ||
else | ||
@related_resource.find_record params[:related_id], query: @record.send(association_name), params: params | ||
raise Avo::InvalidAssociationNameError.new(association_name) | ||
end | ||
@related_resource.hydrate(record: @related_record) | ||
end |
@related_record = if @field.is_a? Avo::Fields::HasOneField | ||
@record.send association_name | ||
else | ||
@related_resource.find_record params[:related_id], query: @record.send(association_name), params: params |
Check failure
Code scanning / CodeQL
Code injection Critical
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 4 months ago
To fix the problem, we need to ensure that the association_name
derived from params[:related_name]
is safe to use with the send
method. This can be achieved by explicitly validating or sanitizing the association_name
to ensure it only contains expected and safe values. One approach is to use a whitelist of allowed association names or to ensure that the association_name
is a valid method name on the @record
object.
-
Copy modified lines R158-R164 -
Copy modified line R166
@@ -157,8 +157,12 @@ | ||
association_name = BaseResource.valid_association_name(@record, params[:related_name]) | ||
@related_record = if @field.is_a? Avo::Fields::HasOneField | ||
@record.send association_name | ||
if @record.respond_to?(association_name) | ||
@related_record = if @field.is_a? Avo::Fields::HasOneField | ||
@record.send association_name | ||
else | ||
@related_resource.find_record params[:related_id], query: @record.send(association_name), params: params | ||
end | ||
@related_resource.hydrate(record: @related_record) | ||
else | ||
@related_resource.find_record params[:related_id], query: @record.send(association_name), params: params | ||
raise Avo::InvalidAssociationNameError.new(association_name) | ||
end | ||
@related_resource.hydrate(record: @related_record) | ||
end |
This PR has been merged into Please check the release guide for more information. |
Description
This PR adds the ability to eject controllers from Avo and more specifically the application controller.
THis enables more granular customizations to the whole request cycle.
Related to #3376
Checklist:
Screenshots & recording
Manual review steps
bin/rails generate avo:eject --controller application
application_controller.rb
file being generated in your app.Manual reviewer: please leave a comment with output from the test if that's the case.