{"id":602,"date":"2009-06-26T21:12:38","date_gmt":"2009-06-26T20:12:38","guid":{"rendered":"http:\/\/t-machine.org\/?p=602"},"modified":"2009-06-26T21:56:33","modified_gmt":"2009-06-26T20:56:33","slug":"making-mediawiki-secure-and-fixing-some-config-annoyances","status":"publish","type":"post","link":"http:\/\/new.t-machine.org\/index.php\/2009\/06\/26\/making-mediawiki-secure-and-fixing-some-config-annoyances\/","title":{"rendered":"Making MediaWiki secure (and fixing some config annoyances)"},"content":{"rendered":"<p>(this assumes you are running Debian on your server; if not, I suggest you switch)<\/p>\n<p>Mediawiki. One of the world&#8217;s less secure wikis? Probably. I use and install it a lot, and it&#8217;s usually &#8220;the compromise wiki&#8221;: it&#8217;s weak at a lot of things, but it&#8217;s the &#8220;least worst overall&#8221; a lot of the time. Here&#8217;s my current standard fixes and tweaks.<\/p>\n<p><!--more--><br \/>\nStrange, given how many people use wikis as a collaboration tool, that Mediawiki doesn&#8217;t do basic security out of the box, and has no user-options to enable any of these:<\/p>\n<ul>\n<li>Prevent non-image uploads (i.e. viruses, rootkits, etc)\n<ul>\n<li>Actually, I don&#8217;t have a simple fix for that one yet; but with the site locked-down to only pre-authorized users, its not quite so scary\n<\/ul>\n<li>Require login to see the wiki content\n<li>Encrypt passwords when people login\n<li>Prevent anyone on planet from &#8220;giving themselves&#8221; user accounts\n<li>Basic upload \/ files \/ viruses security\n<\/ul>\n<p>By default (with no user-configurable settings for this) it also:<\/p>\n<ul>\n<li>Won&#8217;t let you upload most images (!)\n<li>Has a naive idea of what an &#8220;image file&#8221; is &#8230; based on filename(!)\n<li>Won&#8217;t let you edit the navigation bar\n<li>Won&#8217;t give you a link to &#8220;create new user&#8221; (even though it has this feature)\n<\/ul>\n<p>So, here&#8217;s my list of fixes that I have to re-apply manually every time I install mediawiki; I do this often enough that I&#8217;m blogging it so I can just copy\/paste them next time. This is tiresome; it would be nice if they just updated it to work like other webapps and have a &#8220;config&#8221; page &#8211; and even better if it did some of these by default or as options at install time.<\/p>\n<h4>1. Use your webserver<\/h4>\n<p>Assuming you use Apache (and if not, why not?), setup a virtual hosts file to force-redirect non-SSL traffic to an SSL version of the wiki domain. This *guarantees* that *all* wiki pages can&#8217;t be snooped off-the-wire, and has the benefit of preventing any cleartext sending of passwords.<\/p>\n<p>Downsides: er &#8230; only one I can think of off the top of my head is that the CPU usage \/ traffic will increase from using &#8220;always on&#8221; encryption. Shouldn&#8217;t even be noticeable on modern server hardware&#8230;<\/p>\n<blockquote>\n<pre><code>\r\n&lt;VirtualHost *:80&gt;\r\n        ServerName wiki.securedomain.com\r\n        ServerAdmin webmaster@localhost\r\n\r\n        Redirect permanent \/ https:\/\/wiki.securedomain.com\/\r\n&lt;\/VirtualHost&gt;\r\n&lt;VirtualHost *:443&gt;\r\n        ServerName wiki.securedomain.com\r\n        ServerAdmin webmaster@localhost\r\n\r\n        # only these two lines and the second in the file should differ\r\n        #   from the default site\r\n        SSLEngine on\r\n        SSLCertificateFile \/etc\/apache2\/ssl\/apache.pem\r\n\r\n        DocumentRoot \/var\/lib\/mediawiki\/\r\n        ServerSignature On\r\n\r\n&lt;\/VirtualHost&gt;\r\n<\/code>\r\n<\/pre>\n<\/blockquote>\n<h4>2. Change mediawiki configfile settings<\/h4>\n<p>You have to edit the config files manually on your webserver &#8211; if you don&#8217;t have access to your webserver files, you&#8217;re just screwed, sorry. Well, shell-access hosting is very cheap these days ($10 a month), shouldn&#8217;t be a problem&#8230;<\/p>\n<blockquote>\n<pre>\r\n## Adam's default settings for LocalSettings.php\r\n\r\n## *All* the following put together will prevent everyone on the web\r\n## reading your data without even logging in, but will also allow your\r\n## real users to login; don't miss any of these out, or you may be unable\r\n## to login\r\n$wgGroupPermissions['*']['edit'] = false;\r\n$wgWhitelistRead = array(\"Special:Userlogin\", \"-\", \"MediaWiki:Monobook.css\" );\r\n$wgGroupPermissions['*']['read'] = false;\r\n$wgGroupPermissions['*']['createaccount'] = false;\r\n\r\n## Basic obvious default: let users get rid of the ugly\r\n##  default GUI (sidebar, stylesheets, etc)\r\n$wgGroupPermissions['user']['editinterface'] = true;\r\n\r\n## Put uploads ... somewhere sensible:\r\n$wgUploadDirectory = \"{$IP}\/images\";\r\n$wgUploadPath = \"{$wgScriptPath}\/images\";\r\n\r\n## Ah, but they have a \"security\" system that will allow you to upload any\r\n## virus you want, and hack the server, BUT ... it won't let you upload most\r\n## image files. That's just ... stupid, IMHO.\r\n$wgStrictFileExtensions = false;\r\n\r\n## AND you can do this (note that it is STILL active even if the above flag\r\n## is set to false).\r\n## I was quite horrified that they use filename extensions as a security\r\n##\u00a0mechanism - this stops some kinds of simple attack (based on tricking\r\n## the webserver - although you SHOULD already have your webserver\r\n## setup to prevent this; if not, why not?)\r\n## For other attacks ... Mediawiki's approach to security\r\n## simply DOES NOT WORK. You *must* check the content\r\n##\u00a0of files, rather than the filename.\r\n$wgFileBlacklist = array('php','phtml','php3','php4','php5','phps');\r\n<\/pre>\n<\/blockquote>\n<h4>3. Setup each user by hand<\/h4>\n<p>To create new users, you now need to manually go to this URL on your wiki:<\/p>\n<blockquote><p>\n\/index.php\/Special:UserLogin\n<\/p><\/blockquote>\n<p>(assuming you installed the wiki on its own domain name)<\/p>\n<h4>4. Some final tweaks to add missing features<\/h4>\n<p>AND, if you want to edit the navbar, go to: (yes, this is required: go there by hand, with the following &#8220;special&#8221; URL. It&#8217;s a terrible user-interface :( )<\/p>\n<blockquote><p>\n\/index.php?title=MediaWiki:Sidebar&#038;action=edit\n<\/p><\/blockquote>\n<p>&#8230;but it gets worse, because that page alone uses a special syntax (not the Wiki syntax, sadly), so that adding either of the obvious misisng links is a bit of hassle. Here&#8217;s copy\/pasteable working code:<\/p>\n<blockquote><p>\n* essentials<br \/>\n** MediaWiki:Sidebar | edit-sidebar<br \/>\n** Special:UserLogin|create user\n<\/p><\/blockquote>\n<p>(note: they BOTH have a unique syntax due to the way mediawiki is badly designed, and the first one WILL BREAK if you use the text &#8220;sidebar&#8221; instead of &#8220;edit-sidebar&#8221; (use anything, just NOT &#8220;sidebar&#8221; on its own))<\/p>\n<p>More info:<br \/>\n<a href=\"http:\/\/www.mediawiki.org\/wiki\/Manual:Preventing_access\">http:\/\/www.mediawiki.org\/wiki\/Manual:Preventing_access<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>(this assumes you are running Debian on your server; if not, I suggest you switch) Mediawiki. One of the world&#8217;s less secure wikis? Probably. I use and install it a lot, and it&#8217;s usually &#8220;the compromise wiki&#8221;: it&#8217;s weak at a lot of things, but it&#8217;s the &#8220;least worst overall&#8221; a lot of the time. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,45],"tags":[],"_links":{"self":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/602"}],"collection":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/comments?post=602"}],"version-history":[{"count":0,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/602\/revisions"}],"wp:attachment":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/media?parent=602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/categories?post=602"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/tags?post=602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}