summaryrefslogtreecommitdiff
path: root/lib/api/validations
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-10-23 14:59:00 -0700
committerStan Hu <stanhu@gmail.com>2018-10-23 20:47:38 -0700
commita12d25d8a5e95ef868370e7c09e777237047366b (patch)
treee9c7054cddccca198a8f09a79f1ed8990eb73331 /lib/api/validations
parenta310a638db037d3914cf12e580c7a41209d2d06e (diff)
downloadgitlab-ce-a12d25d8a5e95ef868370e7c09e777237047366b.tar.gz
Validate Wiki attachments are valid temporary files
A malicious attacker could craft a request to read arbitrary files on the system. This change adds a Grape validation to ensure that the tempfile parameter delivered by the Rack multipart uploader is a Tempfile type to prevent users from being able to specify arbitrary filenames. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/53072
Diffstat (limited to 'lib/api/validations')
-rw-r--r--lib/api/validations/types/safe_file.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/api/validations/types/safe_file.rb b/lib/api/validations/types/safe_file.rb
new file mode 100644
index 00000000000..53b5790bfa2
--- /dev/null
+++ b/lib/api/validations/types/safe_file.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+# This module overrides the Grape type validator defined in
+# https://github.com/ruby-grape/grape/blob/master/lib/grape/validations/types/file.rb
+module API
+ module Validations
+ module Types
+ class SafeFile < ::Grape::Validations::Types::File
+ def value_coerced?(value)
+ super && value[:tempfile].is_a?(Tempfile)
+ end
+ end
+ end
+ end
+end