Class: Gitlab::Search::AbuseDetection
- Inherits:
-
Object
- Object
- Gitlab::Search::AbuseDetection
- Includes:
- ActiveModel::Validations, AbuseValidators
- Defined in:
- lib/gitlab/search/abuse_detection.rb
Constant Summary collapse
- MAX_PIPE_SYNTAX_FILTERS =
5- ABUSIVE_TERM_SIZE =
100- ALLOWED_CHARS_REGEX =
%r{\A[[:alnum:]_\-\+\/\.!]+\z}- READABLE_PARAMS =
%i[ group_id project_id project_ref query_string repository_ref scope ].freeze
- STOP_WORDS =
%w[ a an and are as at be but by for if in into is it no not of on or such that the their then there these they this to was will with ].freeze
Instance Method Summary collapse
- #abusive_pipes? ⇒ Boolean
-
#initialize(params) ⇒ AbuseDetection
constructor
A new instance of AbuseDetection.
Constructor Details
#initialize(params) ⇒ AbuseDetection
Returns a new instance of AbuseDetection.
51 52 53 54 55 56 57 |
# File 'lib/gitlab/search/abuse_detection.rb', line 51 def initialize(params) @raw_params = {} READABLE_PARAMS.each do |p| instance_variable_set(:"@#{p}", params[p]) @raw_params[p] = params[p] end end |
Instance Method Details
#abusive_pipes? ⇒ Boolean
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gitlab/search/abuse_detection.rb', line 59 def abusive_pipes? pipes = query_string.to_s.split('|') errors.add(:query_string, 'too many pipe syntax filters') if pipes.length > MAX_PIPE_SYNTAX_FILTERS pipes.each do |q| self.class.new(raw_params.merge(query_string: q)).tap do |p| p.validate p.errors.(:query_string).each do |msg| next if errors.added?(:query_string, msg) errors.add(:query_string, msg) end end end errors.any? end |