FIX: Extension-less secure uploads (#29914)

Previously, the secure-upload redirection logic would fail for extension-less files. This commit updates it to work, and adds a spec for the behavior.

Extension-less file uploads are not allowed by default, so this is a very niche situation.
This commit is contained in:
David Taylor 2024-11-25 12:18:21 +00:00 committed by GitHub
parent dfa591aeae
commit bfe0eccdd9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -160,7 +160,8 @@ class UploadsController < ApplicationController
# do not serve uploads requested via XHR to prevent XSS
return xhr_not_allowed if request.xhr?
path_with_ext = "#{params[:path]}.#{params[:extension]}"
path_with_ext =
params[:extension].nil? ? params[:path] : "#{params[:path]}.#{params[:extension]}"
upload = upload_from_path_and_extension(path_with_ext)
return render_404 if upload.blank?

View File

@ -605,6 +605,16 @@ RSpec.describe UploadsController do
expect(response.redirect_url).to match("Amz-Expires")
end
it "returns signed url for legitimate request with no extension" do
upload.update!(extension: nil, url: upload.url.sub(".png", ""))
sign_in(user)
get secure_url
expect(response.status).to eq(302)
expect(response.redirect_url).to match("Amz-Expires")
expect(response.location).not_to include(".?")
end
it "should return secure uploads URL when looking up urls" do
upload.update_column(:secure, true)
sign_in(user)