Skip to content
  • Jonathan Hefner's avatar
    9fbfd810
    Unify Message{Encryptor,Verifier} serializer config · 9fbfd810
    Jonathan Hefner authored
    In #42843 and #42846, several config settings were added to control the
    default serializer for `MessageEncryptor` and `MessageVerifier`, and to
    provide a migration path from a default `Marshal` serializer to a
    default `JSON` serializer:
    
    * `config.active_support.default_message_encryptor_serializer`
      * Supports `:marshal`, `:hybrid`, or `:json`.
    * `config.active_support.default_message_verifier_serializer`
      * Supports `:marshal`, `:hybrid`, or `:json`.
    * `config.active_support.fallback_to_marshal_deserialization`
      * Affects `:hybrid` for both `MessageEncryptor` and `MessageVerifier`.
    * `config.active_support.use_marshal_serialization`
      * Affects `:hybrid` for both `MessageEncryptor` and `MessageVerifier`.
    
    This commit unifies those config settings into a single setting,
    `config.active_support.message_serializer`, which supports `:marshal`,
    `:json_allow_marshal`, and `:json` values.  So, for example,
    
      ```ruby
      config.active_support.default_message_encryptor_serializer = :hybrid
      config.active_support.default_message_verifier_serializer = :hybrid
      config.active_support.fallback_to_marshal_deserialization = true
      config.active_support.use_marshal_serialization = false
      ```
    
    becomes
    
      ```ruby
      config.active_support.message_serializer = :json_allow_marshal
      ```
    
    and
    
      ```ruby
      config.active_support.default_message_encryptor_serializer = :hybrid
      config.active_support.default_message_verifier_serializer = :hybrid
      config.active_support.fallback_to_marshal_deserialization = false
      config.active_support.use_marshal_serialization = false
      ```
    
    becomes
    
      ```ruby
      config.active_support.message_serializer = :json
      ```
    
    This commit also replaces `ActiveSupport::JsonWithMarshalFallback` with
    `ActiveSupport::Messages::SerializerWithFallback`, which implements a
    generic mechanism for serializer fallback.  The `:marshal` serializer
    uses this mechanism too, so
    
      ```ruby
      config.active_support.default_message_encryptor_serializer = :hybrid
      config.active_support.default_message_verifier_serializer = :hybrid
      config.active_support.fallback_to_marshal_deserialization = false
      config.active_support.use_marshal_serialization = true
      ```
    
    becomes
    
      ```ruby
      config.active_support.message_serializer = :marshal
      ```
    
    Additionally, the logging behavior of `JsonWithMarshalFallback` has been
    replaced with notifications which include the names of the intended and
    actual serializers, as well as the serialized and deserialized message
    data.  This provides a more targeted means of tracking serializer
    fallback events.  It also allows the user to "silence" such events, if
    desired, without an additional config setting.
    
    All of these changes make it easier to add migration paths for new
    serializers such as `ActiveSupport::MessagePack`.
    9fbfd810
    Unify Message{Encryptor,Verifier} serializer config
    Jonathan Hefner authored
    In #42843 and #42846, several config settings were added to control the
    default serializer for `MessageEncryptor` and `MessageVerifier`, and to
    provide a migration path from a default `Marshal` serializer to a
    default `JSON` serializer:
    
    * `config.active_support.default_message_encryptor_serializer`
      * Supports `:marshal`, `:hybrid`, or `:json`.
    * `config.active_support.default_message_verifier_serializer`
      * Supports `:marshal`, `:hybrid`, or `:json`.
    * `config.active_support.fallback_to_marshal_deserialization`
      * Affects `:hybrid` for both `MessageEncryptor` and `MessageVerifier`.
    * `config.active_support.use_marshal_serialization`
      * Affects `:hybrid` for both `MessageEncryptor` and `MessageVerifier`.
    
    This commit unifies those config settings into a single setting,
    `config.active_support.message_serializer`, which supports `:marshal`,
    `:json_allow_marshal`, and `:json` values.  So, for example,
    
      ```ruby
      config.active_support.default_message_encryptor_serializer = :hybrid
      config.active_support.default_message_verifier_serializer = :hybrid
      config.active_support.fallback_to_marshal_deserialization = true
      config.active_support.use_marshal_serialization = false
      ```
    
    becomes
    
      ```ruby
      config.active_support.message_serializer = :json_allow_marshal
      ```
    
    and
    
      ```ruby
      config.active_support.default_message_encryptor_serializer = :hybrid
      config.active_support.default_message_verifier_serializer = :hybrid
      config.active_support.fallback_to_marshal_deserialization = false
      config.active_support.use_marshal_serialization = false
      ```
    
    becomes
    
      ```ruby
      config.active_support.message_serializer = :json
      ```
    
    This commit also replaces `ActiveSupport::JsonWithMarshalFallback` with
    `ActiveSupport::Messages::SerializerWithFallback`, which implements a
    generic mechanism for serializer fallback.  The `:marshal` serializer
    uses this mechanism too, so
    
      ```ruby
      config.active_support.default_message_encryptor_serializer = :hybrid
      config.active_support.default_message_verifier_serializer = :hybrid
      config.active_support.fallback_to_marshal_deserialization = false
      config.active_support.use_marshal_serialization = true
      ```
    
    becomes
    
      ```ruby
      config.active_support.message_serializer = :marshal
      ```
    
    Additionally, the logging behavior of `JsonWithMarshalFallback` has been
    replaced with notifications which include the names of the intended and
    actual serializers, as well as the serialized and deserialized message
    data.  This provides a more targeted means of tracking serializer
    fallback events.  It also allows the user to "silence" such events, if
    desired, without an additional config setting.
    
    All of these changes make it easier to add migration paths for new
    serializers such as `ActiveSupport::MessagePack`.
Loading