Skip to content

Instantly share code, notes, and snippets.

@dissolved
Last active August 29, 2015 14:01
Show Gist options
  • Save dissolved/09e9cc5e774985b33366 to your computer and use it in GitHub Desktop.
Save dissolved/09e9cc5e774985b33366 to your computer and use it in GitHub Desktop.
What is the most destructive thing you could assign to params?
def string_to_camelcase(string)
string.gsub(/\s+/, "").camelize # camelize defined in Rails API
end
the_class = eval string_to_camelcase(params[:user_input])
the_object = the_class.new(params[:more_user_input],params[:even_more_user_input])
@cupakromer
Copy link

Also, I may try to impose a whitelist approach of what I want to allow:

string.gsub(/[^\w:]+/, '').camelize.constantize)

@dissolved
Copy link
Author

Agreed, no need for eval at all here... constantize gets the job done with less risk. Great comments. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment