You are currently browsing the tag archive for the 'security' tag.

By now, you all know that you need to use attr_accessible to protect your application from having any old Active Record attribute changed by a malicious user. I find myself, in the course of consulting, looking at a great number of existing applications, and I’ve grown tired of having to open up every model and look. So, let’s be a bit smart: here’s a rake task that you can drop in any existing application to do the audit for you:


namespace :utility do

  desc 'Find models that are not using attr_accessible'
  task :audit_attr_accessible => :environment do

    all_models = Dir.glob(
      File.join(Rails.root, 'app', 'models', '*.rb')
      ).map{|path| path[/.+\/(.+).rb/,1] }
    ar_models = all_models.select{|m|
       m.classify.constantize < ActiveRecord::Base}

    ar_models.each do |model|
      model_class = model.classify.constantize
      if model_class.send("attr_accessible").empty? &&
         model_class.send("attr_protected").empty?
        puts model_class.class_name +
          " allows unprotected mass assignment"
      end
    end

  end

end

(Hat tip Matt for the snippet to find all models).

I think the ActiveRecord Associations Guide I wrote may actually be finished.

  • Dynamic Rails Error Help - Making the default validation messages more useful with a bit of javascript.
  • Exceptional - This online error-tracker for Rails apps is now in open beta.
  • Is Your Rails Application Safe? - If you’re inadvertently allowing mass assignment, probably not.
  • MysqlTableSyncer - Command-line tool to synch up two MySQL tables.
  • turl - My contribution to a little scripting fest on Twitter yesterday. If you have FF3 + Ubiquity, you can use “turl <userid>” to go straight to a Twitter user’s web site.

Checked in another contribution to the DocRails project yesterday - A Guide to Active Record Associations.

Yes, I’m still underemployed, despite some potential contracts on hold. If you’re looking for a Rails dev, let’s talk.

Solr is not playing nice in deployment. Ugh.

Worn out from yesterday’s trip to Holiday World. Hoping today’s huge pile of work is more relaxing.

I really don’t like being in a situation where I don’t know whether the tests are bad or the code is bad.