Senior & Expert RoR Developers Discussion Forum by Nyros Technologies

HIRE Ruby on Rails Expert Developers Programmers Coders From India
Ruby on Rails PHP .Net Developers Community, Nyros Technologies, Kakinada
 
Log in  or IF not a member please REGISTER
Username:
Password:   


Keyword
Log in | Profile 

audit_mass_assignment plugin.

 
Post new topic   Reply to topic    Senior & Expert RoR Developers Discussion Forum by Nyros Technologies Index -> Experts Support & Chit Chat
View previous topic :: View next topic  
Author Message
Divya



Joined: 14 Sep 2009
Posts: 57

PostPosted: Mon Dec 07, 2009 11:51 am    Post subject: audit_mass_assignment plugin. Reply with quote

--------------audit_mass_assignment plugin.-----------------------

This "audit_mass_assignment " plugin contains a rake task that
checks the models in your project for the attr_accessible whitelist approach
for protecting against "mass assignment" exploits. It does not check for
use of attr_protected.

To use this plugin in our application we need to do the following setps:

Step1:

Install the plugin or a gem

gem install ryanlowe-audit_mass_assignment or u can download the plugin from

http://github.com/ryanlowe/audit_mass_assignment

Step2:

Then run in your terminal as

rake audit:mass_assignment

Step 3:

If you get an error as above :

Audit mass assignment in models:
rake aborted!
uninitialized constant CGI::Session.

So then go to vendors/plugins/lib/audit_mass_assignment.rb file

There you can see a line no 11,

--subclasses.delete CGI::Session::ActiveRecordStore::Session

So replace this line to

--subclasses.delete ActionController::Session

Because for latest version the CGI::Session is the child class for ActionController .

Step 4:

Then place in your model as


attr_accessible :title, :description

What ever fields you want to protect

Step 5:

Then run rake audit:mass_assignment

So you can check your models in your project for the attr_accessible whitelist approach
for protecting against "mass assignment" exploits.

This looks in your terminal as

Audit mass assignment in models:
F

1) Event
2) Cal
3) Admin
4) Link

Solution: use attr_accessible in these models

6 models, 4 failures

Here 4 failures means that those models have not specified "attr_accessible" . So that that model attributes have not been protected.So there may be a chances to hack those attributes.

---- attr_accessible usage:------

You should not create or update records directly from parameters!

Ex:

@user = User.new(params[:user])

This is mass assignment. It is creating a new user object from all the attributes assigned to :user

<% form_for @user do |f| %>
<%= f.text_field :name %>
<%= f.text_field :email %>
...
All the attributes from this parameters hash with be be used in creating a new user model. If your user table contains an admin field. The ‘attacker’ can submit a post, setting admin = true.

<% form for @user do |f| %>
<%= f.text_field :name %>
<%= f.text_field :email %>
<%= f.text_field :admin, :value => true %>
...

How can we prevent this ?

We need to only allow “safe” attributes from being mass assigned.

You might think it’s easier to specify which attributes should be restricted, but remember foreign keys are also susceptible to mass assignment.

So we are rather going to set the attributes that are allowed, rather than restricted. The rest we will have to assign individually.

In this example you would add to your model:

attr_accessible :name, email

You should explicitly set which attributes are allowed in every model. It will fail on every model that does not include attr_accessible.As explain below.

Thank You,
Divya.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Senior & Expert RoR Developers Discussion Forum by Nyros Technologies Index -> Experts Support & Chit Chat
Page 1 of 1

 latest topics 
 Topics   Replies   Author   Views   Last Post 
No new posts How to customize Google Maps InfoWindow using ym4r_gm
0 kalyanallampalli 49 Thu Sep 02, 2010 5:34 pm
kalyanallampalli View latest post
No new posts Drag and Drop file upload
0 umamageshwari 45 Wed Sep 01, 2010 9:36 am
umamageshwari View latest post
No new posts Flex On Rails
0 Raghu 45 Wed Sep 01, 2010 3:00 am
Raghu View latest post
No new posts MongoDB
0 Raghu 44 Tue Aug 31, 2010 3:30 pm
Raghu View latest post
No new posts Problem with Dreamweaver / java error
3 Raja 36 Tue Aug 31, 2010 3:24 pm
Raghu View latest post
No new posts Generating Model
0 phani.galla 43 Tue Aug 31, 2010 2:09 pm
phani.galla View latest post
No new posts Hide Panels using JQuery
0 Anu 46 Tue Aug 31, 2010 1:50 pm
Anu View latest post
No new posts Load a text file using ajax in jquery
0 Anu 35 Tue Aug 31, 2010 1:39 pm
Anu View latest post
No new posts Generating Migrations
0 phani.galla 29 Tue Aug 31, 2010 1:38 pm
phani.galla View latest post
No new posts Generating Controllers
0 phani.galla 31 Tue Aug 31, 2010 1:22 pm
phani.galla View latest post




Hire an expert Ruby on Rails developer / coder / programmer or development team from India now!!

Other Forums : PHP   ::   .Net   |   Free unlimited HTML CSS templates download

Nyros Technologies   |   Kakinada City Portal   |   Developers Blog   |   About Ruby on Rails Experts   |   More