Created
May 20, 2014 11:00
-
-
Save pixeltrix/6aaf928d59ccdb6f52cb to your computer and use it in GitHub Desktop.
Tool to report whether a Rails application may be vulnerable to 'Unsafe Query Risk in Active Record'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run this code inside your Rails application | |
# | |
# Rails 2.3: | |
# script/runner unsafe_query_check.rb | |
# | |
# Rails 3.0 and later | |
# rails runner unsafe_query_check.rb | |
connection = ActiveRecord::Base.connection | |
tables = connection.tables | |
columns = tables.map{ |t| connection.columns(t).map(&:name) }.flatten.uniq | |
conflicts = tables & columns | |
if conflicts.empty? | |
puts "Your Rails application is not vulnerable to 'Unsafe Query Risk in Active Record'" | |
else | |
puts "Your Rails application is possibly vulnerable to 'Unsafe Query Risk in Active Record'" | |
puts "Please check the following conflicts between table and column names:" | |
puts conflicts.inspect | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment