Skip to content

Instantly share code, notes, and snippets.

@homakov
Last active September 24, 2016 21:30
Show Gist options
  • Select an option

  • Save homakov/ea001418ecf15319a3e0 to your computer and use it in GitHub Desktop.

Select an option

Save homakov/ea001418ecf15319a3e0 to your computer and use it in GitHub Desktop.

Revisions

  1. homakov revised this gist Jun 26, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion config.ru
    Original file line number Diff line number Diff line change
    @@ -4,11 +4,12 @@ require ::File.expand_path('../config/environment', __FILE__)

    #prevents DNS rebinding attacks
    class DNSBinding
    VALID_HOSTS = %w{localhost:9292 myshop.dev:3000 myshopprod.com}
    def initialize(app)
    @app = app
    end
    def call(env)
    if %w{localhost:9292 myshop.dev:3000 myshopprod.com}.include? env['HTTP_HOST']
    if VALID_HOSTS.include? env['HTTP_HOST']
    @app.call(env)
    else
    [403,{},["Invalid Host"]]
  2. homakov revised this gist Jun 26, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion config.ru
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ class DNSBinding
    @app = app
    end
    def call(env)
    if %w{localhost:9292}.include? env['HTTP_HOST']
    if %w{localhost:9292 myshop.dev:3000 myshopprod.com}.include? env['HTTP_HOST']
    @app.call(env)
    else
    [403,{},["Invalid Host"]]
  3. homakov revised this gist Jun 26, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion config.ru
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,6 @@ class DNSBinding
    @app = app
    end
    def call(env)
    puts env['HTTP_HOST']
    if %w{localhost:9292}.include? env['HTTP_HOST']
    @app.call(env)
    else
  4. homakov created this gist Jun 26, 2015.
    20 changes: 20 additions & 0 deletions config.ru
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    # This file is used by Rack-based servers to start the application.

    require ::File.expand_path('../config/environment', __FILE__)

    #prevents DNS rebinding attacks
    class DNSBinding
    def initialize(app)
    @app = app
    end
    def call(env)
    puts env['HTTP_HOST']
    if %w{localhost:9292}.include? env['HTTP_HOST']
    @app.call(env)
    else
    [403,{},["Invalid Host"]]
    end
    end
    end
    use DNSBinding
    run Rails.application