|
| 1 | +* Allow signed ID verifiers to be configurable via `Rails.application.message_verifiers` |
| 2 | + |
| 3 | + Prior to this change, the primary way to configure signed ID verifiers was |
| 4 | + to set `signed_id_verifier` on each model class: |
| 5 | + |
| 6 | + ```ruby |
| 7 | + Post.signed_id_verifier = ActiveSupport::MessageVerifier.new(...) |
| 8 | + Comment.signed_id_verifier = ActiveSupport::MessageVerifier.new(...) |
| 9 | + ``` |
| 10 | + |
| 11 | + And if the developer did not set `signed_id_verifier`, a verifier would be |
| 12 | + instantiated with a secret derived from `secret_key_base` and the following |
| 13 | + options: |
| 14 | + |
| 15 | + ```ruby |
| 16 | + { digest: "SHA256", serializer: JSON, url_safe: true } |
| 17 | + ``` |
| 18 | + |
| 19 | + Thus it was cumbersome to rotate configuration for all verifiers. |
| 20 | + |
| 21 | + This change defines a new Rails config: [`config.active_record.use_legacy_signed_id_verifier`][]. |
| 22 | + The default value is `:generate_and_verify`, which preserves the previous |
| 23 | + behavior. However, when set to `:verify`, signed ID verifiers will use |
| 24 | + configuration from `Rails.application.message_verifiers` (specifically, |
| 25 | + `Rails.application.message_verifiers["active_record/signed_id"]`) to |
| 26 | + generate and verify signed IDs, but will also verify signed IDs using the |
| 27 | + older configuration. |
| 28 | + |
| 29 | + To avoid complication, the new behavior only applies when `signed_id_verifier_secret` |
| 30 | + is not set on a model class or any of its ancestors. Additionally, |
| 31 | + `signed_id_verifier_secret` is now deprecated. If you are currently setting |
| 32 | + `signed_id_verifier_secret` on a model class, you can set `signed_id_verifier` |
| 33 | + instead: |
| 34 | + |
| 35 | + ```ruby |
| 36 | + # BEFORE |
| 37 | + Post.signed_id_verifier_secret = "my secret" |
| 38 | +
|
| 39 | + # AFTER |
| 40 | + Post.signed_id_verifier = ActiveSupport::MessageVerifier.new("my secret", digest: "SHA256", serializer: JSON, url_safe: true) |
| 41 | + ``` |
| 42 | + |
| 43 | + To ease migration, `signed_id_verifier` has also been changed to behave as a |
| 44 | + `class_attribute` (i.e. inheritable), but _only when `signed_id_verifier_secret` |
| 45 | + is not set_: |
| 46 | + |
| 47 | + ```ruby |
| 48 | + # BEFORE |
| 49 | + ActiveRecord::Base.signed_id_verifier = ActiveSupport::MessageVerifier.new(...) |
| 50 | + Post.signed_id_verifier == ActiveRecord::Base.signed_id_verifier # => false |
| 51 | +
|
| 52 | + # AFTER |
| 53 | + ActiveRecord::Base.signed_id_verifier = ActiveSupport::MessageVerifier.new(...) |
| 54 | + Post.signed_id_verifier == ActiveRecord::Base.signed_id_verifier # => true |
| 55 | +
|
| 56 | + Post.signed_id_verifier_secret = "my secret" # => deprecation warning |
| 57 | + Post.signed_id_verifier == ActiveRecord::Base.signed_id_verifier # => false |
| 58 | + ``` |
| 59 | + |
| 60 | + Note, however, that it is recommended to eventually migrate from |
| 61 | + model-specific verifiers to a unified configuration managed by |
| 62 | + `Rails.application.message_verifiers`. `ActiveSupport::MessageVerifier#rotate` |
| 63 | + can facilitate that transition. For example: |
| 64 | + |
| 65 | + ```ruby |
| 66 | + # BEFORE |
| 67 | + # Generate and verify signed Post IDs using Post-specific configuration |
| 68 | + Post.signed_id_verifier = ActiveSupport::MessageVerifier.new("post secret", ...) |
| 69 | +
|
| 70 | + # AFTER |
| 71 | + # Generate and verify signed Post IDs using the unified configuration |
| 72 | + Post.signed_id_verifier = Post.signed_id_verifier.dup |
| 73 | + # Fall back to Post-specific configuration when verifying signed IDs |
| 74 | + Post.signed_id_verifier.rotate("post secret", ...) |
| 75 | + ``` |
| 76 | + |
| 77 | + [`config.active_record.use_legacy_signed_id_verifier`]: https://guides.rubyonrails.org/v8.1/configuring.html#config-active-record-use-legacy-signed-id-verifier |
| 78 | + |
| 79 | + *Ali Sepehri*, *Jonathan Hefner* |
| 80 | + |
1 | 81 | * Prepend `extra_flags` in postgres' `structure_load`
|
2 | 82 |
|
3 | 83 | When specifying `structure_load_flags` with a postgres adapter, the flags
|
|
0 commit comments