未验证 提交 1c6f8e3e 编写于 作者: B bogdanvlviv

Add `ActionDispatch::HostAuthorization` to "Configuring Middleware" guide [ci skip]

This commit copies info from
https://github.com/rails/rails/pull/33145
([an excellent changelog](https://github.com/rails/rails/blob/6-0-stable/railties/CHANGELOG.md)) to
our guides.

Closes https://github.com/rails/rails/issues/36959
Not sure whether there is a need mentioning `config.hosts` in the "Upgrading to Rails 6.0" guide
since it is configured to work in the development environment by default and we guide how to deal
with "blocked host" issue, see:
https://github.com/rails/rails/blob/6-0-stable/actionpack/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb

I would like to backport this to `6-0-stable` so users will be able to
find info about `ActionDispatch::HostAuthorization` middleware and how
to configure it.

Give credit to @gsamokovarov since I copied the info from the changelog. <3

[bogdanvlviv, Genadi Samokovarov]
上级 785427b8
......@@ -232,6 +232,44 @@ The full set of methods that can be used in this block are as follows:
Every Rails application comes with a standard set of middleware which it uses in this order in the development environment:
* `ActionDispatch::HostAuthorization` prevents against DNS rebinding and other `Host` header attacks.
It is included in the development environment by default with the following configuration:
```ruby
Rails.application.config.hosts = [
IPAddr.new("0.0.0.0/0"), # All IPv4 addresses.
IPAddr.new("::/0"), # All IPv6 addresses.
"localhost" # The localhost reserved domain.
]
```
In other environments `Rails.application.config.hosts` is empty and no
`Host` header checks will be done. If you want to guard against header
attacks on production, you have to manually permit the allowed hosts
with:
```ruby
Rails.application.config.hosts << "product.com"
```
The host of a request is checked against the `hosts` entries with the case
operator (`#===`), which lets `hosts` support entries of type `Regexp`,
`Proc` and `IPAddr` to name a few. Here is an example with a regexp.
```ruby
# Allow requests from subdomains like `www.product.com` and
# `beta1.product.com`.
Rails.application.config.hosts << /.*\.product\.com/
```
A special case is supported that allows you to permit all sub-domains:
```ruby
# Allow requests from subdomains like `www.product.com` and
# `beta1.product.com`.
Rails.application.config.hosts << ".product.com"
```
* `ActionDispatch::SSL` forces every request to be served using HTTPS. Enabled if `config.force_ssl` is set to `true`. Options passed to this can be configured by setting `config.ssl_options`.
* `ActionDispatch::Static` is used to serve static assets. Disabled if `config.public_file_server.enabled` is `false`. Set `config.public_file_server.index_name` if you need to serve a static directory index file that is not named `index`. For example, to serve `main.html` instead of `index.html` for directory requests, set `config.public_file_server.index_name` to `"main"`.
* `ActionDispatch::Executor` allows thread safe code reloading. Disabled if `config.allow_concurrency` is `false`, which causes `Rack::Lock` to be loaded. `Rack::Lock` wraps the app in mutex so it can only be called by a single thread at a time.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册