Sha256: 6427126dc064bd3fd295ba1738c24cc5be1702db710ef0b672f66a606088d081
Contents?: true
Size: 1.14 KB
Versions: 10
Compression:
Stored size: 1.14 KB
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. # # @safety # The behaviour of the code might change depending on what was # in the YAML payload, since `YAML.safe_load` is more restrictive. # # @example # # bad # YAML.load("--- foo") # # # good # YAML.safe_load("--- foo") # YAML.dump("foo") # class YAMLLoad < Base extend AutoCorrector MSG = 'Prefer using `YAML.safe_load` over `YAML.load`.' RESTRICT_ON_SEND = %i[load].freeze # @!method yaml_load(node) def_node_matcher :yaml_load, <<~PATTERN (send (const {nil? cbase} :YAML) :load ...) PATTERN def on_send(node) yaml_load(node) do add_offense(node.loc.selector) do |corrector| corrector.replace(node.loc.selector, 'safe_load') end end end end end end end
Version data entries
10 entries across 10 versions & 2 rubygems