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
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
210
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
260
CSC307 Lecture 17
javiergs
PRO
0
320
AIで効率化できた業務・日常
ochtum
0
140
Oxlintのカスタムルールの現況
syumai
6
1.1k
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
140
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.7k
「エンジニアインターン、どうやって取った?」準備のリアルを語るLT会 Progate BAR
akiomatic
0
130
Lessons from Spec-Driven Development
simas
PRO
0
210
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
550
Featured
See All Featured
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
200
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
400
Information Architects: The Missing Link in Design Systems
soysaucechin
0
970
30 Presentation Tips
portentint
PRO
1
330
The Curious Case for Waylosing
cassininazir
1
390
Building Adaptive Systems
keathley
44
3.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.7k
Navigating Weather and Climate Data
rabernat
0
220
We Are The Robots
honzajavorek
0
250
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
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