Class: Contrast::Components::Assess::Interface

Inherits:
Object
  • Object
show all
Includes:
ComponentBase
Defined in:
lib/contrast/components/assess.rb

Overview

A wrapper build around the Common Agent Configuration project to allow for access of the values contained in its parent_configuration_spec.yaml. Specifically, this allows for querying the state of the Assess product.

Constant Summary collapse

DEFAULT_STACKTRACES =
'ALL'
DEFAULT_MAX_SOURCE_EVENTS =
50_000
DEFAULT_MAX_PROPAGATION_EVENTS =
50_000
DEFAULT_MAX_RULE_REPORTED =
100
DEFAULT_MAX_RULE_TIME_THRESHOLD =
300_000
CANON_NAME =
'assess'
CONFIG_VALUES =
%w[
  enabled?
  tags
  enable_scan_response
  enable_original_object
  enable_dynamic_sources
  enable_response_as_source
  stacktraces
  max_context_source_events
  max_propagation_events
  max_rule_reported
  time_limit_threshold
].cs__freeze

Constants included from ComponentBase

ComponentBase::ENABLE

Constants included from Contrast::Config::Diagnostics::Tools

Contrast::Config::Diagnostics::Tools::CHECK

Constants included from Contrast::Config::Diagnostics::SingletonTools

Contrast::Config::Diagnostics::SingletonTools::API_CREDENTIALS, Contrast::Config::Diagnostics::SingletonTools::CONTRAST_MARK

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ComponentBase

#false?, #file_exists?, #stringify_array, #true?, #valid_cert?

Methods included from Contrast::Config::Diagnostics::Tools

#add_effective_config_values, #add_single_effective_value

Methods included from Contrast::Config::Diagnostics::SingletonTools

#flatten_settings, #to_config_values, #update_config, #value_to_s

Constructor Details

#initialize(hsh = {}) ⇒ Interface

rubocop:disable Naming/MemoizedInstanceVariableName



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/contrast/components/assess.rb', line 69

def initialize hsh = {}
  @config_values = CONFIG_VALUES
  @canon_name = CANON_NAME
  return unless hsh

  @enable = hsh[:enable]
  @tags = hsh[:tags]
  @enable_scan_response = hsh[:enable_scan_response]
  @enable_dynamic_sources = hsh[:enable_dynamic_sources]
  @enable_original_object = hsh[:enable_original_object]
  @enable_response_as_source = hsh[:enable_response_as_source]
  @sampling = Contrast::Components::Sampling::Interface.new(hsh[:sampling])
  @rules = Contrast::Components::AssessRules::Interface.new(hsh[:rules])
  @stacktraces = hsh[:stacktraces]
  assign_limits(hsh)
end

Instance Attribute Details

#canon_nameString (readonly)

Returns:



33
34
35
# File 'lib/contrast/components/assess.rb', line 33

def canon_name
  @canon_name
end

#config_valuesArray<String> (readonly)

Returns:



35
36
37
# File 'lib/contrast/components/assess.rb', line 35

def config_values
  @config_values
end

#enableBoolean?

Returns:

  • (Boolean, nil)


19
20
21
# File 'lib/contrast/components/assess.rb', line 19

def enable
  @enable
end

#enable_dynamic_sourcesBoolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/contrast/components/assess.rb', line 92

def enable_dynamic_sources
  @enable_dynamic_sources.nil? ? true : @enable_dynamic_sources
end

#enable_original_objectBoolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/contrast/components/assess.rb', line 97

def enable_original_object
  @enable_original_object.nil? ? true : @enable_original_object
end

#enable_response_as_sourceBoolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/contrast/components/assess.rb', line 102

def enable_response_as_source
  @enable_response_as_source.nil? ? false : @enable_response_as_source
end

#enable_scan_responseBoolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/contrast/components/assess.rb', line 87

def enable_scan_response
  @enable_scan_response.nil? ? true : @enable_scan_response
end

#max_context_source_eventsObject



132
133
134
# File 'lib/contrast/components/assess.rb', line 132

def max_context_source_events
  @max_context_source_events ||= DEFAULT_MAX_SOURCE_EVENTS
end

#max_propagation_eventsObject



128
129
130
# File 'lib/contrast/components/assess.rb', line 128

def max_propagation_events
  @max_propagation_events ||= DEFAULT_MAX_PROPAGATION_EVENTS
end

#max_rule_reportedObject



120
121
122
# File 'lib/contrast/components/assess.rb', line 120

def max_rule_reported
  @max_rule_reported ||= DEFAULT_MAX_RULE_REPORTED
end

#rulesContrast::Components::AssessRules::Interface



112
113
114
# File 'lib/contrast/components/assess.rb', line 112

def rules
  @rules ||= Contrast::Components::AssessRules::Interface.new
end

#samplingContrast::Components::Sampling::Interface



107
108
109
# File 'lib/contrast/components/assess.rb', line 107

def sampling
  @sampling ||= Contrast::Components::Sampling::Interface.new
end

#stacktracesObject



116
117
118
# File 'lib/contrast/components/assess.rb', line 116

def stacktraces
  @stacktraces ||= DEFAULT_STACKTRACES
end

#tagsString?

Returns:



137
138
139
# File 'lib/contrast/components/assess.rb', line 137

def tags
  stringify_array(@tags)
end

#time_limit_thresholdObject



124
125
126
# File 'lib/contrast/components/assess.rb', line 124

def time_limit_threshold
  @time_limit_threshold ||= DEFAULT_MAX_RULE_TIME_THRESHOLD
