なるようになるブログ

読書感想文かrailsについてかrubyについてか

rails commit log流し読み(2016/04/12)

2016/04/12分のコミットです。

CHANGELOGへの追加はありませんでした。


Merge pull request #24485 from prathamesh-sonpatki/protected_database_env_message

activerecord/lib/active_record/migration.rbの修正です。

ProtectedEnvironmentErrorが発生した場合に表示されるエラーメッセージのグラマーの修正を行っています。


remove explicit curlies for hash argument

railties/lib/rails/application.rbの修正です。

env_configメソッドでHashの生成を行っている箇所にあった不要な中括弧を削除しています。


edit pass over the RDoc of Rails::Railtie [ci skip]

railties/lib/rails/railtie.rbのdocの修正です

Rails::Railtieクラスのdocの、グラマー、フォーマットの修正等をまとめて行っています。


Improved ActionView flows.rb documention [ci skip]

actionview/lib/action_view/flows.rbのdocの修正です。

ActionView::OutputFlow#getメソッド、及びActionView::StreamingFlow#append!メソッドのdoc内のメソッドの説明についての言い回しの修正を行なっています。


Pass over all Rails 5 warnings, to make sure:

Rails 5で表示されるようになったwarningメッセージのグラマーの修正、及び各メッセージの終端にピリオドの追加を行っています。


[ci skip] This modifies the HTTP Token authentication example's authenticate method, to use the secure_compare method with two constant-length strings. This defends against timing attacks, and is best practice. Using == for sensitive actions is not recommended, and this was the source of a CVE fixed in October 2015: https://github.com/rails/rails/commit/17e6f1507b7f2c2a883c180f4f9548445d6dfbda

actionpack/lib/action_controller/metal/http_authentication.rbのdocの修正です。

ActionController::HttpAuthentication::Basic moduleのdoc内にあるauthenticate処理のexampleコードで、String#==で比較処理を行っていたのを、ActiveSupport::SecurityUtils.secure_compareを行って比較処理を行うよう修正しています。

     #       def authenticate
     #         authenticate_or_request_with_http_token do |token, options|
-    #           token == TOKEN
+    #           # Compare the tokens in a time-constant manner, to mitigate
+    #           # timing attacks.
+    #           ActiveSupport::SecurityUtils.secure_compare(
+    #             ::Digest::SHA256.hexdigest(token),
+    #             ::Digest::SHA256.hexdigest(TOKEN)
+    #           )
     #         end

AStringの比較処理の実行時間からパスワードを推測されるのを避ける為。


set default parameter to nil to speed up attribute_changed?

activemodel/lib/active_model/dirty.rbの修正です。

#attribute_changed?メソッドoptionsパラメータのデフォルト値をnilに変更し、optionsが設定されてない場合は、optionsに関する処理を行わないよう修正しています。


Merge pull request #24490 from prathamesh-sonpatki/add-config-to-deprecation-warning

railties/lib/rails/application/configuration.rbの修正です。

static_cache_controlserve_static_filesを使用した場合に出力されるdeprecateメッセージの各パラメータの箇所に、configを追加しています。

        ActiveSupport::Deprecation.warn <<-eow.strip_heredoc
-          `static_cache_control` is deprecated and will be removed in Rails 5.1.
+          `config.static_cache_control` is deprecated and will be removed in Rails 5.1.

Merge pull request #24495 from vipulnsward/rails-changelog-pass

railties/CHANGELOG.mdの修正です。

各entryのグラマー、フォーマットの修正等をまとめて行っています。


Use a single memoized loop to find max mtime in ActiveSupport::FileUpdateChecker#max_mtime

activesupport/lib/active_support/file_update_checker.rbの修正です。

ActiveSupport::FileUpdateChecker#max_mtimeメソッドで、 ファイルのmax timeを取得するのに複数回ループ処理を行っていたのを、値を保持してループが一回で済むようリファクタリングを行っています。


Use Time#compare_without_coercion for super speed

activesupport/lib/active_support/file_update_checker.rbの修正です。

ActiveSupport::FileUpdateChecker#max_mtimeメソッドで、tiimeの比較処理で#compare_without_coercionメソッドを使用するよ修正しています。

-        if time < time_now && time > max_time
+        # This avoids ActiveSupport::CoreExt::Time#time_with_coercion
+        # which is super slow when comparing two Time objects
+        #
+        # Equivalent Ruby:
+        # time < time_now && time > max_time
+        if time.compare_without_coercion(time_now) < 0 && time.compare_without_coercion(max_time) > 0

コメントにある通り、ActiveSupport::CoreExt::Time#time_with_coercionが遅い為、との事です。