LoginSignup
3
0

Rails 7.0.7.2, 6.1.7.6 のアップデートの内容を検証してみる

Last updated at Posted at 2023-08-23

Rails 7.0.7.1, 7.0.7.2, 6.1.7.5, 6.1.7.6 のアップデートがあった

https://rubyonrails.org/2023/8/22/Rails-Versions-7-0-7-1-6-1-7-5-have-been-released
https://rubyonrails.org/2023/8/22/Rails-Versions-7-0-7-2-6-1-7-6-have-been-released

Railsのアップデート(7.0.7.1, 7.0.7.2, 6.1.7.5, 6.1.7.6)が配信された。脆弱性 CVE-2023-38037 のパッチであるという。

Impact
ActiveSupport::EncryptedFile writes contents that will be encrypted to a temporary file. The temporary file’s permissions are defaulted to the user’s current umask settings, meaning that it’s possible for other users on the same system to read the contents of the temporary file.

Attackers that have access to the file system could possibly read the contents of this temporary file while a user is editing it.

  • ActiveSupport::EncryptedFile は、暗号化したい内容を一時ファイルに書き込んでいる。
  • umask の設定によっては同じシステムのユーザがその一時ファイルを覗き見れる状態にあった。
    • ファイルシステムに侵入した攻撃者は、一時ファイルを覗き見できていた。

ファイルシステムに侵入されてるかつ秘密ファイルを編集中に可能な攻撃ってことでかなり特殊なケースっぽい?

(7.0.7.2, 6.1.7.6 は 7.0.7.1, 6.1.7.5 の対応時にファイルパーミッションを変えていて、それをそのまま配信してしまったので元に戻したっていう内容なのでコードの変更とかはない)

検証してみる

7.0.7.0, 6.1.7.4 のrails アプリを用意して秘密ファイルを編集中にする

# umask は 0022
$ umask
0022
# 秘密ファイルを開いた状態にしておく
$ EDITOR=vim bin/rails credentials:edit

秘密ファイルは開いたままで、別の端末から同じシステムの別のユーザで覗き見てみる

# 別ユーザ追加
$ groupadd -g 1000 user
$ useradd -m -s /bin/bash -u 1000 -g 1000 testuser

/tmp をみてみると

$ su testuser

# /tmp に編集中の credentials.yml の一時ファイルがある
# 7.0.7.0, 6.1.7.4 だとread権限がある
$ ls -l /tmp
...
-rw-r--r-- 1 root root  305 Aug 23 03:10 **.credentials.yml
...
# ファイルの内容が見れちゃう
$ cat /tmp/**.credentials.yml
$ su testuser

# /tmp に編集中の credentials.yml の一時ファイルがある
# 7.0.7.2, 6.1.7.6 だとread権限がない
$ ls -l /tmp
...
-rw------- 1 root root   305 Aug 23 02:52 **-credentials.yml
...

# ファイルの内容は見れない
$ cat /tmp/**-credentials.yml
**-credentials.yml: Permission denied

rails の diff みてみた

rails の diff をみてみたら、今まではファイルへの出力を Pathname#binwrite していたのが、 Tempfile を使うようになっていた。 Tempfile の説明を読んでいると、

テンポラリファイルのモードは 0600 です。

なので他のユーザからは見れなくなったみたい。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0