diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-26 21:09:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-26 21:09:11 +0000 |
commit | f82d5dcab7c3d9a672abc827c92f86887b683a7d (patch) | |
tree | 4a4379a82ab825185aaeafdfb9eb0f9029dc286c /lib/api/helpers/custom_validators.rb | |
parent | 619d0b6922a6cf95d291fbbf5fa3d09e772a1ea8 (diff) | |
download | gitlab-ce-f82d5dcab7c3d9a672abc827c92f86887b683a7d.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/api/helpers/custom_validators.rb')
-rw-r--r-- | lib/api/helpers/custom_validators.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/api/helpers/custom_validators.rb b/lib/api/helpers/custom_validators.rb index c86eae6f2da..dab4ca1d1f1 100644 --- a/lib/api/helpers/custom_validators.rb +++ b/lib/api/helpers/custom_validators.rb @@ -3,6 +3,17 @@ module API module Helpers module CustomValidators + 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 + class Absence < Grape::Validations::Base def validate_param!(attr_name, params) return if params.respond_to?(:key?) && !params.key?(attr_name) @@ -38,6 +49,7 @@ module API end end +Grape::Validations.register_validator(:file_path, ::API::Helpers::CustomValidators::FilePath) Grape::Validations.register_validator(:absence, ::API::Helpers::CustomValidators::Absence) Grape::Validations.register_validator(:integer_none_any, ::API::Helpers::CustomValidators::IntegerNoneAny) Grape::Validations.register_validator(:array_none_any, ::API::Helpers::CustomValidators::ArrayNoneAny) |