up
[ikiwiki.git] / doc / security.mdwn
1 Let's do an ikiwiki security analysis.. ok
2
3 If you are using ikiwiki to render pages that only you can edit, do not
4 generate any wrappers, and do not use the cgi, then there are no more
5 security issues with this program than with cat(1). If, however, you let
6 others edit pages in your wiki, then some possible security issues do need
7 to be kept in mind.
8
9 ## html attacks
10
11 ikiwiki does not attempt to do any santization of the html on the wiki.
12 MarkDown allows embedding of arbitrary html into a markdown document. If
13 you let anyone else edit files on the wiki, then anyone can have fun exploiting
14 the web browser bug of the day. This type of attack is typically referred
15 to as an XSS attack ([google](http://www.google.com/search?q=xss+attack)).
16
17 ## image files etc attacks
18
19 If it enounters a file type it does not understand, ikiwiki just copies it
20 into place. So if you let users add any kind of file they like, they can
21 upload images, movies, windows executables, etc. If these files exploit
22 security holes in the browser of someone who's viewing the wiki, that can
23 be a security problem.
24
25 ## exploting ikiwiki with bad content
26
27 Someone could add bad content to the wiki and hope to exploit ikiwiki.
28 Note that ikiwiki runs with perl taint checks on, so this is unlikely;
29 the only data that is not subject to full taint checking is the names of
30 files, and filenames are sanitised.
31
32 ## cgi scripts
33
34 ikiwiki does not allow cgi scripts to be published as part of the wiki. Or
35 rather, the script is published, but it's not marked executable, so
36 hopefully your web server will not run it.
37
38 ## web server attacks
39
40 If your web server does any parsing of special sorts of files (for example,
41 server parsed html files), then if you let anyone else add files to the wiki,
42 they can try to use this to exploit your web server.
43
44 ## --gen-wrapper might generate insecure wrappers
45
46 ikiwiki --gen-wrapper is intended to generate a wrapper program that
47 runs ikiwiki to update a given wiki. The wrapper can in turn be made suid,
48 for example to be used in a [[post-commit]] hook by people who cannot write
49 to the html pages, etc.
50
51 If the wrapper script is made suid, then any bugs in this wrapper would be
52 security holes. The wrapper is written as securely as I know how and
53 there's been no problem yet.
54
55 ## symlink attacks
56
57 Could a committer trick ikiwiki into following a symlink and operating on
58 some other tree that it shouldn't? svn supports symlinks, so one can get
59 into the repo. ikiwiki uses File::Find to traverse the repo, and does not
60 tell it to follow symlinks, but it might be possible to race replacing a
61 directory with a symlink and trick it into following.
62
63 It would certianly be possible to start out with a directory, let ikiwiki
64 run and find a file in there, then replace it with a symlink, and ikiwiki
65 would then go ahead and follow the symlink when it went to open that file
66 to read it. If it was some private file and was running suid, that could be
67 bad.
68
69 TODO: seems that locking to prevent more than one ikiwiki run at a time
70 would both fix this and is a good idea in general. With locking, an
71 attacker couldn't get ikiwiki to svn up while another instance was running.
72
73 Even with locking, if an attacker has local write access to the checkout,
74 they could still fool ikiwiki using similar races. So it's best if only one
75 person can ever write to the checkout that ikiwiki compiles the moo from.
76
77 ## cgi security
78
79 When ikiwiki runs as a cgi to edit a page, it is passed the name of the
80 page to edit. It has to make sure to sanitise this page, to prevent eg,
81 editing of ../../../foo, or editing of files that are not part of the wiki,
82 such as subversion dotfiles. This is done by sanitising the filename
83 removing unallowed characters, then making sure it doesn't start with "/"
84 or contain ".." or "/.svn/". Annoyingly ad-hoc, this kind of code is where
85 security holes breed.