Sha256: 6e9429618740b89b2945408bccfbff49c54a185d6e44041b559f131c40117492

Contents?: true

Size: 988 Bytes

Versions: 4

Compression:

Stored size: 988 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Security
      # This cop checks for the use of Marshal class methods which have
      # potential security issues leading to remote code execution when
      # loading from an untrusted source.
      #
      # @example
      #   # bad
      #   Marshal.load("{}")
      #   Marshal.restore("{}")
      #
      #   # good
      #   Marshal.dump("{}")
      #
      #   # okish - deep copy hack
      #   Marshal.load(Marshal.dump({}))
      #
      class MarshalLoad < Base
        MSG = 'Avoid using `Marshal.%<method>s`.'

        def_node_matcher :marshal_load, <<~PATTERN
          (send (const {nil? cbase} :Marshal) ${:load :restore}
          !(send (const {nil? cbase} :Marshal) :dump ...))
        PATTERN

        def on_send(node)
          marshal_load(node) do |method|
            add_offense(node.loc.selector, message: format(MSG, method: method))
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.90.0/lib/rubocop/cop/security/marshal_load.rb
rubocop-0.90.0 lib/rubocop/cop/security/marshal_load.rb
rubocop-0.89.1 lib/rubocop/cop/security/marshal_load.rb
rubocop-0.89.0 lib/rubocop/cop/security/marshal_load.rb