Skip to content

key_generator_hash_digest_classをSHA1に設定#9411

Merged
komagata merged 1 commit intomainfrom
fix/active-storage-urls-sha1
Dec 19, 2025
Merged

key_generator_hash_digest_classをSHA1に設定#9411
komagata merged 1 commit intomainfrom
fix/active-storage-urls-sha1

Conversation

@komagata
Copy link
Copy Markdown
Member

@komagata komagata commented Dec 19, 2025

Summary

原因

古いActive Storage URLは、SHA1ベースの鍵で署名されていました。
Rails 7.0以降のデフォルトはSHA256のため、古いURLの署名検証が失敗していました。

修正内容

config.active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA1

関連PR

Test plan

  • CIが通ることを確認

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • 互換性向上
    • SHA1ベースのキーを使用して署名されたレガシーなActive Storage URLのサポートを追加しました。

✏️ Tip: You can customize this high-level summary in your review settings.

古いActive Storage URLはSHA1ベースの鍵で署名されていたため、
SHA1を使用するように設定を追加。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 19, 2025

ウォークスルー

設定ファイル config/application.rb に、レガシーActive Storage URLがサポートするようSHA1ベースの鍵生成を有効にする設定オプション config.active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA1 が追加されました。

変更内容

コホート / ファイル(s) 変更内容
設定オプション追加
config/application.rb
config.active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA1 を追加し、SHA1ベースの鍵を使用したレガシーActive Storage URLのサポートを有効化

推定コードレビュー所要時間

🎯 1 (Trivial) | ⏱️ ~3 分

  • 設定オプションの正確性の確認
  • 設定場所の妥当性の確認(Application クラス内の適切な位置か)

推奨レビュアー

  • okuramasafumi

🐰 設定一行、SHA1の鍵で
レガシーURLも蘇る
互換性の橋を渡る

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed Pull requestのタイトルは変更内容の主要なポイント(key_generator_hash_digest_classをSHA1に設定)を明確に要約しており、関連するチームメンバーが履歴をスキャンする際に理解できる具体的な内容となっています。
Description check ✅ Passed Pull request説明は概要、原因、修正内容、関連PR、テストプランを含む構成になっていますが、リポジトリのテンプレート(Issue番号、変更確認方法、Screenshot等)に完全には従っていません。ただし、実質的な情報は十分に含まれています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/active-storage-urls-sha1

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
config/application.rb (1)

41-43: キーローテーション導入を検討し、長期的なセキュリティ戦略を確立してください。

この設定はRails 7.0以降でのキー生成デフォルト変更(SHA1→SHA256)に対する必要な後方互換性対応で、Rails upgrading guideで推奨されている標準的なパターンです。現在の実装は即座の互換性確保としては適切ですが、推奨されるアプローチはキーローテーション(複数の鍵を同時にサポート)です。

Rails公式ドキュメントに基づき、以下を検討してください:

  1. 現在の設定の制限: 全環境でSHA1に固定されており、将来のSHA256への移行が困難です
  2. 推奨されるアプローチ: action_dispatch.cookies_rotationsでキーローテーションを設定し、SHA1で署名された古いメッセージを読み取りながら、新しいメッセージはSHA256で生成できます
  3. 段階的な移行: ローテーション機能を導入することで、SHA256への移行を段階的に進められます

時間的な余裕がある場合、キーローテーション機能の導入を推奨します。

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6d2159e and e39e1cf.

