☠️

🚨RDoc脆弱性を解消!Railsアプリのセキュリティ向上ガイド

2024/06/06に公開

はじめに

RDoc脆弱性を解消!Railsアプリのセキュリティ向上ガイド

こんにちは、Takeです。都内の自社開発企業でエンジニアとして働いています。

GitHubから、Publicの状態で進めているRails TutorialのSample Appに関する高優先度のアラートが届きました。

https://railstutorial.jp/

アラート内容:

アラート内容は以下のようなものでした。

Severity:High🚨

# Title:
RDoc RCE vulnerability with .rdoc_options
# body
An issue was discovered in RDoc 6.3.3 through 6.6.2, as distributed in Ruby 3.x through 3.3.0.

When parsing .rdoc_options (used for configuration in RDoc) as a YAML file, object injection and resultant remote code execution are possible because there are no restrictions on the classes that can be restored.

When loading the documentation cache, object injection and resultant remote code execution are also possible if there were a crafted cache.

We recommend to update the RDoc gem to version 6.6.3.1 or later. In order to ensure compatibility with bundled version in older Ruby series, you may update as follows instead:

For Ruby 3.0 users: Update to rdoc 6.3.4.1
For Ruby 3.1 users: Update to rdoc 6.4.1.1
For Ruby 3.2 users: Update to rdoc 6.5.1.1
You can use gem update rdoc to update it. If you are using bundler, please add gem "rdoc", ">= 6.6.3.1" to your Gemfile.

Note: 6.3.4, 6.4.1, 6.5.1 and 6.6.3 have a incorrect fix. We recommend to upgrade 6.3.4.1, 6.4.1.1, 6.5.1.1 and 6.6.3.1 instead of them.
  • RDocバージョン6.3.3から6.6.2には、リモートコード実行(RCE)脆弱性があります。
  • .rdoc_optionsのパース時にオブジェクトインジェクションが可能で、悪意のあるコードが実行される可能性があります。

対策:

https://www.ruby-lang.org/en/news/2024/03/21/rce-rdoc-cve-2024-27281/

上記のドキュメントを参照してRDocをバージョン6.6.3.1以上にアップグレードしました。以下のRubyシリーズを使用している場合、以下のバージョンにアップグレードします。

  • Ruby 3.0: 6.3.4.1
  • Ruby 3.1: 6.4.1.1
  • Ruby 3.2: 6.5.1.1
 $ ruby -v
ruby 3.2.3 (2024-01-18 revision 52bb2ac0a6) [x86_64-linux]

私の場合、現在V3.2系を使用しているのでRDocをV6.5.1.1にアップデートする必要があります。

Gemfileの更新:

gem "rdoc", ">= 6.5.1.1"

Bundlerを使って更新:

bundle update rdoc

出力

$ bundle update rdoc
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Fetching psych 5.1.2 (was 5.1.1.1)
Installing psych 5.1.2 (was 5.1.1.1) with native extensions
Fetching rdoc 6.7.0 (was 6.6.0)
Installing rdoc 6.7.0 (was 6.6.0)
Bundle updated!
1 installed gem you directly depend on is looking for funding.
  Run `bundle fund` for details

変更をPull Requestを実行後、mainブランチにマージ完了しました。✅
すると、以下のように自動的でDependabot alertsが自動的にClosedされました。🎉

参考

https://www.ruby-lang.org/en/news/2024/03/21/rce-rdoc-cve-2024-27281/

https://railstutorial.jp/

まとめ

今回のアラートは、RDocのバージョン6.3.3から6.6.2に存在するリモートコード実行(RCE)脆弱性に関するものでした。この脆弱性を修正するためにRDocをバージョン6.6.3.1以上にアップグレードし、Gemfileを更新してbundle update rdocコマンドを実行しました。

Publicステータスは確かに多くのリスクに晒される脅威がありますが、このような脆弱性もあると知ることもできたので今後はこのようなアラートが来ないように励みたいと思います。📚

最後に

ここまで読んでいただきありがとうございました!
今回の記事が良かったと思ったらぜひ「いいね」を押していただけると嬉しいです 🎉

noteでも記事を執筆していますので、ぜひチェックしてみてください。
https://note.com/take_lifelog/n/n58df7ce7af6f

他にもこのようなことについて記載しているのでお読みいただければ幸いです。

https://zenn.dev/take_tech/articles/275e5f4242973d

https://zenn.dev/take_tech/articles/374817f256ec9d

最後までお読みいただき、誠にありがとうございました!

Discussion