]> sipb.mit.edu Git - ikiwiki.git/blob - doc/forum/Allow_overriding_of_symlink_restriction.mdwn
eb86ef30ffe7689a7618c74cb29d23bdf67ba38a
[ikiwiki.git] / doc / forum / Allow_overriding_of_symlink_restriction.mdwn
1 There is currently a restriction in ikiwiki that there cannot be any symlinks in the source path.  This is to deal with a security issue discussed [[here|security#index29h2]].  The issue, as I understand it, is that someone might change a symlink and so cause things on the server to be published when the server admin doesn't want them to be.
2
3 I think there are two issues here:
4
5  - Symlinks with the source dir path itself, and
6  - Symlinks inside the source directory.
7
8 The first appears to me to be less of a security issue.  If there is a way for a malicious person to change where that path points, then you have problems this check isn't going to solve.  The second is quite clearly a security issue - if someone were to commit a symlink into the source dir they could cause lots of stuff to be published that shouldn't be.
9
10 > Correct. However, where does the revision controlled source directory end? Ikiwiki has no way
11 > of knowing. It cannot assume that `srcdir` is in revision control, and
12 > everything outside is not. For example, ikiwiki's own source tree has the
13 > doc wiki source inside `ikiwiki/doc`. So to fully close the source dir
14 > symlink issue, it's best to, by default, assume that the revision
15 > controlled directories could go down arbitrarily deep, down to the root of
16 > the filesystem. --[[Joey]]
17
18 The current code seems to check this constraint at the top of IkiWiki/Render.pm at the start of refresh().  It seems to only check the source dir itself, not the subdirs.  Then it uses File::Find to recuse which doesn't follow symlinks.
19
20 Now my problem:  I have a hosted server where I cannot avoid having a symlink in the source path.  I've made a patch to optionally turn off the symlink checking in the source path itself.  The patch would still not follow symlinks inside the source dir.  This would seem to be ok security-wise for me as I know that path is ok and it isn't going to change on me.
21
22 > BTW, if you have a problem, please file it in [[todo]] or [[bugs]] in the
23 > future. Especially if you also have a patch. :-) --[[Joey]]
24
25 Is there a huge objection to this patch?
26
27 (note: patch inline - look at the source to get it.  And I didn't re-indent the code when I added the if...)
28
29         index 990fcaa..d7cb37e 100644
30         --- a/IkiWiki/Render.pm
31         +++ b/IkiWiki/Render.pm
32         @@ -260,6 +260,7 @@ sub prune ($) { #{{{
33          
34          sub refresh () { #{{{
35                 # security check, avoid following symlinks in the srcdir path
36         +       if (! $config{allowsrcdirlinks}) {
37                 my $test=$config{srcdir};
38                 while (length $test) {
39                         if (-l $test) {
40         @@ -269,6 +270,7 @@ sub refresh () { #{{{
41                                 $test=dirname($test);
42                         }
43                 }
44         +       }
45         
46                 run_hooks(refresh => sub { shift->() });
47
48 > No, I don't have a big objection to such an option, as long as it's
49 > extremely well documented that it will make many setups insecure.
50 > It would be nice to come up with an option name that makes clear that
51 > it's allowing symlinks in the path to the `srcdir`, but still not inside
52 > the `srcdir`.
53 > --[[Joey]]
54
55 There is a second location where this can be an issue.  That is in the
56 front of the wrapper.  There the issue is that the path to the source dir
57 as seen on the cgi server and on the git server are different - each has
58 symlinks in place to support the other.  The current wrapper gets the
59 absolute path to the source dir, and that breaks things for me.  This is a
60 slightly different, albeit related, issue to the one above.  The following
61 patch fixes things.  Again, patch inline.  Again, this patch could be
62 cleaned up :).  I just wanted to see if there was any chance of a patch
63 like this being accepted before I bothered.
64
65         diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm
66         index 79b9eb3..e88118b 100644
67         --- a/IkiWiki/Wrapper.pm
68         +++ b/IkiWiki/Wrapper.pm
69         @@ -9,9 +9,13 @@ use Data::Dumper;
70          use IkiWiki;
71          
72          sub gen_wrapper () { #{{{
73         +        my $this = $0;
74         +        if ($config{allowsrcdirlinks}) {
75         +       } else {
76                 $config{srcdir}=abs_path($config{srcdir});
77                 $config{destdir}=abs_path($config{destdir});
78                 my $this=abs_path($0);
79         +       }
80                 if (! -x $this) {
81                         error(sprintf(gettext("%s doesn't seem to be executable"), $this
82                 }
83
84 > ikiwiki uses absolute paths for `srcdir`, `destdir` and `this` because
85 > the wrapper could be run from any location, and if any of them happen to
86 > be a relative path, it would crash and burn.
87
88 > I think the thing to do might be to make it check if `srcdir` and
89 > `destdir` look like an absolute path (ie, start with "/"). If so, it can
90 > skip running `abs_path` on them.
91
92 > I suppose you could do the same thing with `$this`, but it does not sound
93 > like it has caused you problems anyway.
94 > --[[Joey]]