Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RailsConf 2013

RailsConf 2013

Aaron Patterson

May 09, 2013
Tweet

More Decks by Aaron Patterson

Other Decks in Technology

Transcript

  1. Keynote: Ă Dev conferences, round tables, serving spaghetti with one

    chop stick on each side of each person. Boutique hotel, the doub le tree.
  2. Sprinkle of JS! I’m last so I have the last

    word, I can troll all the rest of the keynote speakers and there is nothing they can do. Told DHH it was good that he spoke first so I could troll him with no rebuttal. Yehuda sprinkled us with JavaScript
  3. AT&T, AT&T logo and all AT&T related marks are trademarks

    of AT&T Intellectual Property and/or AT&T affiliated companies.
  4. When I previewed the fax in the expense reporting system,

    there were tons of these at the bottom.
  5. When I previewed the fax in the expense reporting system,

    there were tons of these at the bottom.
  6. Interfaces & Adapters It’s kind of genius because there was

    a legacy system, the fax machine, they needed to support. People want Email, so we give them the email interface, but it actually just adapts to the existing code Imagine being in the meeting where they decided to do this.
  7. SEO Optimization To understand SEO, we must understand the search

    engine. It says Search Engine Optimization Optimization, but that is what we do.
  8. Invented in holland and came to the united states along

    with Lief Erikson (who later went on to invent cell phones). In the US they were improved to be gasoline powered with pistons. You can tell this bit of history from the names.
  9. Invented in holland and came to the united states along

    with Lief Erikson (who later went on to invent cell phones). In the US they were improved to be gasoline powered with pistons. You can tell this bit of history from the names.
  10. Invented in holland and came to the united states along

    with Lief Erikson (who later went on to invent cell phones). In the US they were improved to be gasoline powered with pistons. You can tell this bit of history from the names.
  11. By shouting, we can actually improve the performance of the

    search engine. Back when shouting at machines actually did something.
  12. By shouting, we can actually improve the performance of the

    search engine. Back when shouting at machines actually did something.
  13. Alexander Searchkeyword This lead to search engine dowsers. They would

    use dowsing rods to find the right keywords from dictionaries and shout them at the search engine.
  14. Alexander Searchkeyword This lead to search engine dowsers. They would

    use dowsing rods to find the right keywords from dictionaries and shout them at the search engine.
  15. Doing Client Work. For a small fee, I will come

    to your house, read your web page, and dowse the right keywords for the search engine
  16. Job Definition class Job def initialize(user_id) @user_id = user_id end

    def run user = User.find @user_id # .... end end
  17. F-

  18. describe "whatever" do setup do # ... end it "does

    some stuff" do 1.must_equal 1 end describe "some other stuff" do it "does some other stuff" do 'foo'.must_match /foo/ end end end This is what a minitest/ spec looks like. It looks very similar to RSpec, but it isn’t.
  19. class SomeTest < ActiveSupport::TestCase setup { # ... } test

    "some thing" do # ... end end Rails Tests Here is a Rails test with some of the DSL features that Rails adds on.
  20. MiniTest::Spec class SomeTest < MiniTest::Spec setup { # ... }

    it "some thing" do # ... end end If we compare this to a minitest/spec test, it looks very similar.
  21. Refactor class SomeTest < MiniTest::Spec class << self alias :test

    :it end setup { # ... } test "some thing" do # ... end end We can make the appropriate change to minitest/spec and now it looks exactly the same.
  22. AS::TestCase class ActiveSupport::TestCase < MiniTest::Spec class << self alias :test

    :it end end class SomeTest < ActiveSupport::TestCase setup { # ... } test "some thing" do # ... end end The cool thing is that it’s 100% backwards compatible. Works exactly the same as minitest/unit.
  23. Free goodies! describe "whatever" do it "does some stuff" do

    1.must_equal 1 end describe "some other stuff" do it "does some other stuff" do 'foo'.must_match /foo/ end end end
  24. F-

  25. Example class BrowserController < ApplicationController include ActionController::Live def index 100.times

    do response.stream.write "hello!\n" end response.stream.close end end
  26. Example class BrowserController < ApplicationController include ActionController::Live def index 100.times

    do response.stream.write "hello!\n" end response.stream.close end end Mix in Stream
  27. Puma Browser FS-Events FS Events When the FS changes, it

    tells the webserver, webserver tells the browser All in the same process.
  28. Puma Browser FS-Events FS Events When the FS changes, it

    tells the webserver, webserver tells the browser All in the same process.
  29. Puma Browser FS-Events FS Events When the FS changes, it

    tells the webserver, webserver tells the browser All in the same process.
  30. Puma Browser Console DRB DB Events When a model changes,

    a message is sent via DRB running in the Puma process. That also notifies the browser.
  31. Puma Browser Console DRB DB Events Socket When a model

    changes, a message is sent via DRB running in the Puma process. That also notifies the browser.
  32. create_table(:foos, id: :uuid) do |t| # ... end Generates a

    unique ID rather than sequential. We can easily partition based on this ID.
  33. Faster Tests* *they’re not actually faster (well, they might be)

    Look at the speed improvement, then talk about how it works.
  34. Rails 3.2 (1 test) $ time ruby -I lib:test test/functional/

    line_items_controller_test.rb real 0m1.733s user 0m1.518s sys 0m0.203s
  35. Rails 4.0 (1 test) $ time ruby -I lib:test test/controllers/

    line_items_controller_test.rb real 0m1.753s user 0m1.535s sys 0m0.208s
  36. Environment $ time ruby -Ilib:test:. -rconfig/ environment -e ' '

    real 0m1.442s user 0m1.255s sys 0m0.179s Require the environment, and do nothing. Loads the application.
  37. Sample Test Task # Rakefile Rake::TestTask.new do |t| t.libs <<

    "test" t.verbose = true t.warning = true end
  38. Change the env before app load If it loosk like

    you’re running a test task, then change the env to the test env.
  39. Migrations $ rake test You have 1 pending migrations: 20130401175825

    CreateUsers Run `rake db:migrate` to update your database then try again.
  40. I hate Security * I am not a security expert

    Wasted money, wasted effort. Tiny percentage of people are ruining it for everyone.
  41. Ok, I don’t hate Security * I am not a

    security expert I don’t want people’s sites to be hacked.
  42. “Security is a process” - Bruce Schneier Security is iterative,

    but we’ll talk about something much more pedestrian which is the actual process
  43. Analyze and Patch Determine severity, figure out which versions are

    impacted, create backports and include version info for CVE.
  44. Secrecy We keep issues secret until release because it takes

    time to find impacted versions, make fixes, information must be through official channels.
  45. Symbols are not GC’d At a high level, there are

    strings coming in to the system, and Rails is converting them to symbols. I’ll show you two popular methods for getting strings converted to symbols.
  46. Max Symbol Size irb(main):002:0> ("x" * 1024).to_sym; nil => nil

    irb(main):003:0> ("x" * 1000024).to_sym; nil => nil irb(main):004:0> ("x" * 10000000024).to_sym; nil ^C^C^C^CKilled: 9
  47. 34%

  48. Max Symbol Size irb(main):001:0> ("x" * 100000024).to_sym; nil => nil

    irb(main):002:0> ("x" * 1000000024).to_sym; nil => nil irb(main):003:0> Tried again, and this worked.
  49. F-

  50. Active Record def index User.where(params[:foo]) end In the controller there

    is something like this. Someone posts JSON so the params are automatically converted to a hash, and the strings are converted to symbols
  51. F-

  52. assert_difference('Symbol.all_symbols.count', 0) do # some code end Symbol.all_symbols Helps if

    there is a specific place you know to check for symbols in your system.
  53. ruby$target:::symbol-create { @_[copyinstr(arg1), arg2] = count(); } DTrace This will

    give you an aggregate of where the symbols are created.
  54. Any Foreign Objects Are Bad Talk about YAML, but having

    any foreign objects injected to your system is incredibly bad.
  55. A Hash Subclass > class Foo < Hash; end >

    x = Foo.new > x[:y] = "hello" > puts Psych.dump x --- !ruby/hash:Foo :y: hello
  56. Troubled Code class Helpers def initialize @module = Module.new end

    def []=(key, value) @module.module_eval <<-END_EVAL def #{value}(*args) # ... other stuff end END_EVAL end end Have essentially this in rails where helpers are defined.
  57. Exploit --- !ruby/hash:Helpers foo: |- mname; end; puts 'hello!'; def

    oops Here is the YAML we can use to exploit this. Tell the parser to load a hash with the class Helpers
  58. Exploit --- !ruby/hash:Helpers foo: |- mname; end; puts 'hello!'; def

    oops Here is the YAML we can use to exploit this. Tell the parser to load a hash with the class Helpers
  59. Exploit --- !ruby/hash:Helpers foo: |- mname; end; puts 'hello!'; def

    oops Here is the YAML we can use to exploit this. Tell the parser to load a hash with the class Helpers
  60. F-

  61. Bearer of Bad News “Hey guys, you’re gonna laugh when

    you hear this, but someone can execute arbitrary Ruby code on your system”
  62. F: interesting arel behavior change that led to our email

    debacle this morning Me: huh? Me: email debacle? F: oh boy F: interesting thing is that it happened because of an arel behavior change in one of the recent 3.x security bumps
  63. 3.2.12 User.where(:id => 10) .find(100) `users`.`id` = 10 AND `users`.`id`

    = 100 User.where(:id => 10) .find_by_id(100) `users`.`id` = 10 AND `users`.`id` = 100 Empty Model User.where(:id => 10) .find(100) `users`.`id` = 10 AND `users`.`id` = 100 User.where(:id => 10) .find_by_id(100) `users`.`id` = 100 Default Scope Model
  64. 3.2.12 User.where(:id => 10) .find(100) `users`.`id` = 10 AND `users`.`id`

    = 100 User.where(:id => 10) .find_by_id(100) `users`.`id` = 10 AND `users`.`id` = 100 Empty Model User.where(:id => 10) .find(100) `users`.`id` = 10 AND `users`.`id` = 100 User.where(:id => 10) .find_by_id(100) `users`.`id` = 100 Default Scope Model
  65. 3.2.12 User.where(:id => 10) .find(100) `users`.`id` = 10 AND `users`.`id`

    = 100 User.where(:id => 10) .find_by_id(100) `users`.`id` = 10 AND `users`.`id` = 100 Empty Model User.where(:id => 10) .find(100) `users`.`id` = 10 AND `users`.`id` = 100 User.where(:id => 10) .find_by_id(100) `users`.`id` = 100 Default Scope Model
  66. 3.2.13 User.where(:id => 10) .find(100) `users`.`id` = 10 AND `users`.`id`

    = 100 User.where(:id => 10) .find_by_id(100) `users`.`id` = 10 AND `users`.`id` = 100 Empty Model User.where(:id => 10) .find(100) `users`.`id` = 100 User.where(:id => 10) .find_by_id(100) `users`.`id` = 100 Default Scope Model
  67. Secrecy XML symbol issue lead to the YAML issue. Can’t

    tell people to stop because I’ll give legitimacy. Painful to watch
  68. Getting a Job Presentation to my boss about tools that

    I’ve written for my team mates.
  69. FOCUS on the future Talking about the past only results

    in blaming, talking about the present divides people, separating in to groups (like this VM has a better GC, this VM is faster) Focusing on the future is what brings us together and pushes life forward.
  70. Health Walk. Go to 7-11, find gummies, start buying them

    every week. One day the guy says “hey! Mamba Time!” I am the guy that buys gummy bears. I will be the best damn gummy candy buyer ever.
  71. Find your Mamba Time Contributing impacts people whether or not

    you know it. You need to find that thing, and stick to that thing.
  72. F-