mirror of
https://github.com/opf/openproject.git
synced 2026-06-13 19:20:00 +00:00
Always serve repository file entries as application/octet-stream
This commit is contained in:
@@ -446,11 +446,11 @@ class RepositoriesController < ApplicationController
|
||||
end
|
||||
|
||||
def send_raw(content, path)
|
||||
# Force the download
|
||||
send_opt = { filename: filename_for_content_disposition(path.split("/").last) }
|
||||
send_type = OpenProject::MimeType.of(path)
|
||||
send_opt[:type] = send_type.to_s if send_type
|
||||
send_data content, send_opt
|
||||
# Force the download as binary to prevent CSP bypass
|
||||
send_data content,
|
||||
filename: filename_for_content_disposition(path.split("/").last),
|
||||
type: "application/octet-stream",
|
||||
disposition: :attachment
|
||||
end
|
||||
|
||||
def render_text_entry
|
||||
|
||||
@@ -291,6 +291,18 @@ RSpec.describe RepositoriesController do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#send_raw" do
|
||||
let(:permissions) { [:browse_repository] }
|
||||
|
||||
it "serves raw files as application/octet-stream attachment" do
|
||||
get :entry, params: { project_id: project.identifier, repo_path: "subversion_test/textfile.txt", format: "raw" }
|
||||
|
||||
expect(response).to be_successful
|
||||
expect(response.headers["Content-Type"]).to eq("application/octet-stream")
|
||||
expect(response.headers["Content-Disposition"]).to match(/attachment/)
|
||||
end
|
||||
end
|
||||
|
||||
describe "checkout path" do
|
||||
render_views
|
||||
|
||||
|
||||
Reference in New Issue
Block a user