Last active
September 24, 2016 21:30
-
-
Save homakov/ea001418ecf15319a3e0 to your computer and use it in GitHub Desktop.
config.ru
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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
@homakov why not go even further and suggest this be baked into Rails-core? at least for the default case
localhost:3000
, or even better, construct theVALID_HOSTS
part dynamically on server start, since we can pick the port and the dev url easily. For production we insert a guideline in the security guide. Your thoughts?