Sha256: 2e56c4d2848ef7b34a5af9327dccc2552695e4f920adbc1bdb99bc70336bf07b

Contents?: true

Size: 922 Bytes

Versions: 46

Compression:

Stored size: 922 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Security
      # This cop checks for the use of YAML class methods which have
      # potential security issues leading to remote code execution when
      # loading from an untrusted source.
      #
      # @example
      #   # bad
      #   YAML.load("--- foo")
      #
      #   # good
      #   YAML.safe_load("--- foo")
      #   YAML.dump("foo")
      #
      class YAMLLoad < Cop
        MSG = 'Prefer using `YAML.safe_load` over `YAML.load`.'

        def_node_matcher :yaml_load, <<~PATTERN
          (send (const {nil? cbase} :YAML) :load ...)
        PATTERN

        def on_send(node)
          yaml_load(node) do
            add_offense(node, location: :selector)
          end
        end

        def autocorrect(node)
          ->(corrector) { corrector.replace(node.loc.selector, 'safe_load') }
        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/yaml_load.rb
rubocop-0.88.0 lib/rubocop/cop/security/yaml_load.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/security/yaml_load.rb
rubocop-0.87.1 lib/rubocop/cop/security/yaml_load.rb
rubocop-0.87.0 lib/rubocop/cop/security/yaml_load.rb
rubocop-0.86.0 lib/rubocop/cop/security/yaml_load.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/security/yaml_load.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/security/yaml_load.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/security/yaml_load.rb
rubocop-0.85.1 lib/rubocop/cop/security/yaml_load.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/security/yaml_load.rb
rubocop-0.85.0 lib/rubocop/cop/security/yaml_load.rb
rubocop-0.84.0 lib/rubocop/cop/security/yaml_load.rb
rubocop-0.83.0 lib/rubocop/cop/security/yaml_load.rb
rubocop-0.82.0 lib/rubocop/cop/security/yaml_load.rb
rubocop-0.81.0 lib/rubocop/cop/security/yaml_load.rb
rubocop-0.80.1 lib/rubocop/cop/security/yaml_load.rb
rubocop-0.80.0 lib/rubocop/cop/security/yaml_load.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/security/yaml_load.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/security/yaml_load.rb