Sha256: c7f137b0365289958a4d0c3f7e6d3639df955b45a80c4adc38287da8795ce801

Contents?: true

Size: 1.02 KB

Versions: 46

Compression:

Stored size: 1.02 KB

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 < Cop
        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,
                        location: :selector,
                        message: format(MSG, method: method))
          end
        end
      end
    end
  end
end

Version data entries

46 entries across 35 versions & 5 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/security/marshal_load.rb
rubocop-0.88.0 lib/rubocop/cop/security/marshal_load.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/security/marshal_load.rb
rubocop-0.87.1 lib/rubocop/cop/security/marshal_load.rb
rubocop-0.87.0 lib/rubocop/cop/security/marshal_load.rb
rubocop-0.86.0 lib/rubocop/cop/security/marshal_load.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/security/marshal_load.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/security/marshal_load.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/security/marshal_load.rb
rubocop-0.85.1 lib/rubocop/cop/security/marshal_load.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/security/marshal_load.rb
rubocop-0.85.0 lib/rubocop/cop/security/marshal_load.rb
rubocop-0.84.0 lib/rubocop/cop/security/marshal_load.rb
rubocop-0.83.0 lib/rubocop/cop/security/marshal_load.rb
rubocop-0.82.0 lib/rubocop/cop/security/marshal_load.rb
rubocop-0.81.0 lib/rubocop/cop/security/marshal_load.rb
rubocop-0.80.1 lib/rubocop/cop/security/marshal_load.rb
rubocop-0.80.0 lib/rubocop/cop/security/marshal_load.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/security/marshal_load.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/security/marshal_load.rb