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

Security issue in resource-controller #176

Closed
masche842 opened this issue Feb 6, 2012 · 4 comments
Closed

Security issue in resource-controller #176

masche842 opened this issue Feb 6, 2012 · 4 comments
Assignees

Comments

@masche842
Copy link
Contributor

I know: It should only be accessible by authorized users... Nontheless:

items = resource_model.where(searchable_resource_attributes.map { |attribute|
                    "`#{namespaced_resources_name}`.`#{attribute[:name]}` LIKE '%#{params[:query]}%'"
                }.join(" OR "))

This line is vulnerable regarding to (i.e.):
http://stackoverflow.com/questions/2962263/rails-sql-injection

Solutions are a bit complicated. Maybe it's better to build every condition on its own and chain them together afterwards. I'll try to figure out a nice piece of code for that.

@ghost ghost assigned masche842 Feb 6, 2012
@tvdeyen
Copy link
Member

tvdeyen commented Feb 6, 2012

Thanks for reporting this, but could you please not publish any security issues before it's fixed!

See how rails handles this:

http://guides.rubyonrails.org/contributing_to_ruby_on_rails.html#special-treatment-for-security-issues

http://rubyonrails.org/security

@masche842
Copy link
Contributor Author

Yes, you're right, sorry. Wasn't aware of this as it seemed to be not so critical. Next time via email.
For now I'm working on a solution at the moment to fix it as fast as possible.

You wrote about the arel_table yesterday. Do you now a way to push conditions to where_values? This would make it very easy to chain the conditions up.

@masche842
Copy link
Contributor Author

Ok, quite difficult. I had something more elegant in mind but for now it should be safe to just sanitize the parameter:

      search_terms = ActiveRecord::Base.sanitize("%#{params[:query]}%")
  items = resource_model.where(searchable_resource_attributes.map { |attribute|
    "`#{namespaced_resources_name}`.`#{attribute[:name]}` LIKE #{search_terms}"
  }.join(" OR "))

@tvdeyen
Copy link
Member

tvdeyen commented Feb 6, 2012

Ok, I just created a security@alchemy-cms.com e-mail address

@tvdeyen tvdeyen closed this as completed in 74bad94 Feb 6, 2012
masche842 pushed a commit to masche842/alchemy_cms that referenced this issue Feb 21, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants