Class: Contrast::Config::ProtectRulesConfiguration

Inherits:
Object
  • Object
show all
Includes:
BaseConfiguration
Defined in:
lib/contrast/config/protect_rules_configuration.rb

Overview

Common Configuration settings. Those in this section pertain to the protect rule modes of the Agent.

Constant Summary collapse

BASE_RULE =
'Contrast::Agent::Protect::Rule::Base'.cs__freeze

Constants included from BaseConfiguration

BaseConfiguration::AT_UNDERSCORE

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hsh = {}) ⇒ ProtectRulesConfiguration

rubocop:disable Metrics/AbcSize



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/contrast/config/protect_rules_configuration.rb', line 28

def initialize hsh = {} # rubocop:disable Metrics/AbcSize
  return unless hsh

  # IVs must be with the same name as rule_id
  @disabled_rules = hsh[:disabled_rules]
  @rule_base = Contrast::Config::ProtectRuleConfiguration.new(hsh[BASE_RULE.to_sym])
  @bot_blocker = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'bot-blocker'])
  @cmd_injection = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'cmd-injection'])
  @cmd_injection_command_backdoors =
    Contrast::Config::ProtectRuleConfiguration.new(hsh[:'cmd-injection-command-backdoors'])
  @cmd_injection_semantic_chained_commands =
    Contrast::Config::ProtectRuleConfiguration.new(hsh[:'cmd-injection-semantic-chained-commands'])
  @cmd_injection_semantic_dangerous_paths =
    Contrast::Config::ProtectRuleConfiguration.new(hsh[:'cmd-injection-semantic-dangerous-paths'])
  @method_tampering = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'method-tampering'])
  @nosql_injection = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'nosql-injection'])
  @path_traversal = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'path-traversal'])
  @path_traversal_semantic_file_security_bypass =
    Contrast::Config::ProtectRuleConfiguration.new(hsh[:'path-traversal-semantic-file-security-bypass'])
  @reflected_xss = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'reflected-xss'])
  @sql_injection = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'sql-injection'])
  @sql_injection_semantic_dangerous_functions =
    Contrast::Config::ProtectRuleConfiguration.new(hsh[:'sql-injection-semantic-dangerous-functions'])
  @unsafe_file_upload = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'unsafe-file-upload'])
  @untrusted_deserialization = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'untrusted-deserialization'])
  @xxe = Contrast::Config::ProtectRuleConfiguration.new(hsh[:xxe])
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *_args) ⇒ Object

if method ‘Contrast::Agent::Protect::Rule::Base’ is being called from convert_to_hash handle missing method and call original getter



94
95
96
97
98
# File 'lib/contrast/config/protect_rules_configuration.rb', line 94

def method_missing name, *_args
  return unless name.to_s.include?('Base') || name.to_s.start_with?('Contrast')

  @rule_base
end

Instance Attribute Details

#bot_blockerObject (readonly)

Returns the value of attribute bot_blocker.



13
14
15
# File 'lib/contrast/config/protect_rules_configuration.rb', line 13

def bot_blocker
  @bot_blocker
end

#cmd_injectionObject (readonly)

Returns the value of attribute cmd_injection.



13
14
15
# File 'lib/contrast/config/protect_rules_configuration.rb', line 13

def cmd_injection
  @cmd_injection
end

#cmd_injection_command_backdoorsObject (readonly)

Returns the value of attribute cmd_injection_command_backdoors.



13
14
15
# File 'lib/contrast/config/protect_rules_configuration.rb', line 13

def cmd_injection_command_backdoors
  @cmd_injection_command_backdoors
end

#cmd_injection_semantic_chained_commandsObject (readonly)

Returns the value of attribute cmd_injection_semantic_chained_commands.



13
14
15
# File 'lib/contrast/config/protect_rules_configuration.rb', line 13

def cmd_injection_semantic_chained_commands
  @cmd_injection_semantic_chained_commands
end

#cmd_injection_semantic_dangerous_pathsObject (readonly)

Returns the value of attribute cmd_injection_semantic_dangerous_paths.



13
14
15
# File 'lib/contrast/config/protect_rules_configuration.rb', line 13

def cmd_injection_semantic_dangerous_paths
  @cmd_injection_semantic_dangerous_paths
end

#disabled_rulesObject

Returns the value of attribute disabled_rules.



12
13
14
# File 'lib/contrast/config/protect_rules_configuration.rb', line 12

def disabled_rules
  @disabled_rules
end

