Upgraded Rails to 6, getting Blocked host Error

后端 未结 6 1664
闹比i
闹比i 2021-02-03 19:41

I needed the new function in ActiveStorage to resize_to_fill so I upgraded to Ruby 2.5.1 and Rails 6.

ruby \'2.5.1\'

gem \"rails\", github: \"rails/rails\"
         


        
6条回答
  •  轮回少年
    2021-02-03 20:39

    In Rails 6 Action Pack introduced ActionDispatch::HostAuthorization and by default allows only [IPAddr.new(“0.0.0.0/0”), IPAddr.new(“::/0”), “localhost”]

    You can add arrays of RegExp, Proc, IPAddr and String or a single String in the file config/application.rb like this

    class Application < Rails::Application
      config.hosts << "xxxxxxx-xxxxxxx.c9users.io"
      ...
    end
    

    From "https://drivy.engineering/rails-6-unnoticed-features":

    Rails 6 added a new middleware called ActionDispatch::HostAuthorization allowing you to whitelist some hosts for your application and preventing Host header attacks. You can easily configure it with a String, IPAddr, Proc and RegExp (useful when dealing with wildcard domains).

提交回复
热议问题