Class: Contrast::Agent::Protect::State
- Includes:
- Components::Logger::InstanceMethods
- Defined in:
- lib/contrast/agent/protect/state.rb
Overview
Master class for each protect rule. This class will hold all the rules references. Any access to the rules should be done through this class. and new rules should be added here. Each main rule should require and include and initialize it’s sub-rules.
Instance Attribute Summary collapse
-
#bot_blocker ⇒ Contrast::Agent::Protect::Rule::BotBlocker
readonly
The bot blocker rule.
-
#cmd_injection ⇒ Contrast::Agent::Protect::Rule::CmdInjection
readonly
The command injection rule.
- #cmd_injection_command_backdoors ⇒ Contrast::Agent::Protect::Rule::CmdiBackdoors readonly
- #cmd_injection_semantic_chained_commands ⇒ Contrast::Agent::Protect::Rule::CmdiChainedCommand readonly
- #cmd_injection_semantic_dangerous_paths ⇒ Contrast::Agent::Protect::Rule::CmdiDangerousPath readonly
-
#enabled ⇒ boolean
State dictated by local or server settings.
- #nosql_injection ⇒ Contrast::Agent::Protect::Rule::NoSqli readonly
- #path_traversal ⇒ Contrast::Agent::Protect::Rule::PathTraversal readonly
- #path_traversal_semantic_file_security_bypass ⇒ Contrast::Agent::Protect::Rule::PathTraversalSemanticBypass readonly
-
#reflected_xss ⇒ Contrast::Agent::Protect::Rule::Xss
readonly
The reflected xss rule.
- #sql_injection ⇒ Contrast::Agent::Protect::Rule::Sqli readonly
- #sql_injection_semantic_dangerous_functions ⇒ Contrast::Agent::Protect::Rule::SqliDangerousFunctions readonly
-
#unsafe_file_upload ⇒ Contrast::Agent::Protect::Rule::UnsafeFileUpload
readonly
The unsafe file upload rule.
- #untrusted_deserialization ⇒ Contrast::Agent::Protect::Rule::Deserialization readonly
-
#xxe ⇒ Contrast::Agent::Protect::Rule::Xxe
readonly
The xxe rule.
Instance Method Summary collapse
- #[](rule_id) ⇒ Contrast::Agent::Protect::Rule::Base
-
#enabled? ⇒ Boolean
Check the local configurations first then the server settings.
-
#initialize ⇒ State
constructor
Initialize all the protect rules.
-
#rules ⇒ Hash<String, Contrast::Agent::Protect::Rule::Base>
Return the Rules in Hash form {rule_id => rule_class }.
-
#update ⇒ Object
Update all settings from configuration.
Methods included from Components::Logger::InstanceMethods
Constructor Details
#initialize ⇒ State
Initialize all the protect rules. This should be the one place to access each live rule reference.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/contrast/agent/protect/state.rb', line 49 def initialize @bot_blocker = Contrast::Agent::Protect::Rule::BotBlocker.new @cmd_injection = Contrast::Agent::Protect::Rule::CmdInjection.new @cmd_injection_command_backdoors = @cmd_injection.command_backdoors @cmd_injection_semantic_chained_commands = @cmd_injection.semantic_chained_commands @cmd_injection_semantic_dangerous_paths = @cmd_injection.semantic_dangerous_paths @untrusted_deserialization = Contrast::Agent::Protect::Rule::Deserialization.new @nosql_injection = Contrast::Agent::Protect::Rule::NoSqli.new @path_traversal = Contrast::Agent::Protect::Rule::PathTraversal.new @path_traversal_semantic_file_security_bypass = @path_traversal.semantic_file_security_bypass @sql_injection = Contrast::Agent::Protect::Rule::Sqli.new @sql_injection_semantic_dangerous_functions = @sql_injection.semantic_dangerous_functions @unsafe_file_upload = Contrast::Agent::Protect::Rule::UnsafeFileUpload.new @reflected_xss = Contrast::Agent::Protect::Rule::Xss.new @xxe = Contrast::Agent::Protect::Rule::Xxe.new end |
Instance Attribute Details
#bot_blocker ⇒ Contrast::Agent::Protect::Rule::BotBlocker (readonly)
Returns the bot blocker rule.
19 20 21 |
# File 'lib/contrast/agent/protect/state.rb', line 19 def bot_blocker @bot_blocker end |
#cmd_injection ⇒ Contrast::Agent::Protect::Rule::CmdInjection (readonly)
Returns the command injection rule.
21 22 23 |
# File 'lib/contrast/agent/protect/state.rb', line 21 def cmd_injection @cmd_injection end |
#cmd_injection_command_backdoors ⇒ Contrast::Agent::Protect::Rule::CmdiBackdoors (readonly)
23 24 25 |
# File 'lib/contrast/agent/protect/state.rb', line 23 def cmd_injection_command_backdoors @cmd_injection_command_backdoors end |
#cmd_injection_semantic_chained_commands ⇒ Contrast::Agent::Protect::Rule::CmdiChainedCommand (readonly)
25 26 27 |
# File 'lib/contrast/agent/protect/state.rb', line 25 def cmd_injection_semantic_chained_commands @cmd_injection_semantic_chained_commands end |
#cmd_injection_semantic_dangerous_paths ⇒ Contrast::Agent::Protect::Rule::CmdiDangerousPath (readonly)
27 28 29 |
# File 'lib/contrast/agent/protect/state.rb', line 27 def cmd_injection_semantic_dangerous_paths @cmd_injection_semantic_dangerous_paths end |
#enabled ⇒ boolean
Returns State dictated by local or server settings.
17 18 19 |
# File 'lib/contrast/agent/protect/state.rb', line 17 def enabled @enabled end |
#nosql_injection ⇒ Contrast::Agent::Protect::Rule::NoSqli (readonly)
31 32 33 |
# File 'lib/contrast/agent/protect/state.rb', line 31 def nosql_injection @nosql_injection end |
#path_traversal ⇒ Contrast::Agent::Protect::Rule::PathTraversal (readonly)
33 34 35 |
# File 'lib/contrast/agent/protect/state.rb', line 33 def path_traversal @path_traversal end |
#path_traversal_semantic_file_security_bypass ⇒ Contrast::Agent::Protect::Rule::PathTraversalSemanticBypass (readonly)
35 36 37 |
# File 'lib/contrast/agent/protect/state.rb', line 35 def path_traversal_semantic_file_security_bypass @path_traversal_semantic_file_security_bypass end |
#reflected_xss ⇒ Contrast::Agent::Protect::Rule::Xss (readonly)
Returns the reflected xss rule.
43 44 45 |
# File 'lib/contrast/agent/protect/state.rb', line 43 def reflected_xss @reflected_xss end |
#sql_injection ⇒ Contrast::Agent::Protect::Rule::Sqli (readonly)
37 38 39 |
# File 'lib/contrast/agent/protect/state.rb', line 37 def sql_injection @sql_injection end |
#sql_injection_semantic_dangerous_functions ⇒ Contrast::Agent::Protect::Rule::SqliDangerousFunctions (readonly)
39 40 41 |
# File 'lib/contrast/agent/protect/state.rb', line 39 def sql_injection_semantic_dangerous_functions @sql_injection_semantic_dangerous_functions end |
#unsafe_file_upload ⇒ Contrast::Agent::Protect::Rule::UnsafeFileUpload (readonly)
Returns the unsafe file upload rule.
41 42 43 |
# File 'lib/contrast/agent/protect/state.rb', line 41 def unsafe_file_upload @unsafe_file_upload end |
#untrusted_deserialization ⇒ Contrast::Agent::Protect::Rule::Deserialization (readonly)
29 30 31 |
# File 'lib/contrast/agent/protect/state.rb', line 29 def untrusted_deserialization @untrusted_deserialization end |
#xxe ⇒ Contrast::Agent::Protect::Rule::Xxe (readonly)
Returns the xxe rule.
45 46 47 |
# File 'lib/contrast/agent/protect/state.rb', line 45 def xxe @xxe end |
Instance Method Details
#[](rule_id) ⇒ Contrast::Agent::Protect::Rule::Base
104 105 106 |
# File 'lib/contrast/agent/protect/state.rb', line 104 def [] rule_id rules[rule_id] end |
#enabled? ⇒ Boolean
Check the local configurations first then the server settings.
98 99 100 |
# File 'lib/contrast/agent/protect/state.rb', line 98 def enabled? Contrast::PROTECT.enable || Contrast::SETTINGS.protect_state.enabled end |
#rules ⇒ Hash<String, Contrast::Agent::Protect::Rule::Base>
Return the Rules in Hash form {rule_id => rule_class }. This is used to traverse for each rule and update it’s settings. Also is the way a rule is retrieved given the ID is known.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/contrast/agent/protect/state.rb', line 71 def rules @_rules ||= { @bot_blocker.rule_name => @bot_blocker, @cmd_injection.rule_name => @cmd_injection, @cmd_injection_command_backdoors.rule_name => @cmd_injection_command_backdoors, @cmd_injection_semantic_chained_commands.rule_name => @cmd_injection_semantic_chained_commands, @cmd_injection_semantic_dangerous_paths.rule_name => @cmd_injection_semantic_dangerous_paths, @untrusted_deserialization.rule_name => @untrusted_deserialization, @nosql_injection.rule_name => @nosql_injection, @path_traversal.rule_name => @path_traversal, @path_traversal_semantic_file_security_bypass.rule_name => @path_traversal_semantic_file_security_bypass, @sql_injection.rule_name => @sql_injection, @sql_injection_semantic_dangerous_functions.rule_name => @sql_injection_semantic_dangerous_functions, @unsafe_file_upload.rule_name => @unsafe_file_upload, @reflected_xss.rule_name => @reflected_xss, @xxe.rule_name => @xxe } end |
#update ⇒ Object
Update all settings from configuration.
91 92 93 94 95 |
# File 'lib/contrast/agent/protect/state.rb', line 91 def update rules.values.each(&:update) logger.info('Current rule settings:') rules.each { |k, v| logger.info('Protect Rule mode set', rule: k, mode: v.mode) } end |