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)
|
|
|
|
path = params[attr_name]
|
|
|
|
|
|
|
|
Gitlab::Utils.check_path_traversal!(path)
|
2020-06-23 00:09:42 +05:30
|
|
|
rescue ::Gitlab::Utils::PathTraversalAttackError
|
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
|