1 _I hate [WikiSpam|http://en.wikipedia.org/wiki/Wikispam]!_
3 Being technically minded and based in the Asia time zone while my
4 co-authors are mainly in Europe and some in the US, it became my
5 unofficial role to clean up the WikiSpam each day in a 1.2 based PhpWiki.
6 The WikiSpam that I see is mostly created during the evening in the US
7 time zone - which is the morning for me.
9 I started working on PhpWiki 1.3/1.4 with a view to upgrade our wiki,
10 implementing security to:
11 * let anyone view our work,
12 * let anyone register themselves as users,
13 * but require new users to be authorised before editing or creating pages.
15 While testing and fixing bugs, I discovered some interesting and useful
16 things about security in PhpWiki. I hope my knowledge will help others.
17 This is the recipe that I used. There are many variations that will work
18 just as well or even better for you. Note that for most of the actions,
19 you need to be logged into the wiki as an administrator.
21 !!!1 - Generic security setup.
22 For the configuration that I describe above, the following parameters
23 should be set in config/config.ini (and are further documented there).
24 This requires that you have read and write access to the filestore on the
28 ; require the new login code - the default
29 ;ENABLE_USER_NEW = true
31 ; allow ACL based permissions on pages - the default
32 ;ENABLE_PAGEPERM = true
34 ; allow unknown/anonymous users to by default read the content
35 ALLOW_ANON_USER = true
37 ; prevent unknown/anonymous users from editing/creating pages
38 ALLOW_ANON_EDIT = false
40 ; prevent users just creating a temporary user
41 ; (I am skating over the complexities of this setting)
42 ALLOW_BOGO_LOGIN = false
44 ; to require users to have passwords
45 ; (this is not independent of the other settings above)
46 ALLOW_USER_PASSWORDS = true
48 ; require passwords to have a minimum length
49 ; I am not trying to protect national security,
50 ; just encourage the vandals to go elsewhere
51 PASSWORD_LENGTH_MINIMUM = 6
53 ; use a database to check user-ids and passwords.
54 ; Note that there many other settings database settings that
55 ; need careful attention but that is out of scope for this HOW-TO
56 USER_AUTH_ORDER = "Db"
57 USER_AUTH_POLICY = first-only
59 ; Store group information in wiki pages
60 ; there's no need to develop a complex front end for a database.
61 ; Note that in performance terms this is the most expensive option.
62 GROUP_METHOD = WIKIPAGE
64 ; the master page listing the groups - I just used the default
65 ; CATEGORY_GROUP_PAGE = ~CategoryGroup
67 ; The following SQL queries/statements are stored in
68 ; config/config.ini so that they can easily be changed
69 ; if there an existing user database. Several of these have
70 ; alternatives documented in config/config.ini
71 DBAUTH_AUTH_USER_EXISTS = "SELECT userid FROM user WHERE userid="$userid""
72 DBAUTH_AUTH_CHECK = "SELECT IF(passwd=PASSWORD("$password"),1,0) AS ok
73 FROM user WHERE userid="$userid""
74 DBAUTH_AUTH_CRYPT_METHOD = plain
75 DBAUTH_AUTH_UPDATE = "UPDATE user SET passwd=PASSWORD("$password") WHERE
77 DBAUTH_AUTH_CREATE = "INSERT INTO user SET
78 passwd=PASSWORD("$password"),userid="$userid""
79 DBAUTH_PREF_SELECT = "SELECT prefs FROM pref WHERE userid="$userid""
80 DBAUTH_PREF_UPDATE = "REPLACE INTO pref SET
81 prefs="$pref_blob",userid="$userid""
83 ; I am paranoid about undiscovered cross-site scripting
84 ; vulnerabilities so I prevent users injecting HTML directly into
85 ; pages. It may be safe to allow the latter 2 options
86 ENABLE_RAW_HTML = false
87 ENABLE_RAW_HTML_LOCKEDONLY = false
88 ENABLE_RAW_HTML_SAFE = false
92 !!!2 - User Group management
93 Create group pages in the wiki.
94 *First, in page CategoryGroup, add the name of the group in the bulleted
95 list. This may either be a WikiWord or enclosed in "~[" and "~]" and
96 there must be nothing else on the line. For example, while editing
101 and save. I will use these two groups as examples.
103 * Create the two group pages by clicking on the links in the CategoryGroup
104 page and add the list of users as a bulleted list (as above).
105 - In the Writers group, list the users that are allowed to edit and
107 - In the UserManagement group, list the users that may authorise new
108 users (or remove existing users).
109 - A user may be a member of both groups and new users may be added at
111 * Lock all three pages CategoryGroup, Writers and UserManagement.
112 * Unlock all three pages. _I am not certain that these last two steps are
113 necessary but various comments around the documentation indicate that it
114 is and, anyway, it did no harm._
116 !!!3 - change the default page permissions.
118 Create a page named . to hold these default permissions. _Yes, named "."._
120 The recommended way to do this is to
122 * remove "HomePage" from the url and replace with the parameters
123 "?pagename=.&action=create"
124 * enter some text like "This page holds the default ACLs for all pages"
127 * remove "HomePage" from the url and replace with the parameters
128 "?pagename=.&action=setacl"
129 * change the ACLs for EDIT and for CREATE to
133 - -Authenticated Users
136 * _Where + means the ACL allows that kind of access and x means the ACL
137 does not allow that kind of access._
138 * change the ACLs for CHANGE and REMOVE to
141 - -Authenticated Users
145 !3a Alternative method to create page "." and set the ACLs correctly.
146 I found some problems in the SetACL user interface (that I have not yet looked
147 into / fixed), so I used an alternative mechanism to set the ACLs.
148 * export a Zip Dump (via the PhpWikiAdministration page)
149 * extract one of the files from this zip - initially, it might look like
151 <pre>Subject: ~AppendText
152 From: foo@bar (~PhpWiki)
153 To: foo@bar (~PhpWiki)
154 Date: Wed, 5 Jan 2005 17:09:46 +0800
155 Mime-Version: 1.0 (Produced by ~PhpWiki 1.3.11pre-20050108)
156 Content-Type: application/x-phpwiki;
157 pagename=~AppendText;
159 author=The%20PhpWiki%20programming%20team;
161 lastmodified=1104916186;
163 author_id=The%20PhpWiki%20programming%20team;
166 Content-Transfer-Encoding: quoted-printable
168 ~<?plugin ~AppendText ?>
171 * rename and edit this file (I called it "dot" but this does not matter).
172 The contents should look something like
175 From: foo@bar (~PhpWiki)
176 To: foo@bar (~PhpWiki)
177 Date: Mon, 17 Jan 2005 15:54:59 +0800
178 Mime-Version: 1.0 (Produced by ~PhpWiki 1.3.11pre-20050108)
179 Content-Type: application/x-phpwiki;
184 lastmodified=1105949000;
189 edit:_ADMIN,_OWNER,Writers,-_SIGNED-_BOGOUSER,-_AUTHENTICATED;
190 create:_ADMIN,_OWNER,Writers,-_SIGNED,-_BOGOUSER,-_AUTHENTICATED;
191 list:_EVERY; remove:_ADMIN,_OWNER,-_SIGNED,-_BOGOUSER,-_AUTHENTICATED;
192 change:_ADMIN,_OWNER,-_SIGNED,-_BOGOUSER,-_AUTHENTICATED; dump:_EVERY";
194 Content-Transfer-Encoding: quoted-printable
196 This page holds the default permissions for all pages
199 * The author and author_id should be the name of the administrator account.
200 * The important line is the one starting " acl=". This lists the
201 groups/login types allowed to perform various actions on a page.
202 - Names starting with an _ and all in capitals ("_ADMIN","_OWNER" etc.)
203 are built-in PhpWiki groups.
204 - A - in front of the name means that that group is not allowed perform
205 an action, so "edit:-_AUTHENTICATED" means that a user that has logged
206 in is not allowed edit a page (unless they are also a member of another
207 group that is allowed).
208 * The example acl= line above implements the policy that I described near
209 the start of this page.
210 * Load the file back into the database through the PhpWikiAdministration
212 * Check the permissions are what you need in PhpWikiAdministration/SetAcl
213 - this can be done on any page, not just on the "." page. _Use the setacl
214 button to see the permissions on a page._
216 * If you have to alter the ACL, I suggest that you bump the values for
217 version, lastmodified and created before reloading (I found problems
218 removing groups in the UI, so use the dump page, manual edit and reload
219 page mechanism documented above).
221 * Set any additional/specific restrictions on an individual page by page
223 * In particular, to have a limited list of users that can manage adding
224 and removing users from the Writers group, you should
225 - on pages Writers, UserManagement, CategoryGroup and CategoryCategory
226 - add UserManagement to edit and create permissions
227 - remove Writers from edit and create permissions
229 * Test the permissions work as expected.
231 --PhpWiki:CharlesCorrigan