diff options
Diffstat (limited to 'app/validators')
-rw-r--r-- | app/validators/untrusted_regexp_validator.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/app/validators/untrusted_regexp_validator.rb b/app/validators/untrusted_regexp_validator.rb new file mode 100644 index 00000000000..02ed7dfb4ed --- /dev/null +++ b/app/validators/untrusted_regexp_validator.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class UntrustedRegexpValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + return unless value + + Gitlab::UntrustedRegexp.new(value) + + rescue RegexpError => e + record.errors.add(attribute, "not valid RE2 syntax: #{e.message}") + end +end |