-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1083 from texpert/fix-path-traversal-in-download-…
…private-file Mitigate arbitrary path traversal in download_private_file (GHSL-2024-183)
- Loading branch information
Showing
7 changed files
with
65 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'Media requests', type: :request do | ||
init_site | ||
|
||
describe 'Download private file' do | ||
let(:current_site) { Cama::Site.first.decorate } | ||
|
||
before do | ||
allow_any_instance_of(CamaleonCms::Admin::MediaController).to receive(:cama_authenticate) | ||
allow_any_instance_of(CamaleonCms::Admin::MediaController).to receive(:current_site).and_return(current_site) | ||
end | ||
|
||
context 'when the file path is valid and file exists' do | ||
before do | ||
allow_any_instance_of(CamaleonCmsLocalUploader).to receive(:fetch_file).and_return('some_file') | ||
|
||
allow_any_instance_of(CamaleonCms::Admin::MediaController).to receive(:send_file) | ||
allow_any_instance_of(CamaleonCms::Admin::MediaController).to receive(:default_render) | ||
end | ||
|
||
it 'allows the file to be downloaded' do | ||
expect_any_instance_of(CamaleonCms::Admin::MediaController).to receive(:send_file).with('some_file', disposition: 'inline') | ||
|
||
get '/admin/media/download_private_file', params: { file: 'some_file' } | ||
end | ||
end | ||
|
||
context 'when file path is invalid' do | ||
it 'returns invalid file path error' do | ||
get '/admin/media/download_private_file', params: { file: './../../../../../etc/passwd' } | ||
|
||
expect(response.body).to include('Invalid file path') | ||
end | ||
end | ||
|
||
context 'when the file is not found' do | ||
it 'returns file not found error' do | ||
get '/admin/media/download_private_file', params: { file: 'passwd' } | ||
|
||
expect(response.body).to include('File not found') | ||
end | ||
end | ||
end | ||
end |