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
path: root/lib
diff options
context:
space:
mode:
authorThiago Presa <tpresa@gitlab.com>2018-10-25 00:07:44 +0300
committerThiago Presa <tpresa@gitlab.com>2018-10-25 03:40:03 +0300
commitfd080530e5de0e890eccfc917d4ba40c0b40c564 (patch)
tree6e2bd81a5e1e8ac49901f551d7eb286b41e511fc /lib
parentbb3ad8e7a19ad1e2b70537f44453e0030fe741d5 (diff)
Merge branch 'sh-validate-wiki-attachments-11-3' into 'security-11-3'
[11.3] Validate Wiki attachments are valid temporary files See merge request gitlab/gitlabhq!2570
Diffstat (limited to 'lib')
-rw-r--r--lib/api/validations/types/safe_file.rb15
-rw-r--r--lib/api/wikis.rb4
2 files changed, 17 insertions, 2 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
diff --git a/lib/api/wikis.rb b/lib/api/wikis.rb
index e86ebc573f2..c98f6dd9318 100644
--- a/lib/api/wikis.rb
+++ b/lib/api/wikis.rb
@@ -4,7 +4,7 @@ module API
def commit_params(attrs)
{
file_name: attrs[:file][:filename],
- file_content: File.read(attrs[:file][:tempfile]),
+ file_content: attrs[:file][:tempfile].read,
branch_name: attrs[:branch]
}
end
@@ -98,7 +98,7 @@ module API
success Entities::WikiAttachment
end
params do
- requires :file, type: File, desc: 'The attachment file to be uploaded'
+ requires :file, type: ::API::Validations::Types::SafeFile, desc: 'The attachment file to be uploaded'
optional :branch, type: String, desc: 'The name of the branch'
end
post ":id/wikis/attachments", requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do