149 fixed remote-code-execution vulnerability, added tests for new code #180
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #149
Fixed a remote-code-execution vulnerability.
The previous method
Object.const_get(params[:controller_name].classify)
uses user-supplied data(params[:controller_name])
to dynamically retrieve a constant. This is risky because a malicious user can potentially gain access to any constant in the Ruby environment, which could lead to various types of attacks including Remote Code Execution (RCE).Proposed Fix
Instead of dynamically getting the constant using
Object.const_get
, we use a whitelist of allowable controller names that map to the models we want to work with. This way, we can ensure that only authorized models can be accessed.Added logging if csv generation fails.
Added tests for future models to ensure that they are on the list of approved controller names and that the new models have the self.to_csv method that will be called to generate a CSV.