Skip to content

Commit d80f4fa

Browse files
committed
Merge pull request discourse#1523 from dbarbera/avatar_formats_fix
add image authorization on upload_avatar
2 parents c954807 + 9106596 commit d80f4fa

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

app/controllers/users_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ def upload_avatar
302302

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

305+
unless SiteSetting.authorized_image?(file)
306+
return render status: 422, text: I18n.t("upload.images.unknown_image_type")
307+
end
308+
305309
# check the file size (note: this might also be done in the web server)
306310
filesize = File.size(file.tempfile)
307311
max_size_kb = SiteSetting.max_image_size_kb * 1024

spec/controllers/users_controller_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,12 @@ def post_user
966966
response.status.should eq 413
967967
end
968968

969+
it 'rejects unauthorized images' do
970+
SiteSetting.stubs(:authorized_image?).returns(false)
971+
xhr :post, :upload_avatar, username: user.username, file: avatar
972+
response.status.should eq 422
973+
end
974+
969975
it 'is successful' do
970976
upload = Fabricate(:upload)
971977
Upload.expects(:create_for).returns(upload)

0 commit comments

Comments
 (0)