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

Inherits:
Grape::Validations::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
# 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]
  path = Gitlab::Utils.check_path_traversal!(path)
  Gitlab::Utils.check_allowed_absolute_path!(path, path_allowlist)
rescue
  raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)],
                                       message: "should be a valid file path"
end