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

PDF
The Next Five Years of Rails
PDF
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
PDF
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
PDF
The Complementarity of React and Web Components
PDF
Esri Dev Summit 2009 Rest and Mvc Final
PPTX
Introduction to Backbone.js & Marionette.js
PPT
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
PPT
Top Ten Web Application Defenses v12
The Next Five Years of Rails
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
The Complementarity of React and Web Components
Esri Dev Summit 2009 Rest and Mvc Final
Introduction to Backbone.js & Marionette.js
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
Top Ten Web Application Defenses v12

What's hot (20)

PDF
Javaland 2017: "You´ll do microservices now". Now what?
PDF
Von JavaEE auf Microservice in 6 Monaten - The Good, the Bad, and the wtfs...
PPTX
Das kannste schon so machen
PPT
Getting started with angular js
PDF
webcomponents (Jfokus 2015)
PDF
Our application got popular and now it breaks
PPTX
Authenticating and Securing Node.js APIs
PPTX
Building Layers of Defense with Spring Security
PDF
OWASP SF - Reviewing Modern JavaScript Applications
PPTX
Cross Site Scripting (XSS) Defense with Java
PPT
Top Ten Proactive Web Security Controls v5
PDF
AtlasCamp 2014: 10 Things a Front End Developer Should Know About Connect
PDF
Design & Development of Web Applications using SpringMVC
PDF
Cutting the Fat
PDF
XSS Magic tricks
PDF
Azure Container Apps
PDF
The Future of CSS with Web Components
PPTX
Mvvm knockout vs angular
KEY
An Introduction to webOS
PDF
Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...
Javaland 2017: "You´ll do microservices now". Now what?
Von JavaEE auf Microservice in 6 Monaten - The Good, the Bad, and the wtfs...
Das kannste schon so machen
Getting started with angular js
webcomponents (Jfokus 2015)
Our application got popular and now it breaks
Authenticating and Securing Node.js APIs
Building Layers of Defense with Spring Security
OWASP SF - Reviewing Modern JavaScript Applications
Cross Site Scripting (XSS) Defense with Java
Top Ten Proactive Web Security Controls v5
AtlasCamp 2014: 10 Things a Front End Developer Should Know About Connect
Design & Development of Web Applications using SpringMVC
Cutting the Fat
XSS Magic tricks
Azure Container Apps
The Future of CSS with Web Components
Mvvm knockout vs angular
An Introduction to webOS
Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...
Ad

Similar to Security on Rails (20)

PDF
Security in Node.JS and Express:
PDF
Neoito — Secure coding practices
PPTX
OWASP ZAP Workshop for QA Testers
PDF
Rails Security
PDF
Breaking Bad CSP
PPTX
DevOps and the Future of Enterprise Security
PDF
JSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
PDF
Pawel Cygal - SQL Injection and XSS - Basics (Quality Questions Conference)
PDF
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
PPTX
ASP.NET Web Security
PDF
Whatever it takes - Fixing SQLIA and XSS in the process
PDF
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
ODP
Hunting Security Bugs in Modern Web Applications
PDF
They Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
PDF
手把手教你如何串接 Log 到各種網路服務
PPTX
Hackers vs developers
PDF
Web Security 101
PDF
Application Security around OWASP Top 10
PPT
Web Apps Security
PDF
Reviewing AngularJS
Security in Node.JS and Express:
Neoito — Secure coding practices
OWASP ZAP Workshop for QA Testers
Rails Security
Breaking Bad CSP
DevOps and the Future of Enterprise Security
JSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
Pawel Cygal - SQL Injection and XSS - Basics (Quality Questions Conference)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
ASP.NET Web Security
Whatever it takes - Fixing SQLIA and XSS in the process
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
Hunting Security Bugs in Modern Web Applications
They Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
手把手教你如何串接 Log 到各種網路服務
Hackers vs developers
Web Security 101
Application Security around OWASP Top 10
Web Apps Security
Reviewing AngularJS
Ad

More from David Paluy (15)

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

Recently uploaded (20)

PPTX
The Hidden Link Between Self-Talk and Self-Worth.pptx
PPTX
show1- motivational ispiring positive thinking
PDF
Red Light Wali Muskurahat – A Heart-touching Hindi Story
PPTX
Identity Development in Adolescence.pptx
PDF
Quiet Wins: Why the Silent Fish Survives.pdf
PPTX
UNIVERSAL HUMAN VALUES for NEP student .pptx
DOCX
Boost your energy levels and Shred Weight
PPTX
SELF ASSESSMENT -SNAPSHOT.pptx an index of yourself by Dr NIKITA SHARMA
PPT
cypt-cht-healthy-relationships-part1-presentation-v1.1en.ppt
PPTX
Presentation on interview preparation.pt
PDF
⚡ Prepping for grid failure_ 6 Must-Haves to Survive Blackout!.pdf
PDF
technical writing on emotional quotient ppt
PDF
SEX-GENDER-AND-SEXUALITY-LESSON-1-M (2).pdf
PPTX
THEORIES-PSYCH-3.pptx theory of Abraham Maslow
PPTX
Pradeep Kumar Roll no.30 Paper I.pptx....
PPTX
How to Deal with Imposter Syndrome for Personality Development?
PPT
proper hygiene for teenagers for secondary students .ppt
PPTX
Personal Development - By Knowing Oneself?
PPTX
Travel mania in india needs to change the world
PDF
Top 10 Visionary Entrepreneurs to Watch in 2025
The Hidden Link Between Self-Talk and Self-Worth.pptx
show1- motivational ispiring positive thinking
Red Light Wali Muskurahat – A Heart-touching Hindi Story
Identity Development in Adolescence.pptx
Quiet Wins: Why the Silent Fish Survives.pdf
UNIVERSAL HUMAN VALUES for NEP student .pptx
Boost your energy levels and Shred Weight
SELF ASSESSMENT -SNAPSHOT.pptx an index of yourself by Dr NIKITA SHARMA
cypt-cht-healthy-relationships-part1-presentation-v1.1en.ppt
Presentation on interview preparation.pt
⚡ Prepping for grid failure_ 6 Must-Haves to Survive Blackout!.pdf
technical writing on emotional quotient ppt
SEX-GENDER-AND-SEXUALITY-LESSON-1-M (2).pdf
THEORIES-PSYCH-3.pptx theory of Abraham Maslow
Pradeep Kumar Roll no.30 Paper I.pptx....
How to Deal with Imposter Syndrome for Personality Development?
proper hygiene for teenagers for secondary students .ppt
Personal Development - By Knowing Oneself?
Travel mania in india needs to change the world
Top 10 Visionary Entrepreneurs to Watch in 2025

Security on Rails