なるようになるブログ

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

rails commit log流し読み(2015/06/17)

2015/06/17分のコミットです。

CHANGELOGにのったコミットは以下の通りです。

actionpack/CHANGELOG.md


raise ActiveModel::MissingAttributeError when trying to access a relationship without the foreign key attribute

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

foreign key attributeを取得してない状態で、associationを取得しようとした際に、ActiveModel::MissingAttributeErrorがraiseされるよう修正しています。

class User < ActiveRecord::Base
end

class Post < ActiveRecord::Base
  belongs_to :user
end

# before
Post.select(:id).first.user # => nil

# after
Post.select(:id).first.user # => ActiveModel::MissingAttributeError: missing attribute: user_id

4.1まではMissingAttributeErrorがraiseされるようになっていたのが、4.2.0で変わってしまっており、再度元の挙動に戻した形のようです。


Escape HTML entities in JSON keys

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

JSONエンコーディング処理で、JSONのkeyにHTMLエンティティが含まれていた場合に、正しくエスケープ処理が行われるよう修正しています。 CVE-2015-3226の対応です。

ActiveSupport::JSON.encode("<>" => "<>")
# => {\"\\u003c\\u003e\":\"\\u003c\\u003e\"

元々はエスケープ処理が行われていなかった為、ユーザが送信したJSON stringをそのままHTMLページに表示する、という場合にXSSが発生してしまう可能性がありました。

具体的には以下のようなケースとの事です。

<%= javascript_tag "var data = #{user_supplied_data.to_json};" %>

CVE-2015-3226 についての詳細は、oss-security - [CVE-2015-3226] XSS Vulnerability in ActiveSupport::JSON.encode 参照。


enforce a depth limit on XML documents

ActiveSupportXMLパース処理の修正です。

XML documentsを読み込む階層を、100階層までに制限しています。

今までは無制限に読み込むようになっていたのですが、それだと巨大なXMLを送信された場合にXMLの読み込みでstack overflowがおきてしまい、DoS attackになる可能性があった為、制限したとの事です。

CVE-2015-3227についての詳細は、oss-security - [CVE-2015-3227] Possible Denial of Service attack in Active Support参照。


Fix the comment about attr_reader of headers [ci skip]

actionpack/lib/action_dispatch/http/response.rbのdocの修正です。

Response#headerについてのdocを、Get and set headers から Get headersに修正しています。


Fix descriptions of databases.rake [ci skip]

activerecord/lib/active_record/railties/databases.rakeのdocの修正です。

各タスクのdescriptionのグラマーの修正を行っています。


Catch InvalidURIError on bad paths on redirect.

actionpack/lib/action_dispatch/routing/redirection.rbの修正です。

redirectメソッドの引数に不正なpathを指定した場合に、500エラーになっていたのを、400エラー(Bad Request)を返すよう修正しています。

pathが不正、という事がより判りやすくなるように、との理由で修正したようです。

ただ、redirect('posts/ındex')のように、本来indexと書くべき所をındexにタイポしてしまった、というようなケースでは、500の方が正しいのでは、という話も出てきているので、後でまた少し変わるかもしれません。


Merge pull request #20584 from arthurnn/fix_url


Bump AMS to 0.10.0.rc2

railties/lib/rails/generators/rails/app/templates/Gemfileの修正です。

rails apiを作成した際のデフォルトのGemfileで読み込むactive_model_serializersのバージョンを0.10.0.rc1 -> 0.10.0.rc2に修正しています。


Update bundler to v1.10.4

Gemfile.lockの修正です。

bunlderのバージョンを1.10.4にあげています。


Use single quote in Railties generators Gemfile [ci skip]

railties/lib/rails/generators/rails/app/templates/Gemfileの修正です。

rails apiを作成した際のデフォルトのGemfileで、web-consoleのgithubのブランチ名をダブルクォートで囲んでいたのを、他のgemfile同様シングルクォートで囲むよう修正しています。