Skip to content
  • Jonathan Hefner's avatar
    6f31335d
    Hard code serializer for AS::EncryptedFile · 6f31335d
    Jonathan Hefner authored
    Follow-up to #42846.
    
    Prior to this commit, `ActiveSupport::EncryptedFile` used the
    `ActiveSupport::MessageEncryptor` default serializer.  #42846 changed
    the default serializer to `JSON` when using `config.load_defaults 7.1`.
    Thus, encrypted files that were written with the previous default
    serializer (`Marshal`) could not be read by `Rails.application.encrypted`.
    That included files which were written with `bin/rails encrypted:edit`
    even when using the new default, because the `bin/rails encrypted:edit`
    command does not run the initializer that applies the configuration to
    `MessageEncryptor`:
    
      ```console
      $ bin/rails r 'puts ActiveSupport::MessageEncryptor.default_message_encryptor_serializer'
      json
    
      $ bin/rails encrypted:edit config/my_encrypted.yml.enc
      ...
    
      $ bin/rails encrypted:show config/my_encrypted.yml.enc
      foo: bar
    
      $ bin/rails r 'Rails.application.encrypted("config/my_encrypted.yml.enc").read'
      rails/activesupport/lib/active_support/message_encryptor.rb:241:in `rescue in _decrypt': ActiveSupport::MessageEncryptor::InvalidMessage (ActiveSupport::MessageEncryptor::InvalidMessage)
      ...
      ruby-3.2.0/lib/ruby/3.2.0/json/common.rb:216:in `parse': unexpected token at "foo: bar (JSON::ParserError)
      ```
    
    This commit hard codes the serializer for `EncryptedFile` to `Marshal`.
    6f31335d
    Hard code serializer for AS::EncryptedFile
    Jonathan Hefner authored
    Follow-up to #42846.
    
    Prior to this commit, `ActiveSupport::EncryptedFile` used the
    `ActiveSupport::MessageEncryptor` default serializer.  #42846 changed
    the default serializer to `JSON` when using `config.load_defaults 7.1`.
    Thus, encrypted files that were written with the previous default
    serializer (`Marshal`) could not be read by `Rails.application.encrypted`.
    That included files which were written with `bin/rails encrypted:edit`
    even when using the new default, because the `bin/rails encrypted:edit`
    command does not run the initializer that applies the configuration to
    `MessageEncryptor`:
    
      ```console
      $ bin/rails r 'puts ActiveSupport::MessageEncryptor.default_message_encryptor_serializer'
      json
    
      $ bin/rails encrypted:edit config/my_encrypted.yml.enc
      ...
    
      $ bin/rails encrypted:show config/my_encrypted.yml.enc
      foo: bar
    
      $ bin/rails r 'Rails.application.encrypted("config/my_encrypted.yml.enc").read'
      rails/activesupport/lib/active_support/message_encryptor.rb:241:in `rescue in _decrypt': ActiveSupport::MessageEncryptor::InvalidMessage (ActiveSupport::MessageEncryptor::InvalidMessage)
      ...
      ruby-3.2.0/lib/ruby/3.2.0/json/common.rb:216:in `parse': unexpected token at "foo: bar (JSON::ParserError)
      ```
    
    This commit hard codes the serializer for `EncryptedFile` to `Marshal`.
Loading