SlideShare a Scribd company logo
Security On Rails
David Paluy
October 2012
"Ruby is simple in appearance,
  but is very complex inside,
  just like our human body."

  Yukihiro "matz" Matsumoto
Agenda

●   Session Hijacking
●   CSRF
●   Mass Assignment
●   SQL Injection
Websites are all about
      the data!
When is a user not a user?
You have no way of knowing
who or where the data that hits
  your application is coming
             from.
Session Hijacking
Session Hijacking
●   Sniff the cookie in an insecure network.
●   Most people don’t clear out the cookies after
    working at a public terminal
●   Cross-Site Scripting (XSS)
●   CSS Injection
●   Header Injection
config.force_ssl = true

●   If you have http assets on an https page, the
    user’s browser will display a mixed-content
    warning in the browser bar.

●   Rails does most of the work for you, but if you
    have any hard-coded “http://” internal-links or
    images, make sure you change them.
Session Expiry

class Session < ActiveRecord::Base
 def self.sweep(time = 1.hour)
  if time.is_a?(String)
   time = time.split.inject { |count, unit| count.to_i.send(unit) }
  end
  delete_all "updated_at < '#{time.ago.to_s(:db)}' OR
       created_at < '#{2.days.ago.to_s(:db)}'"
 end
end
Provide the user with a log-out
button in the web application,
   and make it prominent.
XSS Countermeasures

strip_tags("some<<b>script>alert('hello')<</b>/script>")
RESULT: some<script>alert(‘hello’)</script>


<%= h post.text %>


<%= sanitize @article.body %>
view SanitizeHelper
CSS Injection

●   <div style="background:url('javascript:alert(1)')">
●   alert(eval('document.body.inne' + 'rHTML'));
Header Injection

redirect_to params[:referer]
http://www.yourapplication.com/controller/action?
referer=http://www.malicious.tld



Make sure you do it yourself when you
build other header fields with user input.
Session Storage

config.action_dispatch.session = {
    :key   => '_app_session',
    :secret => '0dkfj3927dkc7djdh36rkckdfzsg...'
}
Cross-Site Request Forgery (CSRF)




            Most Rails applications use cookie-based sessions
CSRF Countermeasures
    Be RESTful
    Use GET if:
●   The interaction is more like a question (i.e., it is a safe operation such as a
    query, read operation, or lookup).


    Use POST if:
●   The interaction is more like an order, or
●   The interaction changes the state of the resource in a way that the user
    would perceive (e.g., a subscription to a service), or
●   The user is held accountable for the results of the interaction.


       protect_from_forgery :secret => "123456789012345678901234567890..."
Mass Assignment




attr_accessible :name
attr_accessible :is_admin, :as => :admin
Mass Assignment
SQL Injection

●   Project.where("name = '#{params[:name]}'")
    SELECT * FROM projects WHERE name = '' OR 1'


