Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/validations/validators/file_path.rb')
-rw-r--r--lib/api/validations/validators/file_path.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/api/validations/validators/file_path.rb b/lib/api/validations/validators/file_path.rb
new file mode 100644
index 00000000000..93a20e5bf7d
--- /dev/null
+++ b/lib/api/validations/validators/file_path.rb
@@ -0,0 +1,18 @@
+# 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)
+ rescue StandardError
+ raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)],
+ message: "should be a valid file path"
+ end
+ end
+ end
+ end
+end