diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2018-10-29 16:08:08 +0000 |
---|---|---|
committer | Jan Provaznik <jprovaznik@gitlab.com> | 2018-10-29 16:08:08 +0000 |
commit | d3cd569bc60f81613c700e64e7ee5b469e32a4ac (patch) | |
tree | 6c6f20f4d6f76834ce40977a425f45dd09819b78 /lib/api | |
parent | 58646c65d5df98f2c16995056a3dd4a77d1eb1c9 (diff) | |
parent | a12d25d8a5e95ef868370e7c09e777237047366b (diff) | |
download | gitlab-ce-d3cd569bc60f81613c700e64e7ee5b469e32a4ac.tar.gz |
Merge branch 'sh-fix-wiki-security-issue-53072' into 'master'
[master] Validate Wiki attachments are valid temporary files
See merge request gitlab/gitlabhq!2568
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/validations/types/safe_file.rb | 15 | ||||
-rw-r--r-- | lib/api/wikis.rb | 4 |
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 6e1d4eb335f..24746f4efc6 100644 --- a/lib/api/wikis.rb +++ b/lib/api/wikis.rb @@ -6,7 +6,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 @@ -100,7 +100,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 |