Module: Contrast::Agent::Protect::Policy::AppliesPathTraversalRule

Extended by:
RuleApplicator
Defined in:
lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb

Overview

This Module is how we apply the Path Traversal rule. It is called from our patches of the targeted methods in which File or IO access occur. It is responsible for deciding if the infilter methods of the rule should be invoked.

Class Method Summary collapse

Methods included from RuleApplicator

apply_rule

Methods included from Components::Interface

included

Class Method Details

.invoke(method, _exception, properties, object, args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb', line 20

def invoke method, _exception, properties, object, args
  return unless args&.any?

  path = args[0]
  return unless path.is_a?(String)
  return if skip_analysis?

  action = properties['action']
  write_marker = write?(action, *args)
  possible_write = write_marker && possible_write?(write_marker)
  path_traversal_rule(path, possible_write, object, method)

  # If the action was copy, we need to handle the write half of it.
  # We handled read in line above.
  return unless action == COPY
  return unless args.length > 1

  dst = args[1]
  return unless dst.is_a?(String)

  path_traversal_rule(dst, true, object, method)
end