web commit by JamesWestby: Add a bug and patch for 404 when cancelling the creation...
[ikiwiki] / doc / bugs / 404_when_cancel_create_page.mdwn
1 If you 
2
3  * Add a link to a non-existant page and save. (e.g. [[somewhere-over-the-rainbow]])
4  * Click the question mark to create the page.
5  * Click the cancel button.
6
7 You get a 404 as the page doesn't exist. This patch redirects to the from location
8 if it is known.
9
10
11         === modified file 'IkiWiki/CGI.pm'
12         --- IkiWiki/CGI.pm
13         +++ IkiWiki/CGI.pm
14         @@ -427,7 +427,11 @@
15                 }
16         
17                 if ($form->submitted eq "Cancel") {
18         -               redirect($q, "$config{url}/".htmlpage($page));
19         +               if ( $newpage && defined $from ) {
20         +                       redirect($q, "$config{url}/".htmlpage($from));
21         +               } else {
22         +                       redirect($q, "$config{url}/".htmlpage($page));
23         +               }
24                         return;
25                 }
26                 elsif ($form->submitted eq "Preview") {
27
28
29
30 [P.S. just above that is 
31
32                 $type=$form->param('type');
33                 if (defined $type && length $type && $hooks{htmlize}{$type}) {
34                         $type=possibly_foolish_untaint($type);
35                 }
36                 ....
37                 $file=$page.".".$type;
38
39 I'm a little worried by the `possibly_foolish_untaint` (good name for it by the way,
40 makes it stick out). I don't think much can be done to exploit this (if anything), 
41 but it seems like you could have a very strict regex there rather than the untaint,
42 is there aren't going to be many possible extensions. Something like `/(.\w+)+/`
43 (groups of dot separated alpha-num chars if my perl-foo isn't failing me). You could
44 at least exclude `/` and `..`. I'm happy to turn this in to a patch if you agree.]
45
46