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.
3 I think there are two issues here:
5 - Symlinks with the source dir path itself, and
6 - Symlinks inside the source directory.
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.
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]]
20 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.
22 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.
24 > BTW, if you have a problem, please file it in [[todo]] or [[bugs]] in the
25 > future. Especially if you also have a patch. :-) --[[Joey]]
27 >> Well, I was unsure I wasn't missing something. I wanted to discuss the concept of the patch as much as submit the patch. But, ok :)
29 Is there a huge objection to this patch?
31 (note: patch inline - look at the source to get it. And I didn't re-indent the code when I added the if...)
33 index 990fcaa..d7cb37e 100644
34 --- a/IkiWiki/Render.pm
35 +++ b/IkiWiki/Render.pm
36 @@ -260,6 +260,7 @@ sub prune ($) { #{{{
39 # security check, avoid following symlinks in the srcdir path
40 + if (! $config{allowsrcdirlinks}) {
41 my $test=$config{srcdir};
42 while (length $test) {
44 @@ -269,6 +270,7 @@ sub refresh () { #{{{
50 run_hooks(refresh => sub { shift->() });
52 > No, I don't have a big objection to such an option, as long as it's
53 > extremely well documented that it will make many setups insecure.
54 > It would be nice to come up with an option name that makes clear that
55 > it's allowing symlinks in the path to the `srcdir`, but still not inside
59 >> Ok, I'll try to get it cleaned up and documented.
61 There is a second location where this can be an issue. That is in the
62 front of the wrapper. There the issue is that the path to the source dir
63 as seen on the cgi server and on the git server are different - each has
64 symlinks in place to support the other. The current wrapper gets the
65 absolute path to the source dir, and that breaks things for me. This is a
66 slightly different, albeit related, issue to the one above. The following
67 patch fixes things. Again, patch inline. Again, this patch could be
68 cleaned up :). I just wanted to see if there was any chance of a patch
69 like this being accepted before I bothered.
73 index 79b9eb3..ce1c395 100644
74 --- a/IkiWiki/Wrapper.pm
75 +++ b/IkiWiki/Wrapper.pm
76 @@ -4,14 +4,14 @@ package IkiWiki;
85 sub gen_wrapper () { #{{{
86 - $config{srcdir}=abs_path($config{srcdir});
87 - $config{destdir}=abs_path($config{destdir});
88 - my $this=abs_path($0);
89 + $config{srcdir}=File::Spec->rel2abs($config{srcdir});
90 + $config{destdir}=File::Spec->rel2abs($config{destdir});
91 + my $this=File::Spec->rel2abs($0);
93 error(sprintf(gettext("%s doesn't seem to be executable"), $this
96 > ikiwiki uses absolute paths for `srcdir`, `destdir` and `this` because
97 > the wrapper could be run from any location, and if any of them happen to
98 > be a relative path, it would crash and burn.
100 >> Which makes perfect sense. It is annoying that abs_path() is also
101 >> expanding symlinks.
103 > I think the thing to do might be to make it check if `srcdir` and
104 > `destdir` look like an absolute path (ie, start with "/"). If so, it can
105 > skip running `abs_path` on them.
107 >> I'll do that. I assume something like <code> File::Spec->file_name_is_absolute( $path ); </code> would have more cross-platformy goodness.
108 >> hrm. I might see if <code> File::Spec->rel2abs( $path ) ; </code> will give absolute an path without expanding symlinks.
109 >>> Patch using rel2abs() works well - it no longer expands symlinks.
111 > I suppose you could do the same thing with `$this`, but it does not sound
112 > like it has caused you problems anyway.