Security: Instiki 0.16.2

On Webs with file uploads enabled, uploaded files were stored
(in version 0.16.1 and earlier) in the public/ directory.

This was a security threat. A miscreant could upload a .html file.
When a user clicked on the link to the file, it was opened (unsanitized)
in the browser.

As of version 0.16.2, uploaded files are stored in the webs/
directory. Now, when the user clicks on the link, the file is sent
with the

    Content-Disposition: attachment

header set, which causes the file to be downloaded, rather than opened
in the browser. As always, files downloaded from the internets should be
treated with caution. At least, this way, they are not aoutomatically 
opened in the browser.

To move your existing uploaded files to the new location, do a

     rake upgrade_instiki
This commit is contained in:
Jacques Distler 2009-01-26 00:21:30 -06:00
parent b80995dbdc
commit 5d15e3f39d
6 changed files with 24 additions and 9 deletions

View file

@ -241,9 +241,9 @@ module Instiki
module VERSION #:nodoc: module VERSION #:nodoc:
MAJOR = 0 MAJOR = 0
MINOR = 16 MINOR = 16
TINY = 1 TINY = 2
SUFFIX = '(MML+)' SUFFIX = '(MML+)'
PRERELEASE = 'pre' # false PRERELEASE = false
if PRERELEASE if PRERELEASE
STRING = [MAJOR, MINOR].join('.') + PRERELEASE + SUFFIX STRING = [MAJOR, MINOR].join('.') + PRERELEASE + SUFFIX
else else

View file

@ -153,9 +153,9 @@ class Web < ActiveRecord::Base
def files_path def files_path
if default_web? if default_web?
"#{RAILS_ROOT}/public/files" "#{RAILS_ROOT}/webs/files"
else else
"#{RAILS_ROOT}/public/#{self.address}/files" "#{RAILS_ROOT}/webs/#{self.address}/files"
end end
end end
end end

View file

@ -0,0 +1,15 @@
require 'sqlite3'
task :upgrade_instiki do
db = SQLite3::Database.new( "db/production.db.sqlite3" )
db.execute( "select * from webs" ) do |row|
if File.exists?('public/' + row[4])
if File.exists?('webs/' + row[4])
print "Warning! The directory webs/#{row[4]} already exists. Skipping.\n"
else
File.rename('public/' + row[4], 'webs/' + row[4])
print "Moved: #{row[4]}\n"
end
end
end
end

View file

@ -24,7 +24,7 @@ class FileControllerTest < Test::Unit::TestCase
@wiki = Wiki.new @wiki = Wiki.new
WikiFile.delete_all WikiFile.delete_all
require 'fileutils' require 'fileutils'
FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*") FileUtils.rm_rf("#{RAILS_ROOT}/webs/wiki1/files/*")
end end
def test_file_upload_form def test_file_upload_form

View file

@ -510,7 +510,7 @@ END_THM
def test_link_to_pic_and_file def test_link_to_pic_and_file
WikiFile.delete_all WikiFile.delete_all
require 'fileutils' require 'fileutils'
FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*") FileUtils.rm_rf("#{RAILS_ROOT}/webs/wiki1/files/*")
@web.wiki_files.create(:file_name => 'square.jpg', :description => 'Square', :content => 'never mind') @web.wiki_files.create(:file_name => 'square.jpg', :description => 'Square', :content => 'never mind')
assert_markup_parsed_as( assert_markup_parsed_as(
"<p><img alt='Blue Square' src='../file/square.jpg'/></p>", "<p><img alt='Blue Square' src='../file/square.jpg'/></p>",
@ -529,7 +529,7 @@ END_THM
def test_link_to_pic_and_file_null_desc def test_link_to_pic_and_file_null_desc
WikiFile.delete_all WikiFile.delete_all
require 'fileutils' require 'fileutils'
FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*") FileUtils.rm_rf("#{RAILS_ROOT}/webs/wiki1/files/*")
@web.wiki_files.create(:file_name => 'square.jpg', :description => '', :content => 'never mind') @web.wiki_files.create(:file_name => 'square.jpg', :description => '', :content => 'never mind')
assert_markup_parsed_as( assert_markup_parsed_as(
"<p><img alt='Blue Square' src='../file/square.jpg'/></p>", "<p><img alt='Blue Square' src='../file/square.jpg'/></p>",

View file

@ -7,8 +7,8 @@ class WikiFileTest < Test::Unit::TestCase
def setup def setup
@web = webs(:test_wiki) @web = webs(:test_wiki)
mkdir_p("#{RAILS_ROOT}/public/wiki1/files/") mkdir_p("#{RAILS_ROOT}/webs/wiki1/files/")
rm_rf("#{RAILS_ROOT}/public/wiki1/files/*") rm_rf("#{RAILS_ROOT}/webs/wiki1/files/*")
WikiFile.delete_all WikiFile.delete_all
end end