なるようになるブログ

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

rails commit log流し読み(2014/07/03)

2014/07/03分のコミットです。

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

actionview/CHANGELOG.md

activesupport/CHANGELOG.md

actionpack/CHANGELOG.md


Fix typo

actionpack/test/dispatch/request_test.rbの修正です。

クラス名にtypoがあったのを修正しています。


Fix SQL injection when querying against ranges and bitstrings

activerecord/lib/active_record/connection_adapters/postgresql/quoting.rbactiverecord/lib/active_record/connection_adapters/postgresql_adapter.rbの修正です。

SQL injection対策を追加しています(CVE-2014-3482、CVE-2014-3483対応)。

PostgreSQLbitstringrange型を使用している時にquote処理が足りて無かったのを追加しています。

コミットログから抜粋。

           case value
            when Range
              if /range$/ =~ sql_type
-              "'#{PostgreSQLColumn.range_to_string(value)}'::#{sql_type}"
+              escaped = quote_string(PostgreSQLColumn.range_to_string(value))
+              "#{escaped}::#{sql_type}"
              else
                super
              end
 @@ -52,8 +53,8 @@ def quote(value, column = nil) #:nodoc:
              when 'xml'   then "xml '#{quote_string(value)}'"
              when /^bit/
                case value
 -              when /^[01]*$/      then "B'#{value}'" # Bit-string notation
 -              when /^[0-9A-F]*$/i then "X'#{value}'" # Hexadecimal notation
 +              when /\A[01]*\Z/      then "B'#{value}'" # Bit-string notation
 +              when /\A[0-9A-F]*\Z/i then "X'#{value}'" # Hexadecimal notation
                end

rangeの方は、PostgreSQLColumn.range_to_stringメソッドを使用するように修正がされ、bitstringの方は正規表現に"\A \Z"を使用するよう修正されてます。

各バージョン(3.2.19, 4.0.7 & 4.1.3)用のパッチが当然出ているので、心当たりある方は、対応をば。


Quote range strings when quoting PG ranges

activerecord/lib/active_record/connection_adapters/postgresql/quoting.rbの修正です。

上のコミットに対して、再度修正が行われています。

-              "#{escaped}::#{sql_type}"
+              "'#{escaped}'::#{sql_type}"

シングルクォートの追加対応が行われています。


Merge pull request #16015 from sgrif/sg-ensure-initialized activerecord/lib/active_record/attribute_set.rbactiverecord/lib/active_record/core.rbの修正です。

PrimaryKeyの初期化処理をAttributeSetの中に移動しています。


automatically include ActiveModel::Validations when include ActiveModel::SecurePassword

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

include ActiveModel::Validationsを追加しています。


DateTime#to_f now preserves fractional seconds.

activesupport/lib/active_support/core_ext/date_time/conversions.rbの修正です。

DateTime#to_fメソッドで小数部が必ず0を返していたのを、値を返すよう修正しています。

# before
 DateTime.civil(1999,12,31,19,0,0.5,Rational(-5,24)).to_f # => 946684800.0

# after
 DateTime.civil(1999,12,31,19,0,0.5,Rational(-5,24)).to_f # => 946684800.5

Only automatically include validations when enabled

再度activemodel/lib/active_model/secure_password.rbの修正です。

validationsの設定がされている時のみ、include ActiveModel::Validationsするよう修正しています。


Fix escape_once double-escaping hex-encoded entities

activesupport/lib/active_support/core_ext/string/output_safety.rbの修正です。

HTML_ESCAPE_ONCE_REGEXPにパターンを追加しています。

-    HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
+    HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+)|(#[xX][\dA-Fa-f]{1,4}));)/

16進文字のエスケープを追加しています。

assert_equal " &#X27; &#x27; &#x03BB; &#X03bb; &quot; &#39; &lt; &gt; ", html_escape_once(" &#X27; &#x27; &#x03BB; &#X03bb; \" ' < > ")

html_escape_once、使った事無いんですよね。どういうユースケースで使用するんだろう。


The hex escape sequence can be of any length

もう一回activesupport/lib/active_support/core_ext/string/output_safety.rbの修正です。

-    HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+)|(#[xX][\dA-Fa-f]{1,4}));)/
+    HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+)|(#[xX][\dA-Fa-f]+));)/

4文字とは限らないからですね。


Add CHANGELOG for c803b90

上記html_escape_onceの対応について、CHANGELOGに追記しています。


Change the JSON renderer to enforce the 'JS' Content Type

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

JSONPでのrequestの場合、content typeにJSONが設定されていた場合でも、JSを設定するよう修正しています。

       if options[:callback].present?
-        self.content_type ||= Mime::JS
+        if self.content_type.nil? || self.content_type == Mime::JSON
+          self.content_type = Mime::JS
+        end

JSONPの場合、content typeにapplication/javascriptを設定しなくてはならないんですよね。Chromeとかだと、application/jsonが設定されてた場合、エラーになります。ついこの間、これでエラーに…。


Fix typo in comment https://github.com/rails/rails/commit/3c917dd1ec84299460657237f2f4771086ba1106

activerecord/lib/active_record/relation/calculations.rbのdocの修正です。

typoの修正。


Use the type object for type casting HStore columns

activerecord/lib/active_record/connection_adapters/postgresql/cast.rbactiverecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rbの修正です。

HStoreカラムの変換処理をCastからHStoreクラスに移動しています。