debian-mirror-gitlab/lib/api/validations/validators/file_path.rb

23 lines
681 B
Ruby
Raw Normal View History

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
2021-02-22 17:27:13 +05:30
raise Grape::Exceptions::Validation.new(
params: [@scope.full_name(attr_name)],
message: "should be a valid file path"
)
2020-04-22 19:07:51 +05:30
end
end
end
end
end