Skip to content

Instantly share code, notes, and snippets.

@davydovanton
Forked from homakov/config.ru
Created September 24, 2016 21:30
Show Gist options
  • Save davydovanton/3e84b9e2a8e05cfba427fea0075f27bc to your computer and use it in GitHub Desktop.
Save davydovanton/3e84b9e2a8e05cfba427fea0075f27bc to your computer and use it in GitHub Desktop.
config.ru
# 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
VALID_HOSTS = %w{localhost:9292 myshop.dev:3000 myshopprod.com}
def initialize(app)
@app = app
end
def call(env)
if VALID_HOSTS.include? env['HTTP_HOST']
@app.call(env)
else
[403,{},["Invalid Host"]]
end
end
end
use DNSBinding
run Rails.application
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment