How do I add a host to my permitted rails hosts dynamically?

Viewed 350

I need to dynamically add a permitted host to my Rails 6 application during runtime.

I've managed to append to Rails.application.config.hosts at runtime, but I'm still receiving an error Blocked host. Rails appears to ignore the hosts added to Rails.application.config.hosts that are added outside of application.rb and initializers.

Looking at host_authorization.rb, I can't see an obvious way of asking it to listen to new hosts.

My Reasoning:

User's can programmatically create their own 'shop' on our platform, which adds a new 'tenant' (apartment gem) to our multi-tenanted application We also allow them to point their own domains to our application.

However, in order to allow traffic from their custom domain, we currently would require a manual application restart if we stick with the default whitelisted domains.

I know I could use a workaround, and just set the hosts to whitelist everything (Rails.application.config.hosts = nil), but we need to keep the platform secure and automated.

0 Answers
Related