#method_tamperingObject (readonly)

Returns the value of attribute method_tampering.



13
14
15
# File 'lib/contrast/config/protect_rules_configuration.rb', line 13

def method_tampering
  @method_tampering
end

#nosql_injectionObject (readonly)

Returns the value of attribute nosql_injection.



13
14
15
# File 'lib/contrast/config/protect_rules_configuration.rb', line 13

def nosql_injection
  @nosql_injection
end

#path_traversalObject (readonly)

Returns the value of attribute path_traversal.



13
14
15
# File 'lib/contrast/config/protect_rules_configuration.rb', line 13

def path_traversal
  @path_traversal
end

#path_traversal_semantic_file_security_bypassObject (readonly)

Returns the value of attribute path_traversal_semantic_file_security_bypass.



13
14
15
# File 'lib/contrast/config/protect_rules_configuration.rb', line 13

def path_traversal_semantic_file_security_bypass
  @path_traversal_semantic_file_security_bypass
end

#reflected_xssObject (readonly)

Returns the value of attribute reflected_xss.



13
14
15
# File 'lib/contrast/config/protect_rules_configuration.rb', line 13

def reflected_xss
  @reflected_xss
end

#rule_baseObject (readonly)

Returns the value of attribute rule_base.



13
14
15
# File 'lib/contrast/config/protect_rules_configuration.rb', line 13

def rule_base
  @rule_base
end

#sql_injectionObject (readonly)

Returns the value of attribute sql_injection.



13
14
15
# File 'lib/contrast/config/protect_rules_configuration.rb', line 13

def sql_injection
  @sql_injection
end

#sql_injection_semantic_dangerous_functionsObject (readonly)

Returns the value of attribute sql_injection_semantic_dangerous_functions.



13
14
15
# File 'lib/contrast/config/protect_rules_configuration.rb', line 13

def sql_injection_semantic_dangerous_functions
  @sql_injection_semantic_dangerous_functions
end

#unsafe_file_uploadObject (readonly)

Returns the value of attribute unsafe_file_upload.



13
14
15
# File 'lib/contrast/config/protect_rules_configuration.rb', line 13

def unsafe_file_upload
  @unsafe_file_upload
end

#untrusted_deserializationObject (readonly)

Returns the value of attribute untrusted_deserialization.



13
14
15
# File 'lib/contrast/config/protect_rules_configuration.rb', line 13

def untrusted_deserialization
  @untrusted_deserialization
end

#xxeObject (readonly)

Returns the value of attribute xxe.



13
14
15
# File 'lib/contrast/config/protect_rules_configuration.rb', line 13

def xxe
  @xxe
end

Instance Method Details

#[](key) ⇒ Object



60
61
62
# File 'lib/contrast/config/protect_rules_configuration.rb', line 60

def [] key
  send(convert_key(key).to_sym)
end

#[]=(key, value) ⇒ Object



56
57
58
# File 'lib/contrast/config/protect_rules_configuration.rb', line 56

def []= key, value
  instance_variable_set("@#{ convert_key(key) }".to_sym, value)
end

#convert_key(key) ⇒ Object



64
65
66
# File 'lib/contrast/config/protect_rules_configuration.rb', line 64

def convert_key key
  return_proper_class(key).to_s.tr('-', '_')
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/contrast/config/protect_rules_configuration.rb', line 100

def respond_to_missing? method_name, include_private = false
  (method_name.to_s.include?('Base') || method_name.to_s.start_with?('Contrast')) || super
end

#return_proper_class(str_key) ⇒ Object

This method is to handle the specific case of Contrast::Agent::Protect::Rule::Base from protect/base.rb#initialize

Parameters:

  • str_key (String)

    the key we want to check form the config

Returns:

  • String



85
86
87
88
89
90
# File 'lib/contrast/config/protect_rules_configuration.rb', line 85

def return_proper_class str_key
  return BASE_RULE if str_key == 'rule_base'
  return 'rule_base' if str_key == BASE_RULE

  str_key
end

#to_contrast_hashObject

Convert instance variable names to format expected by TS for adding to the hash



70
71
72
73
74
75
76
77
78
# File 'lib/contrast/config/protect_rules_configuration.rb', line 70

def to_contrast_hash
  hsh = {}
  instance_variables.each do |iv|
    # strip the '@' to get the key
    key = return_proper_class(iv.to_s.delete('@'))
    hsh[key.tr('_', '-')] = send(key.to_sym)
  end
  hsh
end