security: whitelist allowed image MIME types for uploads
Only accept common image formats (JPEG, PNG, GIF, WebP, AVIF, SVG) on the upload endpoint. Non-image uploads now return HTTP 415 with a structured JSON error listing the allowed types. Includes a test.
This commit is contained in:
@@ -124,6 +124,19 @@ class AdminTest < Minitest::Test
|
||||
assert_equal 403, last_response.status
|
||||
end
|
||||
|
||||
def test_upload_rejects_unsupported_media_type
|
||||
login
|
||||
get "/admin/posts/new"
|
||||
token = csrf(last_response.body)
|
||||
txt_path = File.join(@dir, "readme.txt")
|
||||
File.binwrite(txt_path, "hello")
|
||||
post "/admin/uploads",
|
||||
"_csrf" => token,
|
||||
"file" => Rack::Test::UploadedFile.new(txt_path, "text/plain")
|
||||
assert_equal 415, last_response.status
|
||||
assert_equal "unsupported_media_type", JSON.parse(last_response.body)["error"]
|
||||
end
|
||||
|
||||
def test_upload_rejects_file_too_large
|
||||
login
|
||||
get "/admin/posts/new"
|
||||
|
||||
Reference in New Issue
Block a user