mbleigh / subdomain-fu

A new plugin approach to attempting to solve the usage of subdomains in linking and routing in Rails projects.
http://rdoc.info/projects/mbleigh/subdomain-fu
Other
586 stars 118 forks source link

Exceptions thrown when someone requests without Host: HTTP header #22

Open kylev opened 13 years ago

kylev commented 13 years ago

http://apidock.com/rails/ActionController/Request/domain

ActionController::Request.domain() will return nil if someone comes to a site using subdomain-fu using only the server's IP address, such as http://10.2.3.4/zomg-haxor.php . In the real world, this sort of thing will happen fairly frequently thanks to security probes, ill-written bots, and crummy HTTP clients. This causes an error, attempting to apply '+' to nil:

gems/subdomain-fu-0.5.4/lib/subdomain-fu.rb:145:in `current_domain'

subdomain-fu should gracefully degrade in some way.

pboling commented 13 years ago

This is fixed in many of the forks, mine being one example: https://github.com/pboling/subdomain-fu

It is Rails 3 compatible with a very large test suite. :)

kylev commented 13 years ago

I might monkey-patch ActionController::Request thusly

def domain_with_default
  domain_without_default || 'example.com'
end
alias_method_chain :domain, :default