Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Security, Secrets, and Shenanigans
Search
Richard Schneeman
March 06, 2013
Programming
490
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Security, Secrets, and Shenanigans
Richard Schneeman
March 06, 2013
More Decks by Richard Schneeman
See All by Richard Schneeman
[RubyConf] Beware the Dreaded Dead End
schneems
1
400
[Kaigi] Beware the Dead End
schneems
0
210
Threads Aren't Evil
schneems
0
640
Bayes is BAE
schneems
0
4k
Testing the Untestable
schneems
1
950
SLOMO
schneems
2
1.3k
Saving Sprockets
schneems
8
17k
Memory Leaks, Tweaks, and Techniques
schneems
1
260
Speed Science
schneems
20
37k
Other Decks in Programming
See All in Programming
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
250
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
180
Signal Forms: Beyond the Basics @ngBaguette 2026 in Paris
manfredsteyer
PRO
0
230
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.3k
The NotImplementedError Problem in Ruby
koic
1
690
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
230
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
160
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
100
New "Type" system on PicoRuby
pocke
1
790
AIエージェントの隔離技術の徹底比較
kawayu
0
470
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
530
TAKTでAI駆動開発の品質を設計する
j5ik2o
6
1.1k
Featured
See All Featured
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
390
Producing Creativity
orderedlist
PRO
348
40k
How to Think Like a Performance Engineer
csswizardry
28
2.6k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
270
The Spectacular Lies of Maps
axbom
PRO
1
800
Code Review Best Practice
trishagee
74
20k
WENDY [Excerpt]
tessaabrams
11
38k
Exploring anti-patterns in Rails
aemeredith
3
400
The Limits of Empathy - UXLibs8
cassininazir
1
350
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Transcript
Security, Secrets, & Shenanigans Richard Schneeman @schneems
@schneems
Schnauser
None
I <3 Ruby
Hans Peter Von Wolfe (the 5th)
Sextant Gem
Wicked ‘ ‘ Gem
Triage Code codetriage.com
None
Adjunct Professor
Good News Everyone! schneems.com/ut-rails
I work for this one
AUS Ruby Conf
None
Hello wroclove
Close your Laptops
Unless you’re commenting on rails/rails issues
Web Security
What does it mean to be secure
I am not a security researcher
You don’t have to be either
Arm yourself with knowledge
Every system has a weakness
Security Bugs are Bugs
420,000 lines 11 versions 17 errors
Bug free software is impossible
Cover Common Exploits
Talk about Mitigation Strategies
Improve our security processes
Availability
Security isn’t just keeping others out
Staying Available to Serve your customers
DDoS
Distributed Denial of Service
None
None
None
Block IP Addresses
Memory Exploits
:symbols aren’t fancy strings
:symbols are never garbage collected
params[:id].to_sym
params[:id].to_sym Don’t Do This
Parser Exploits
A billion Laughs
<?xml version="1.0"?> <!DOCTYPE lolz [ <!ENTITY lol "lol"> <!ENTITY lol1
"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;"> <!ENTITY lol2 "&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;"> <!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;"> <!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;"> <!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;"> <!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;"> <!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;"> <!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;"> <!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;"> ]> <lolz>&lol9;</lolz>
10 Entities
Each Reference Previous Entries
Consumes ~3GB of ram to process
Like a Zip Bomb for XML parsers
Ouch
modern XML parsers are not vulnerable to this attack Libxml2
Authentication the act of confirming the truth of an attribute
of a datum or entity
e Armadillos
YAML Parser
YAML Ain’t Markup Language
development: adapter: postgresql encoding: utf8 database: my_development pool: 5 host:
localhost config/database.yml
require 'yaml' db_config = YAML::load_file('config/database.yml') puts db_config["development"] # => {
"adapter" => "postgresql", "encoding" => "utf8", "database" => "example_development", "pool" => 5, "host" => "localhost" }
YAML Ain’t just for basic objects
“--- !ruby/array:Array - jacket - sweater” YAML::load => ???
“--- !ruby/array:Array - jacket - sweater” YAML::load => [“jacket”, “sweater”]
“--- !ruby/hash:User email:
[email protected]
” YAML::load => ???
“--- !ruby/hash:User email:
[email protected]
” YAML::load => #<User id: 1, email:
"
[email protected]
">
“--- !ruby/hash:User email:
[email protected]
” YAML::load user = User.new
“--- !ruby/hash:User email:
[email protected]
” YAML::load user = User.new user[:email] =
“
[email protected]
“--- !ruby/hash:User email:
[email protected]
” YAML::load user = User.new user[:email] =
“
[email protected]
“--- !ruby/hash:User email:
[email protected]
” YAML::load user = User.new user[:email] =
“
[email protected]
puts user => #<User id: 1, email: "
[email protected]
">
Interesting, but is it insecure?
class Foo def []=(name, value) puts value * 3 end
end “--- !ruby/hash:Foo bar: hi” YAML::load foo = Foo.new
class Foo def []=(name, value) puts value * 3 end
end “--- !ruby/hash:Foo bar: hi” YAML::load foo = Foo.new foo[:bar] = “hi” => “hihihi”
class Foo def []=(name, value) puts value * 3 end
end “--- !ruby/hash:Foo bar: hi” YAML::load foo = Foo.new foo[:bar] = “hi” => “hihihi”
Let’s Get Dirty
class Foo def []=(name, value) eval(name) + value end end
class Foo def []=(name, value) eval(name) + value end end
--- !ruby/hash:Foo “puts '=== hello there'.inspect;”: hi YAML::load
class Foo def []=(name, value) eval(name) + value end end
--- !ruby/hash:Foo “puts '=== hello there'.inspect;”: hi YAML::load foo = Foo.new foo["puts '=== hello there'.inspect"] = 'hi' === hello there NoMethodError: undefined method `+' for nil:NilClass
class Foo def []=(name, value) eval(name) + value end end
--- !ruby/hash:Foo “puts '=== hello there'.inspect;”: hi YAML::load foo = Foo.new foo["puts '=== hello there'.inspect"] = 'hi' === hello there NoMethodError: undefined method `+' for nil:NilClass
zOMG arbitrary code execution
But how does an attacker get us to execute arbitrary
YAML?
XML Parser
<?xml version="1.0" encoding="UTF-8"?> <boom type="yaml"><![CDATA[--- !ruby/ object:UnsafeObject attribute1: value1 ]]></boom>
By default will parse arbitrary YAML
I’m in UR Servers Executing My Code
Java/ PHP/ C++/ etc. Secure?
Sanatize Your Inputs
And your Floors
Never Trust your users
Or your dogs
Ro Om Ba Attacks
RoOmBa Attacks
Responsible Disclosure
Create a /security report page
None
Intrusion Detection/ Logging
Papertrail
Stay Informed
Subscribe to Security Lists
Patch Early, Patch often
Secrets Secrets Secrets
CSRF
Cross Site Request Forgery
None
config.security_token
the key to your digital kingdom
Would you give your Car key copies to:
Interns? Your
Contractors? Your
Your Open Source Contributors?
If secrets are in your source, you’ve already given them
your digital kingdom
Protect Your Code
Secure keys in source control aren’t secure
What’s an alternative?
Environment Variables
$ rake db:migrate RAILS_ENV=test
$ rake db:migrate RAILS_ENV=test
In Development
Use a .env file
$ cat .env SECRET_TOKEN=d59c2a439f
Use dotenv gem
$ irb > Dotenv.load > puts ENV[‘SECRET_TOKEN’] > “d59c2a439f”
Use foreman gem
$ foreman run irb > puts ENV[‘SECRET_TOKEN’] > “d59c2a439f”
In Production
$ heroku config:add SECRET_TOKEN=d59c2a439f
VPS • Use Foreman/Dotenv • Add to bashrc • Add
values directly to command $ SECRET_TOKEN=asd123 rails console ruby-1.9.3> puts ENV[‘SECRET_TOKEN’] ruby-1.9.3> “asd123”
What if...
Someone Can read my ENV Variables?
Then they can read your files too
Is your app secure?
Is your app open source- able?
SECRET_TOKEN is just one example of Config
Define: Config
Config • What varies between deploys • resource strings to
databases • credentials to S3, twitter, facebook, etc. • canonical values, hostname • security tokens
Can you deploy your app to change your S3 Bucket?
Do you NEED to deploy your app to change your
S3 bucket?
Environment Variables! Use
Config
But I like storing my credentials in git!
What is Config? Just because it works...
Wishlist: rotate-able security tokens
Security
Nothing is ever 100% secure
Educate yourself
Secrets
Don’t store secrets in Git
Use ENV Variables
Shenanigans
None
Vote @hone02 (Terence Lee) Ruby Hero 2013
Questions? @schneems