Class: API::Validations::Validators::FilePath

Inherits:
Grape::Validations::Validators::Base
  • Object
show all
Defined in:
lib/api/validations/validators/file_path.rb

Instance Method Summary collapse

Instance Method Details

#validate_param!(attr_name, params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/api/validations/validators/file_path.rb', line 7

def validate_param!(attr_name, params)
  options = @option.is_a?(Hash) ? @option : {}
  path_allowlist = options.fetch(:allowlist, [])
  path = params[attr_name]
  Gitlab::PathTraversal.check_allowed_absolute_path_and_path_traversal!(path, path_allowlist)
rescue StandardError
  raise Grape::Exceptions::Validation.new(
    params: [@scope.full_name(attr_name)],
    message: "should be a valid file path"
  )
end