Sha256: 511dd4e5d4c5a2416505bc1cf87b0eb100c58b1d115353c7d4d961dfd218e2fb

Contents?: true

Size: 1.52 KB

Versions: 12

Compression:

Stored size: 1.52 KB

Contents

require_relative '../context'
# We use DebugInspector to execute eval() in the callers frame.

require 'binding_of_caller'
module Immunio
  module KernelEvalHook
    extend ActiveSupport::Concern

    def self.extended(base)
      Immunio::Utils.alias_method_chain base.singleton_class, :eval, :immunio
    end

    def self.included(base)
      Immunio::Utils.alias_method_chain base, :eval, :immunio
    end

    protected
    def eval_with_immunio(*args)
      Immunio.logger.debug {"Eval_with_immunio with args: #{args}"}
      Request.time "plugin", "#{Module.nesting[0]}::#{__method__}" do
        strict_context, loose_context, stack = Immunio::Context.context()
        Immunio.run_hook! "eval", "eval",
                          parameters: args,
                          context_key: loose_context,
                          stack: stack
        Request.pause "plugin", "#{Module.nesting[0]}::#{__method__}" do
          if args[1].nil?
            # eval call did not include a binding, so we eval it in the caller's binding
            # NOTE: the 7 here is the number of frames above us the caller was. Changing
            # the call stack will break this...
            args[1] = binding.of_caller(7)
          end
          eval_without_immunio(*args)
        end
      end
    end
  end
end

Immunio::Plugin.load 'Kernel (Eval)',
                     feature: 'eval',
                     hooks: %w( eval ) do |plugin|

  Kernel.send :include, Immunio::KernelEvalHook
  Kernel.extend Immunio::KernelEvalHook

  plugin.loaded! RUBY_VERSION
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
immunio-2.0.4 lib/immunio/plugins/eval.rb
immunio-2.0.3 lib/immunio/plugins/eval.rb
immunio-2.0.2 lib/immunio/plugins/eval.rb
immunio-1.2.1 lib/immunio/plugins/eval.rb
immunio-1.1.19 lib/immunio/plugins/eval.rb
immunio-1.1.18 lib/immunio/plugins/eval.rb
immunio-1.1.16 lib/immunio/plugins/eval.rb
immunio-1.1.15 lib/immunio/plugins/eval.rb
immunio-1.1.13 lib/immunio/plugins/eval.rb
immunio-1.1.11 lib/immunio/plugins/eval.rb
immunio-1.1.10 lib/immunio/plugins/eval.rb
immunio-1.1.7 lib/immunio/plugins/eval.rb