end

Instance Method Details

#capture_stacktrace?(policy_node) ⇒ Boolean

Consider capture_stacktrace_value along with the node type to determine whether stacktraces should be captured.

capture_stacktrace_value -> (:ALL, :NONE, :SOME) node types (SourceNode, PolicyNode, TriggerNode, PropagationNode)

Parameters:

Returns:

  • (Boolean)

    to capture or not to capture, that is the question.



187
188
189
190
191
192
193
194
195
196
# File 'lib/contrast/components/assess.rb', line 187

def capture_stacktrace? policy_node
  return true if capture_stacktrace_value == :ALL
  return false if capture_stacktrace_value == :NONE

  # Below here capture_stacktrace_value must be :SOME.
  return true if policy_node.cs__is_a?(Contrast::Agent::Assess::Policy::SourceNode)
  return true if policy_node.cs__is_a?(Contrast::Agent::Assess::Policy::TriggerNode)

  false
end

#capture_stacktrace_valueSymbol

The value of the stacktrace should be treated as an ENUM. We upcase it for faster comparisons when we use it. Anything not one of the known values of ‘NONE’, ‘SOME’, or ‘ALL’ is treated as ‘ALL’

Returns:

  • (Symbol)

    the normalized value of ::Contrast::CONFIG.assess.stacktraces



168
169
170
171
172
173
174
175
176
177
# File 'lib/contrast/components/assess.rb', line 168

def capture_stacktrace_value
  @_capture_stacktrace_value ||= case stacktraces&.upcase
                                 when 'NONE'
                                   :NONE
                                 when 'SOME'
                                   :SOME
                                 else
                                   :ALL
                                 end
end

#disabled_rulesObject



221
222
223
# File 'lib/contrast/components/assess.rb', line 221

def disabled_rules
  rules&.disabled_rules || ::Contrast::SETTINGS.assess_state.disabled_assess_rules || []
end

#enabled?Boolean

Returns:

  • (Boolean)


141
142
143
144
145
146
147
# File 'lib/contrast/components/assess.rb', line 141

def enabled?
  # config overrides if forcibly set
  return false if forcibly_disabled?
  return true  if forcibly_enabled?

  ::Contrast::SETTINGS.assess_state.enabled == true
end

#forcibly_disabled?Boolean

Returns:

  • (Boolean)


153
154
155
156
157
# File 'lib/contrast/components/assess.rb', line 153

def forcibly_disabled?
  @_forcibly_disabled = false?(enable) if @_forcibly_disabled.nil?

  @_forcibly_disabled
end

#non_request_tracking?Boolean

Returns:

  • (Boolean)


215
216
217
218
219
# File 'lib/contrast/components/assess.rb', line 215

def non_request_tracking?
  @_non_request_tracking = true?(::Contrast::CONFIG.agent.ruby.non_request_tracking) if
    @_non_request_tracking.nil?
  @_non_request_tracking
end

#require_dynamic_sources?Boolean

Returns:

  • (Boolean)


209
210
211
212
213
# File 'lib/contrast/components/assess.rb', line 209

def require_dynamic_sources?
  return @_require_dynamic_sources unless @_require_dynamic_sources.nil?

  @_require_dynamic_sources = !false?(enable_dynamic_sources)
end

#require_scan?Boolean

Returns:

  • (Boolean)


204
205
206
207
# File 'lib/contrast/components/assess.rb', line 204

def require_scan?
  @_require_scan = !false?(::Contrast::CONFIG.agent.ruby.require_scan) if @_require_scan.nil?
  @_require_scan
end

#rule_disabled?(name) ⇒ Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/contrast/components/assess.rb', line 159

def rule_disabled? name
  disabled_rules.include?(name)
end

#scan_response?Boolean

Returns:

  • (Boolean)


198
199
200
201
202
# File 'lib/contrast/components/assess.rb', line 198

def scan_response?
  @_scan_response = !false?(enable_scan_response) if @_scan_response.nil?

  @_scan_response
end

#session_idObject

The id for this process, based on the session metadata or id provided by the user, as indicated in application startup.

The ID of the current application run, as returned by the application settings endpoint or set by application.session_id. If there is no session associated with this run, this field should be omitted when reporting to TS.



244
245
246
# File 'lib/contrast/components/assess.rb', line 244

def session_id
  ::Contrast::SETTINGS.assess_state.session_id
end

#tainted_columnsObject



149
150
151
# File 'lib/contrast/components/assess.rb', line 149

def tainted_columns
  ::Contrast::SETTINGS.tainted_columns
end

#to_effective_config(effective_config) ⇒ Object

Converts current configuration to effective config values class and appends them to EffectiveConfig class.

Parameters:



252
253
254
255
256
# File 'lib/contrast/components/assess.rb', line 252

def to_effective_config effective_config
  super
  sampling&.to_effective_config(effective_config)
  rules&.to_effective_config(effective_config)
end

#track_original_object?Boolean

Returns:

  • (Boolean)


225
226
227
228
229
# File 'lib/contrast/components/assess.rb', line 225

def track_original_object?
  @_track_original_object = !false?(enable_original_object) if @_track_original_object.nil?

  @_track_original_object
end

#track_response_as_source?Boolean

Returns:

  • (Boolean)


231
232
233
234
235
236
# File 'lib/contrast/components/assess.rb', line 231

def track_response_as_source?
  @track_response_as_source = !false?(enable_response_as_source) if
    @track_response_as_source.nil?

  @track_response_as_source
end