Class: Contrast::Agent::Protect::Rule::NoSqli

Inherits:
Base
  • Object
show all
Includes:
SqlSampleBuilder::AttackBuilder, SqlSampleBuilder::NoSqliSample, Reporting::InputType
Defined in:
lib/contrast/agent/protect/rule/no_sqli/no_sqli.rb,
lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb

Overview

The Ruby implementation of the Protect NoSQL Injection rule.

Defined Under Namespace

Classes: MongoNoSqlScanner

Constant Summary collapse

NAME =
'nosql-injection'
BLOCK_MESSAGE =
'NoSQLi rule triggered. Response blocked.'
APPLICABLE_USER_INPUTS =
[
  BODY, COOKIE_NAME, COOKIE_VALUE, HEADER,
  PARAMETER_NAME, PARAMETER_VALUE, JSON_VALUE,
  MULTIPART_VALUE, MULTIPART_FIELD_NAME,
  XML_VALUE, DWR_VALUE
].cs__freeze

Constants included from Reporting::InputType

Reporting::InputType::BODY, Reporting::InputType::COOKIE_NAME, Reporting::InputType::COOKIE_VALUE, Reporting::InputType::DWR_VALUE, Reporting::InputType::HEADER, Reporting::InputType::JSON_ARRAYED_VALUE, Reporting::InputType::JSON_VALUE, Reporting::InputType::METHOD, Reporting::InputType::MULTIPART_CONTENT_TYPE, Reporting::InputType::MULTIPART_FIELD_NAME, Reporting::InputType::MULTIPART_NAME, Reporting::InputType::MULTIPART_VALUE, Reporting::InputType::PARAMETER_NAME, Reporting::InputType::PARAMETER_VALUE, Reporting::InputType::QUERYSTRING, Reporting::InputType::REQUEST, Reporting::InputType::SOCKET, Reporting::InputType::UNDEFINED_TYPE, Reporting::InputType::UNKNOWN, Reporting::InputType::URI, Reporting::InputType::URL_PARAMETER, Reporting::InputType::XML_VALUE

Constants inherited from Base

Base::BLOCKING_MODES, Base::RULE_NAME, Base::STACK_COLLECTION_RESULTS, Base::SUSPICIOUS_REPORTING_RULES

Constants included from Filters

Filters::POSTFILTER_MODES

Instance Attribute Summary

Attributes inherited from Base

#mode

Instance Method Summary collapse

Methods included from Reporting::InputType

to_a

Methods included from SqlSampleBuilder::AttackBuilder

#append_match, #record_agent_lib_match, #record_match, #select_scanner

Methods included from SqlSampleBuilder::NoSqliSample

#build_sample

Methods inherited from Base

#append_to_activity, #cef_logging, #classify, #enabled?, #excluded?, #initialize, #stream_safe?, #sub_rules, #update

Methods included from Filters

#infilter?, #postfilter, #postfilter?, #prefilter, #prefilter?

Methods included from Builders

#build_attack_result, #build_attack_without_match, #build_base_sample, #build_sample, #build_violation

Methods included from Components::Scope::InstanceMethods

#contrast_enter_method_scopes!, #contrast_exit_method_scopes!, #with_app_scope, #with_contrast_scope, #with_deserialization_scope, #with_split_scope

Methods included from Components::Logger::InstanceMethods

#cef_logger, #logger

Constructor Details

This class inherits a constructor from Contrast::Agent::Protect::Rule::Base

Instance Method Details

#applicable_user_inputsObject



42
43
44
# File 'lib/contrast/agent/protect/rule/no_sqli/no_sqli.rb', line 42

def applicable_user_inputs
  APPLICABLE_USER_INPUTS
end

#block_messageString

Return the specific blocking message for this rule.

Returns:

  • (String)

    the reason for the raised security exception.



38
39
40
# File 'lib/contrast/agent/protect/rule/no_sqli/no_sqli.rb', line 38

def block_message
  BLOCK_MESSAGE
end

#build_attack_with_match(context, input_analysis_result, result, candidate_string, **kwargs) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/contrast/agent/protect/rule/no_sqli/no_sqli.rb', line 67

def build_attack_with_match context, input_analysis_result, result, candidate_string, **kwargs
  return result if mode == :NO_ACTION || mode == :PERMIT

  result ||= build_attack_result(context)
  update_successful_attack_response(context, input_analysis_result, result, candidate_string)
  append_sample(context, input_analysis_result, result, candidate_string, **kwargs)
  result
end

#classificationmodule<Contrast::Agent::Protect::Rule::NoSqliInputClassification>

NoSQLI input classification



49
50
51
# File 'lib/contrast/agent/protect/rule/no_sqli/no_sqli.rb', line 49

def classification
  @_classification ||= Contrast::Agent::Protect::Rule::NoSqliInputClassification.cs__freeze
end

#infilter(context, database, query_string) ⇒ Object

Raises:



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/contrast/agent/protect/rule/no_sqli/no_sqli.rb', line 55

def infilter context, database, query_string
  return unless infilter?(context)

  result = find_attacker(context, query_string, database: database)
  return unless result

  append_to_activity(context, result)
  record_triggered(context)
  cef_logging(result, :successful_attack)
  raise(Contrast::SecurityException.new(self, BLOCK_MESSAGE)) if blocked_violation?(result)
end

#rule_nameObject



31
32
33
# File 'lib/contrast/agent/protect/rule/no_sqli/no_sqli.rb', line 31

def rule_name
  NAME
end