Sha256: d494d1745a159f343f4bc91ad9d4e66b673caa73beb034accdd26120866b7d3f

Contents?: true

Size: 1.46 KB

Versions: 25

Compression:

Stored size: 1.46 KB

Contents

module Immunio
  module CookieHooks
    extend ActiveSupport::Concern

    included do
      # TODO: should anything be checked to make sure @parent_jar exists
      if method_defined? :[]  # Not sure when this wouldn't exist.
        # The following won't work because of the names:
        # alias_method_chain :[], :immunio if method_defined? :[]
        alias_method :lookup_without_immunio, :[]
        alias_method :[], :lookup_with_immunio
      end

    end

    def lookup_with_immunio(name)
      Request.time "plugin", "#{Module.nesting[0]}::#{__method__}" do
        raw_cookie_value = @parent_jar[name]
        cookie_value = Request.pause "plugin", "#{Module.nesting[0]}::#{__method__}" do
          lookup_without_immunio(name)
        end
        if !raw_cookie_value.nil? and cookie_value.nil?
          Immunio.run_hook! "action_dispatch", "bad_cookie", key: name,
                                                             value: raw_cookie_value
        end
        cookie_value
      end
    end
  end
end

class ActionDispatch::Cookies
  if defined? SignedCookieJar
    SignedCookieJar.send :include, Immunio::CookieHooks
  end
  if defined? UpgradeLegacySignedCookieJar
    UpgradeLegacySignedCookieJar.send :include, Immunio::CookieHooks
  end
  if defined? EncryptedCookieJar
    EncryptedCookieJar.send :include, Immunio::CookieHooks
  end
  if defined? UpgradeLegacyEncryptedCookieJar
    UpgradeLegacyEncryptedCookieJar.send :include, Immunio::CookieHooks
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
immunio-1.1.0 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.22 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.19 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.17 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.15 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.14 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.13 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.12 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.11 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.10 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.9 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.8 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.7 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.6 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.5 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.4 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.3 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.2 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.1 lib/immunio/plugins/action_dispatch.rb
immunio-1.0.0 lib/immunio/plugins/action_dispatch.rb