# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/agent/reporting/settings/helpers' require 'contrast/agent/reporting/settings/keyword' module Contrast module Agent module Reporting module Settings # The keywords and patterns required for the input analysis of each rule with that capability. class RuleDefinition ATTRIBUTES = %i[name keywords patterns].cs__freeze # For the ServerSettings this name is not used instead it is used as key to the keywords and patterns # arrays. It is used in the agent startup message. # # @return name [String] Name of the rule attr_accessor :name # The words to search for in input that indicate an attack # # @return [array] def keywords @_keywords ||= [] end # A word or pattern whose presence in an input represents an attack # # @return [array] def patterns @_patterns ||= [] end # Set keywords. # # @param keywords_array [Array] # @return [array] def keywords= keywords_array Contrast::Agent::Reporting::Settings::Helpers.array_to_iv(Contrast::Agent::Reporting::Settings::Keyword, keywords, keywords_array) end # Set patterns. # # @param patterns_array [Array] # @return [array] def patterns= patterns_array Contrast::Agent::Reporting::Settings::Helpers.array_to_iv(Contrast::Agent::Reporting::Settings::Pattern, patterns, patterns_array) end def to_controlled_hash { name: name, # rubocop:disable Security/Module/Name keywords: keywords.map(&:to_controlled_hash), patterns: patterns.map(&:to_controlled_hash) } end end end end end end