Skip to content

Commit

Permalink
Merge pull request discourse#1523 from dbarbera/avatar_formats_fix
Browse files Browse the repository at this point in the history
add image authorization on upload_avatar
  • Loading branch information
ZogStriP committed Oct 14, 2013
2 parents c954807 + 9106596 commit d80f4fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ def upload_avatar

file = params[:file] || params[:files].first

unless SiteSetting.authorized_image?(file)
return render status: 422, text: I18n.t("upload.images.unknown_image_type")
end

# check the file size (note: this might also be done in the web server)
filesize = File.size(file.tempfile)
max_size_kb = SiteSetting.max_image_size_kb * 1024
Expand Down
6 changes: 6 additions & 0 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,12 @@ def post_user
response.status.should eq 413
end

it 'rejects unauthorized images' do
SiteSetting.stubs(:authorized_image?).returns(false)
xhr :post, :upload_avatar, username: user.username, file: avatar
response.status.should eq 422
end

it 'is successful' do
upload = Fabricate(:upload)
Upload.expects(:create_for).returns(upload)
Expand Down

0 comments on commit d80f4fa

Please sign in to comment.