●   User.first("login = '#{params[:name]}' AND
    password = '#{params[:password]}'")
    SELECT * FROM users WHERE login = '' OR '1'='1' AND
                              password = '' OR '2'>'1' LIMIT 1
SQL Injection Countermeasures

●   Model.where("login = ? AND password = ?",
    entered_user_name, entered_password).first

●   Model.where(:login => entered_user_name,
         :password => entered_password).first
Tools

●   Brakeman - A static analysis security
    vulnerability scanner for Ruby on Rails
    applications
●   RoRSecurity – explore Rails security
●   Techniques to Secure your Website with RoR
Summary


The security landscape shifts and
 it is important to keep up to date,
because missing a new vulnerability
         can be catastrophic.

More Related Content

What's hot (20)

PDF
Javaland 2017: "You´ll do microservices now". Now what?
André Goliath
 
PDF
Von JavaEE auf Microservice in 6 Monaten - The Good, the Bad, and the wtfs...
André Goliath
 
PPTX
Das kannste schon so machen
André Goliath
 
PPT
Getting started with angular js
Maurice De Beijer [MVP]
 
PDF
webcomponents (Jfokus 2015)
Hendrik Ebbers
 
PDF
Our application got popular and now it breaks
ColdFusionConference
 
PPTX
Authenticating and Securing Node.js APIs
Jimmy Guerrero
 
PPTX
Building Layers of Defense with Spring Security
Joris Kuipers
 
PDF
OWASP SF - Reviewing Modern JavaScript Applications
Lewis Ardern
 
PPTX
Cross Site Scripting (XSS) Defense with Java
Jim Manico
 
PPT
Top Ten Proactive Web Security Controls v5
Jim Manico
 
PDF
AtlasCamp 2014: 10 Things a Front End Developer Should Know About Connect
Atlassian
 
PDF
Design & Development of Web Applications using SpringMVC
Naresh Chintalcheru
 
PDF
Cutting the Fat
Codemotion
 
PDF
XSS Magic tricks
GarethHeyes
 
PDF
Azure Container Apps
ninefyi
 
PDF
The Future of CSS with Web Components
ColdFusionConference
 
PPTX
Mvvm knockout vs angular
Basarat Syed
 
KEY
An Introduction to webOS
Kevin Decker
 
PDF
Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...
MUG-Lyon Microsoft User Group
 
Javaland 2017: "You´ll do microservices now". Now what?
André Goliath
 
Von JavaEE auf Microservice in 6 Monaten - The Good, the Bad, and the wtfs...
André Goliath
 
Das kannste schon so machen
André Goliath
 
Getting started with angular js
Maurice De Beijer [MVP]
 
webcomponents (Jfokus 2015)
Hendrik Ebbers
 
Our application got popular and now it breaks
ColdFusionConference
 
Authenticating and Securing Node.js APIs
Jimmy Guerrero
 
Building Layers of Defense with Spring Security
Joris Kuipers
 
OWASP SF - Reviewing Modern JavaScript Applications
Lewis Ardern
 
Cross Site Scripting (XSS) Defense with Java
Jim Manico
 
Top Ten Proactive Web Security Controls v5
Jim Manico
 
AtlasCamp 2014: 10 Things a Front End Developer Should Know About Connect
Atlassian
 
Design & Development of Web Applications using SpringMVC
Naresh Chintalcheru
 
Cutting the Fat
Codemotion
 
XSS Magic tricks
GarethHeyes
 
Azure Container Apps
ninefyi
 
The Future of CSS with Web Components
ColdFusionConference
 
Mvvm knockout vs angular
Basarat Syed
 
An Introduction to webOS
Kevin Decker
 
Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...
MUG-Lyon Microsoft User Group
 

Similar to Security on Rails (20)

PDF
Security in Node.JS and Express:
Petros Demetrakopoulos
 
PDF
Neoito — Secure coding practices
Neoito
 
PPTX
OWASP ZAP Workshop for QA Testers
Javan Rasokat
 
PDF
Rails Security
Wen-Tien Chang
 
PDF
Breaking Bad CSP
Lukas Weichselbaum
 
PPTX
DevOps and the Future of Enterprise Security
Frank Kim
 
PDF
JSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
Mario Heiderich
 
PDF
Pawel Cygal - SQL Injection and XSS - Basics (Quality Questions Conference)
Grand Parade Poland
 
PDF
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Igor Bronovskyy
 
PPTX
ASP.NET Web Security
SharePointRadi
 
PDF
Whatever it takes - Fixing SQLIA and XSS in the process
guest3379bd
 
PDF
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack
 
ODP
Hunting Security Bugs in Modern Web Applications
Toe Khaing
 
PDF
They Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
michelemanzotti
 
PDF
手把手教你如何串接 Log 到各種網路服務
Mu Chun Wang
 
PPTX
Hackers vs developers
Soumyasanto Sen
 
PDF
Web Security 101
Michael Peters
 
PDF
Application Security around OWASP Top 10
Sastry Tumuluri
 
PPT
Web Apps Security
Victor Bucutea
 
PDF
Reviewing AngularJS
Lewis Ardern
 
Security in Node.JS and Express:
Petros Demetrakopoulos
 
Neoito — Secure coding practices
Neoito
 
OWASP ZAP Workshop for QA Testers
Javan Rasokat
 
Rails Security
Wen-Tien Chang
 
Breaking Bad CSP
Lukas Weichselbaum
 
DevOps and the Future of Enterprise Security
Frank Kim
 
JSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
Mario Heiderich
 
Pawel Cygal - SQL Injection and XSS - Basics (Quality Questions Conference)
Grand Parade Poland
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Igor Bronovskyy
 
ASP.NET Web Security
SharePointRadi
 
Whatever it takes - Fixing SQLIA and XSS in the process
guest3379bd
 
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack
 
Hunting Security Bugs in Modern Web Applications
Toe Khaing
 
They Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
michelemanzotti
 
手把手教你如何串接 Log 到各種網路服務
Mu Chun Wang
 
Hackers vs developers
Soumyasanto Sen
 
Web Security 101
Michael Peters
 
Application Security around OWASP Top 10
Sastry Tumuluri
 
Web Apps Security
Victor Bucutea
 
Reviewing AngularJS
Lewis Ardern
 
Ad

More from David Paluy (15)

PPTX
Intro to Smart Contracts
David Paluy
 
PDF
Decentralizing Everything with Blockchain
David Paluy
 
PDF
Testing with Rspec 3
David Paluy
 
PDF
Continuous integration for Ruby on Rails
David Paluy
 
PDF
Tdd - Test Driven Development
David Paluy
 
PDF
Knowledge sharing at MESH
David Paluy
 
PDF
Juicy Ruby 2.1
David Paluy
 
ODP
The Secret: How Programmers Develop Code
David Paluy
 
ODP
Tools to help you understand other people's code
David Paluy
 
ODP
Debugging and Profiling Rails Application
David Paluy
 
PDF
Ruby On Rails coding conventions, standards and best practices
David Paluy
 
PDF
Git flow Introduction
David Paluy
 
ODP
Faster on Rails
David Paluy
 
PPT
Howto prepare fund raising presentation
David Paluy
 
PPT
Test driven-development
David Paluy
 
Intro to Smart Contracts
David Paluy
 
Decentralizing Everything with Blockchain
David Paluy
 
Testing with Rspec 3
David Paluy
 
Continuous integration for Ruby on Rails
David Paluy
 
Tdd - Test Driven Development
David Paluy
 
Knowledge sharing at MESH
David Paluy
 
Juicy Ruby 2.1
David Paluy
 
The Secret: How Programmers Develop Code
David Paluy
 
Tools to help you understand other people's code
David Paluy
 
Debugging and Profiling Rails Application
David Paluy
 
Ruby On Rails coding conventions, standards and best practices
David Paluy
 
Git flow Introduction
David Paluy
 
Faster on Rails
David Paluy
 
Howto prepare fund raising presentation
David Paluy
 
Test driven-development
David Paluy
 
Ad

Recently uploaded (14)

PDF
Why Tripura Now Relies Heavily on Civil Services Over IAS Officers.pdf
blogging022
 
PPTX
Emotional Intelligence Understanding and Recognition
ssuser9fcca3
 
DOCX
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
ERKhelemba
 
PDF
self love, mindfulness, psychology, growth
tanya99budhiraja
 
PDF
Make an IMPACT: A Framework to Transform People, Teams, and Futures
Chandan Patary
 
PPT
Assessment according to 19011-3 presentation.ppt
ibr1722011
 
PPTX
09CHAPTER-O1-Areas-Exposed-to-Hazards-Disaster-from-Difft.-Perspectives.pptx
jeromedmangino23
 
PPTX
Banking_Fraud_Presentation_with_Visuals.
johnwick25061999
 
PPTX
what is personality and Personality Development.pptx
Teenu10
 
PPTX
why-journaling-helps-in-self-growth.pptx
StrengthsTheatre
 
PPTX
Positive Role Modeling for Personal Growth.pptx
StrengthsTheatre
 
PPTX
Jurnal international conferences ISSRESTEC
TheodoraSinta
 
PPTX
UP SDRF History English.pptxdownload it is easy to understand
aanyatiwari1015
 
PPTX
Presentatiof local anaesthesiaonon1.pptx
harmanjotsingh483731
 
Why Tripura Now Relies Heavily on Civil Services Over IAS Officers.pdf
blogging022
 
Emotional Intelligence Understanding and Recognition
ssuser9fcca3
 
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
ERKhelemba
 
self love, mindfulness, psychology, growth
tanya99budhiraja
 
Make an IMPACT: A Framework to Transform People, Teams, and Futures
Chandan Patary
 
Assessment according to 19011-3 presentation.ppt
ibr1722011
 
09CHAPTER-O1-Areas-Exposed-to-Hazards-Disaster-from-Difft.-Perspectives.pptx
jeromedmangino23
 
Banking_Fraud_Presentation_with_Visuals.
johnwick25061999
 
what is personality and Personality Development.pptx
Teenu10
 
why-journaling-helps-in-self-growth.pptx
StrengthsTheatre
 
Positive Role Modeling for Personal Growth.pptx
StrengthsTheatre
 
Jurnal international conferences ISSRESTEC
TheodoraSinta
 
UP SDRF History English.pptxdownload it is easy to understand
aanyatiwari1015
 
Presentatiof local anaesthesiaonon1.pptx
harmanjotsingh483731
 

Security on Rails