]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
getsource: don't allow getting the source of an attachment
authorSimon McVittie <smcv@ http://smcv.pseudorandom.co.uk/>
Sun, 26 Jul 2009 15:48:25 +0000 (16:48 +0100)
committerSimon McVittie <smcv@ http://smcv.pseudorandom.co.uk/>
Sun, 26 Jul 2009 16:04:34 +0000 (17:04 +0100)
Serving up images etc. as text/plain; charset=utf-8 is unlikely to work
very well, and there's no point in having this CGI action for attachments
(since they're copied into the output as-is anyway).

IkiWiki/Plugin/getsource.pm

index 6a208f1e735d19791da4c5a0821fc124e9bee3a7..1b7eb56c67f5cfb3ed04e93df49d8c01fb47be02 100644 (file)
@@ -66,6 +66,17 @@ sub cgi_getsource ($) {
                exit;
        }
 
                exit;
        }
 
+       if (! defined pagetype($IkiWiki::pagesources{$page})) {
+               IkiWiki::cgi_custom_failure(
+                       $cgi->header(-status => "403 Forbidden"),
+                       IkiWiki::misctemplate(gettext("not a page"),
+                               "<p>".
+                               sprintf(gettext("%s is an attachment, not a page."),
+                                       htmllink("", "", $page)).
+                               "</p>"));
+               exit;
+       }
+
        my $data = IkiWiki::readfile(IkiWiki::srcfile($IkiWiki::pagesources{$page}));
 
        if (! $config{getsource_mimetype}) {
        my $data = IkiWiki::readfile(IkiWiki::srcfile($IkiWiki::pagesources{$page}));
 
        if (! $config{getsource_mimetype}) {