mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 09:42:36 +02:00
Fix bug allowing you to delete your own site directory
This commit is contained in:
parent
092eb4536f
commit
397f34a014
3 changed files with 26 additions and 0 deletions
|
@ -48,6 +48,10 @@ post '/api/delete' do
|
||||||
api_error 400, 'bad_filename', "#{path} is not a valid filename, canceled deleting"
|
api_error 400, 'bad_filename', "#{path} is not a valid filename, canceled deleting"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if current_site.files_path(path) == current_site.files_path
|
||||||
|
api_error 400, 'cannot_delete_site_directory', 'cannot delete the root directory of the site'
|
||||||
|
end
|
||||||
|
|
||||||
if !current_site.file_exists?(path)
|
if !current_site.file_exists?(path)
|
||||||
api_error 400, 'missing_files', "#{path} was not found on your site, canceled deleting"
|
api_error 400, 'missing_files', "#{path} was not found on your site, canceled deleting"
|
||||||
end
|
end
|
||||||
|
|
|
@ -637,6 +637,7 @@ class Site < Sequel::Model
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_file(path)
|
def delete_file(path)
|
||||||
|
return false if files_path(path) == files_path
|
||||||
begin
|
begin
|
||||||
FileUtils.rm files_path(path)
|
FileUtils.rm files_path(path)
|
||||||
rescue Errno::EISDIR
|
rescue Errno::EISDIR
|
||||||
|
|
|
@ -107,6 +107,27 @@ describe 'api delete' do
|
||||||
res[:error_type].must_equal 'missing_files'
|
res[:error_type].must_equal 'missing_files'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'fails to delete site directory' do
|
||||||
|
create_site
|
||||||
|
basic_authorize @user, @pass
|
||||||
|
post '/api/delete', filenames: ['/']
|
||||||
|
res[:error_type].must_equal 'cannot_delete_site_directory'
|
||||||
|
File.exist?(@site.files_path).must_equal true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'fails to delete other directories' do
|
||||||
|
create_site
|
||||||
|
@other_site = @site
|
||||||
|
create_site
|
||||||
|
basic_authorize @user, @pass
|
||||||
|
post '/api/delete', filenames: ["../#{@other_site.username}"]
|
||||||
|
File.exist?(@other_site.base_files_path).must_equal true
|
||||||
|
res[:error_type].must_equal 'missing_files'
|
||||||
|
post '/api/delete', filenames: ["../#{@other_site.username}/index.html"]
|
||||||
|
File.exist?(@other_site.base_files_path+'/index.html').must_equal true
|
||||||
|
res[:error_type].must_equal 'missing_files'
|
||||||
|
end
|
||||||
|
|
||||||
it 'succeeds with valid filenames' do
|
it 'succeeds with valid filenames' do
|
||||||
create_site
|
create_site
|
||||||
basic_authorize @user, @pass
|
basic_authorize @user, @pass
|
||||||
|
|
Loading…
Add table
Reference in a new issue