Railsのconfigurationを調べてみた(2)
なに?
Railsのconfigurationはどんなものがあって、どういう挙動なのかを調べてみた。
今回調べたものはActionDispatchに含まれるconfigだけである。
# ActionDispatchに関するconfigurationは、以下のように`action_dispatch`をはさむ。
config.action_dispatch.x_sendfile_header = nil
各項目の細かい挙動まで十分に調べきれてはいないが、よく設定する項目などは別途調べたい。
ばーじょん
- Ruby ruby 2.7.2p137
- Rails 6.1.2
いちらん
x_sendfile_header(string)
send_file
でファイルを返すときに付与するHTTPヘッダーを指定する。
デフォルトはnil
。
X-Sendfile
という機能(仕様?)がProxyサーバに実装されている場合、HTTPヘッダーをProxyサーバの仕様に合わせて設定することで、Proxyサーバがファイルを返してくれるようだ。
NGINXの場合は、以下にサンプルがある。
ip_spoofing_check(boolean)
IPスプーフィングのチェックを行うかを指定する。
デフォルトはtrue
。
デフォルトで信頼済みに設定されているのは、以下の6種類。
"127.0.0.0/8"
"::1"
"fc00::/7"
"10.0.0.0/8"
"172.16.0.0/12"
"192.168.0.0/16"
追加したい場合はconfig.action_dispatch.trusted_proxies
で設定できる。
show_exceptions(boolean)
例外発生時に、例外情報を表示するかを指定する。
デフォルトはtrue
。
config.consider_all_requests_local
は、詳細に表示するかの設定で、少し意味合いが異なる。
※config.consider_all_requests_local
は、ActionDispatch内ではaction_dispatch.show_detailed_exceptions
として参照される。
tld_length(integer)
TLDの階層を指定する。
デフォルトは1
。
dev.www.example.co.jp
のように、サブドメインで運用する場合は2
とする。
ignore_accept_header(boolean)
HTTPヘッダーのAccept
を無視するかどうかを指定する。
デフォルトはfalse
。
無視した場合はformat
パラメータや、URLの拡張子(index.html
など)などから判断する。
rescue_templates(hash)
例外発生時に、例外クラスに応じたテンプレートを表示するための設定をする。
(config.action_dispatch.show_exceptions == true
のときに利用される)
デフォルトは以下の通り。
例外クラス | テンプレート名 |
---|---|
ActionView::MissingTemplate |
missing_template |
ActionController::RoutingError |
routing_error |
AbstractController::ActionNotFound |
unknown_action |
ActiveRecord::StatementInvalid |
invalid_statement |
ActionView::Template::Error |
template_error |
ActionController::MissingExactTemplate |
missing_exact_template |
rescue_responses(hash)
例外発生時に、例外クラスに応じたHTTP Status Codeを返すための設定をする。
デフォルトは以下の通り。
例外クラス | ステータス名 |
---|---|
ActionController::RoutingError |
:not_found |
AbstractController::ActionNotFound |
:not_found |
ActionController::MethodNotAllowed |
:method_not_allowed |
ActionController::UnknownHttpMethod |
:method_not_allowed |
ActionController::NotImplemented |
:not_implemented |
ActionController::UnknownFormat |
:not_acceptable |
ActionDispatch::Http::MimeNegotiation::InvalidType |
:not_acceptable |
ActionController::MissingExactTemplate |
:not_acceptable |
ActionController::InvalidAuthenticityToken |
:unprocessable_entity |
ActionController::InvalidCrossOriginRequest |
:unprocessable_entity |
ActionDispatch::Http::Parameters::ParseError |
:bad_request |
ActionController::BadRequest |
:bad_request |
ActionController::ParameterMissing |
:bad_request |
Rack::QueryParser::ParameterTypeError |
:bad_request |
Rack::QueryParser::InvalidParameterError |
:bad_request |
default_charset(string)
レスポンスのcharsetを指定する。
デフォルトはnil
で、nil
の場合はconfig.encoding
が設定される。
なお、config.encoding
はUTF-8
固定になっている。
rack_cache(?)
Rackベースでcacheするための設定のようだ。
デフォルトはfalse
。
Railsにcacheする機能はなく、以下のような3rd partyのgemを使って、利用するようだ。
http_auth_salt(string)
HTTP Authのsalt値を指定する。
デフォルトは"http authentication"
。
signed_cookie_salt(string)
署名済みcookie用のsalt値を指定する。
デフォルトは"signed cookie"
。
encrypted_cookie_salt(string)
暗号化済みcookie用のsalt値を指定する。
デフォルトは"encrypted cookie"
。
encrypted_signed_cookie_salt(string)
署名暗号化済みcookie用のsalt値を指定する。
デフォルトは"signed encrypted cookie"
。
authenticated_encrypted_cookie_salt(string)
認証された暗号化済みcookieのsalt値を指定する。
デフォルトは"authenticated encrypted cookie"
。
use_authenticated_cookie_encryption(boolean)
AES-256-GCM
を使ってcookieを暗号化するかどうかを指定する。
デフォルトはfalse
。
ただし、5.2以降のデフォルト設定を読み込むとtrue
になる。
use_cookies_with_metadata(boolean)
cookieにメタデータ(purpose
)を利用するかどうかを指定する。
デフォルトはfalse
。
ただし、6.0以降のデフォルト設定を読み込むとtrue
になる。
perform_deep_munge(boolean)
nil
になるようなparameterを除外するかどうかを指定する。
ActiveRecordを使う際に、意図しない挙動で脆弱性に繋がりかねないために導入された。
デフォルトはtrue
。
詳しくは、Rails Guideを参照。
request_id_header(string)
HTTPヘッダーに設定するRequest IDを指定する。
デフォルトは"X-Request-Id"
。
default_headers(hash)
HTTPヘッダーにデフォルトで設定するヘッダーを設定する。
デフォルトは{}
。
cookies_rotations(object)
cookieをローテートするためのinstanceを設定する。
デフォルトはActiveSupport::Messages::RotationConfiguration.new
。
旧方式から新方式に切り替えたとき、旧方式で生成されたcookieが読み込めなくなったり、旧方式のまま使い続けることを避けるためのローテーター。
詳しくは、Rails Guideを参照。
always_write_cookie(boolean)
cookieを書き込むかを指定する。
デフォルトは未設定だが、developmentモードのときはtrue
になる。
リクエストがhttps
か、secureなcookieか、本プロパティがtrue
の場合に、cookieが書き込まれる。
Discussion