📒 Files selected for processing (1)
  • config/application.rb (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
config/**

📄 CodeRabbit inference engine (AGENTS.md)

Configuration files in config/ should include environment settings, routes, and lints (.rubocop.yml, config/slim_lint.yml)

Files:

  • config/application.rb
**/*.rb

📄 CodeRabbit inference engine (AGENTS.md)

Ruby code should use 2-space indentation, snake_case for method names, and CamelCase for class names, enforced by RuboCop (.rubocop.yml)

Files:

  • config/application.rb

⚙️ CodeRabbit configuration file

**/*.rb: # refactoring

  • まずFat Controllerを避け、次にFat Modelを避ける。
  • Serviceクラスの乱用を避ける。
  • controller concernを作ろうとしたらPORO(Plain Old Ruby Object)やActiveRecordモデルでの実装で代替できないか検討する。

Rails Patterns

  • ViewHelperにメソッドを実装する時にはまずDecoratorパターンを使うことを検討する。(active_decorator gemを導入しているのでそれを使う)
  • 複雑なActiveRecordクエリがあり、再利用できそうな場合はQueryObjectパターンを検討する。(rails-patterns gemを導入しているのでそれのQuery機能を使う)
  • Viewにpartialを作る場合はViewComponentを使うことを検討する。
  • 複数のActiveRecordモデルを操作する1つの責務がある時や外部APIとやりとりする処理がある場合にはInteractorオブジェクトパターンを検討する。(interactor gemを導入しているのでそれを使う)
  • 複数のInteractorを実行するような処理がある場合Organizerオブジェクトパターンを検討する。(interactor gemを導入しており、その中にOrganizerの機能があるので使う)

Files:

  • config/application.rb
🧠 Learnings (3)
📓 Common learnings
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/notifiers/discord_notifier.rb:19-23
Timestamp: 2025-09-12T21:17:26.029Z
Learning: Rails アップグレードPRにおいて、config_for(:secrets) を使った webhook URL 設定の shared セクション未参照問題は、設定システム全体の変更として別PRで対応すべきである。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/notifiers/discord_notifier.rb:131-135
Timestamp: 2025-09-12T21:18:00.834Z
Learning: Rails アップグレードPRにおいて、product_review_not_completed メソッドの webhook URL 設定の shared フォールバック追加も、設定システム全体の変更として別PRで対応すべきである。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: config/initializers/sorcery.rb:0-0
Timestamp: 2025-09-11T16:02:24.782Z
Learning: Rails アップグレードPRにおいて、JWT設定の改善では複数のソース(secrets, credentials, ENV)を優先順位付きで検索し、本番環境では未設定時に起動を停止させる実装が推奨される。開発・テスト環境でのみsecret_key_baseフォールバックを許可する構成が安全である。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/models/graduation_notifier.rb:23-28
Timestamp: 2025-09-12T21:16:47.639Z
Learning: Rails upgrade PRにおいて、configuration systemの変更やwebhook設定の改善提案も、アップグレードに直接関連しない場合は別PRで対応すべきである。PRのスコープ維持が重要。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/notifiers/discord_notifier.rb:52-56
Timestamp: 2025-09-12T21:17:45.295Z
Learning: Rails upgrade PRにおいて、configuration systemの改善提案(shared configuration fallback等)も、アップグレードに直接関連しない場合は別PRで対応すべきである。PRのスコープ維持が重要。
📚 Learning: 2025-09-11T16:02:24.782Z
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: config/initializers/sorcery.rb:0-0
Timestamp: 2025-09-11T16:02:24.782Z
Learning: Rails アップグレードPRにおいて、JWT設定の改善では複数のソース(secrets, credentials, ENV)を優先順位付きで検索し、本番環境では未設定時に起動を停止させる実装が推奨される。開発・テスト環境でのみsecret_key_baseフォールバックを許可する構成が安全である。

Applied to files:

  • config/application.rb
📚 Learning: 2025-09-12T21:17:26.029Z
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/notifiers/discord_notifier.rb:19-23
Timestamp: 2025-09-12T21:17:26.029Z
Learning: Rails アップグレードPRにおいて、config_for(:secrets) を使った webhook URL 設定の shared セクション未参照問題は、設定システム全体の変更として別PRで対応すべきである。

Applied to files:

  • config/application.rb
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test

@komagata komagata merged commit 391570b into main Dec 19, 2025
6 checks passed
@komagata komagata deleted the fix/active-storage-urls-sha1 branch December 19, 2025 18:05
@github-actions github-actions Bot mentioned this pull request Dec 19, 2025
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant