2020-04-22 19:07:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Validations
|
|
|
|
module Validators
|
|
|
|
class FilePath < Grape::Validations::Base
|
|
|
|
def validate_param!(attr_name, params)
|
2020-10-24 23:57:45 +05:30
|
|
|
options = @option.is_a?(Hash) ? @option : {}
|
|
|
|
path_allowlist = options.fetch(:allowlist, [])
|
2020-04-22 19:07:51 +05:30
|
|
|
path = params[attr_name]
|
2020-10-24 23:57:45 +05:30
|
|
|
path = Gitlab::Utils.check_path_traversal!(path)
|
|
|
|
Gitlab::Utils.check_allowed_absolute_path!(path, path_allowlist)
|
|
|
|
rescue
|
2020-04-22 19:07:51 +05:30
|
|
|
raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)],
|
|
|
|
message: "should be a valid file path"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|