summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IkiWiki.pm2
-rw-r--r--IkiWiki/Plugin/attachment.pm2
-rw-r--r--IkiWiki/Plugin/comments.pm4
-rw-r--r--IkiWiki/Plugin/editpage.pm4
-rw-r--r--IkiWiki/Plugin/rename.pm5
-rw-r--r--IkiWiki/Receive.pm2
-rwxr-xr-xt/file_pruned.t40
7 files changed, 46 insertions, 13 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index b37b1f344..a5f83ac7a 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -355,7 +355,7 @@ sub getsetup () {
},
wiki_file_prune_regexps => {
type => "internal",
- default => [qr/(^|\/)\.\.(\/|$)/, qr/^\./, qr/\/\./,
+ default => [qr/(^|\/)\.\.(\/|$)/, qr/^\//, qr/^\./, qr/\/\./,
qr/\.x?html?$/, qr/\.ikiwiki-new$/,
qr/(^|\/).svn\//, qr/.arch-ids\//, qr/{arch}\//,
qr/(^|\/)_MTN\//, qr/(^|\/)_darcs\//,
diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm
index ad1dd9bca..8c3ff887a 100644
--- a/IkiWiki/Plugin/attachment.pm
+++ b/IkiWiki/Plugin/attachment.pm
@@ -137,7 +137,7 @@ sub formbuilder (@) {
$filename=linkpage(IkiWiki::possibly_foolish_untaint(
attachment_location($form->field('page')).
IkiWiki::basename($filename)));
- if (IkiWiki::file_pruned($filename, $config{srcdir})) {
+ if (IkiWiki::file_pruned($filename)) {
error(gettext("bad attachment filename"));
}
diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm
index 0aa043215..1c219b6c6 100644
--- a/IkiWiki/Plugin/comments.pm
+++ b/IkiWiki/Plugin/comments.pm
@@ -338,7 +338,7 @@ sub editcomment ($$) {
my $page = $form->field('page');
$page = IkiWiki::possibly_foolish_untaint($page);
if (! defined $page || ! length $page ||
- IkiWiki::file_pruned($page, $config{srcdir})) {
+ IkiWiki::file_pruned($page)) {
error(gettext("bad page name"));
}
@@ -548,7 +548,7 @@ sub commentmoderation ($$) {
# pending comment before untainting.
my ($f)= $id =~ /$config{wiki_file_regexp}/;
if (! defined $f || ! length $f ||
- IkiWiki::file_pruned($f, $config{srcdir})) {
+ IkiWiki::file_pruned($f)) {
error("illegal file");
}
diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm
index 44fe5514a..ee1de8eaa 100644
--- a/IkiWiki/Plugin/editpage.pm
+++ b/IkiWiki/Plugin/editpage.pm
@@ -94,7 +94,7 @@ sub cgi_editpage ($$) {
$page=possibly_foolish_untaint($page);
my $absolute=($page =~ s#^/+##);
if (! defined $page || ! length $page ||
- file_pruned($page, $config{srcdir})) {
+ file_pruned($page)) {
error(gettext("bad page name"));
}
@@ -220,7 +220,7 @@ sub cgi_editpage ($$) {
my $best_loc;
if (! defined $from || ! length $from ||
$from ne $form->field('from') ||
- file_pruned($from, $config{srcdir}) ||
+ file_pruned($from) ||
$from=~/^\// ||
$absolute ||
$form->submitted) {
diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm
index 1a9da6363..69e615ead 100644
--- a/IkiWiki/Plugin/rename.pm
+++ b/IkiWiki/Plugin/rename.pm
@@ -63,9 +63,8 @@ sub check_canrename ($$$$$$) {
error(gettext("no change to the file name was specified"));
}
- # Must be a legal filename, and not absolute.
- if (IkiWiki::file_pruned($destfile, $config{srcdir}) ||
- $destfile=~/^\//) {
+ # Must be a legal filename.
+ if (IkiWiki::file_pruned($destfile)) {
error(sprintf(gettext("illegal name")));
}
diff --git a/IkiWiki/Receive.pm b/IkiWiki/Receive.pm
index cd94d0938..ae1bd8bef 100644
--- a/IkiWiki/Receive.pm
+++ b/IkiWiki/Receive.pm
@@ -82,7 +82,7 @@ sub test () {
my ($file)=$change->{file}=~/$config{wiki_file_regexp}/;
$file=IkiWiki::possibly_foolish_untaint($file);
if (! defined $file || ! length $file ||
- IkiWiki::file_pruned($file, $config{srcdir})) {
+ IkiWiki::file_pruned($file)) {
error(gettext("bad file name %s"), $file);
}
diff --git a/t/file_pruned.t b/t/file_pruned.t
index f9c1c257e..4335ed917 100755
--- a/t/file_pruned.t
+++ b/t/file_pruned.t
@@ -1,41 +1,75 @@
#!/usr/bin/perl
use warnings;
use strict;
-use Test::More tests => 27;
+use Test::More tests => 54;
BEGIN { use_ok("IkiWiki"); }
%config=IkiWiki::defaultconfig();
ok(IkiWiki::file_pruned("src/.htaccess", "src"));
+ok(IkiWiki::file_pruned(".htaccess"));
ok(IkiWiki::file_pruned("src/.ikiwiki/", "src"));
+ok(IkiWiki::file_pruned(".ikiwiki/"));
ok(IkiWiki::file_pruned("src/.ikiwiki/index", "src"));
+ok(IkiWiki::file_pruned(".ikiwiki/index"));
ok(IkiWiki::file_pruned("src/CVS/foo", "src"));
+ok(IkiWiki::file_pruned("CVS/foo"));
ok(IkiWiki::file_pruned("src/subdir/CVS/foo", "src"));
+ok(IkiWiki::file_pruned("subdir/CVS/foo"));
ok(IkiWiki::file_pruned("src/.svn", "src"));
+ok(IkiWiki::file_pruned(".svn"));
ok(IkiWiki::file_pruned("src/subdir/.svn", "src"));
+ok(IkiWiki::file_pruned("subdir/.svn"));
ok(IkiWiki::file_pruned("src/subdir/.svn/foo", "src"));
+ok(IkiWiki::file_pruned("subdir/.svn/foo"));
ok(IkiWiki::file_pruned("src/.git", "src"));
+ok(IkiWiki::file_pruned(".git"));
ok(IkiWiki::file_pruned("src/subdir/.git", "src"));
+ok(IkiWiki::file_pruned("subdir/.git"));
ok(IkiWiki::file_pruned("src/subdir/.git/foo", "src"));
+ok(IkiWiki::file_pruned("subdir/.git/foo"));
ok(! IkiWiki::file_pruned("src/svn/fo", "src"));
+ok(! IkiWiki::file_pruned("svn/fo"));
ok(! IkiWiki::file_pruned("src/git", "src"));
+ok(! IkiWiki::file_pruned("git"));
ok(! IkiWiki::file_pruned("src/index.mdwn", "src"));
+ok(! IkiWiki::file_pruned("index.mdwn"));
ok(! IkiWiki::file_pruned("src/index.", "src"));
+ok(! IkiWiki::file_pruned("index."));
# these are ok because while the filename starts with ".", the canonpathed
# version does not
ok(! IkiWiki::file_pruned("src/.", "src"));
ok(! IkiWiki::file_pruned("src/./", "src"));
+# OTOH, without a srcdir, no canonpath, so they're not allowed.
+ok(IkiWiki::file_pruned("."));
+ok(IkiWiki::file_pruned("./"));
+
+# Without a srcdir, absolute filenames are not allowed.
+ok(IkiWiki::file_pruned("/etc/passwd"));
+ok(IkiWiki::file_pruned("//etc/passwd"));
+ok(IkiWiki::file_pruned("/"));
+ok(IkiWiki::file_pruned("//"));
+ok(IkiWiki::file_pruned("///"));
+
ok(IkiWiki::file_pruned("src/..", "src"));
+ok(IkiWiki::file_pruned(".."));
ok(IkiWiki::file_pruned("src/../", "src"));
+ok(IkiWiki::file_pruned("../"));
ok(IkiWiki::file_pruned("src/../", "src"));
+ok(IkiWiki::file_pruned("../"));
+# This is perhaps counterintuitive.
ok(! IkiWiki::file_pruned("src", "src"));
+
+# Dots, etc, in the srcdir are ok.
ok(! IkiWiki::file_pruned("/.foo/src", "/.foo/src"));
ok(IkiWiki::file_pruned("/.foo/src/.foo/src", "/.foo/src"));
ok(! IkiWiki::file_pruned("/.foo/src/index.mdwn", "/.foo/src/index.mdwn"));
-ok(IkiWiki::file_pruned("x/y/foo.dpkg-tmp", "src"));
-ok(IkiWiki::file_pruned("x/y/foo.ikiwiki-new", "src"));
+ok(IkiWiki::file_pruned("src/y/foo.dpkg-tmp", "src"));
+ok(IkiWiki::file_pruned("y/foo.dpkg-tmp"));
+ok(IkiWiki::file_pruned("src/y/foo.ikiwiki-new", "src"));
+ok(IkiWiki::file_pruned("y/foo.ikiwiki-new"));