]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - doc/README.security
Remove ENABLE_USER_NEW (always true), remove lib/WikiUser.php
[SourceForge/phpwiki.git] / doc / README.security
1 _I hate [WikiSpam|http://en.wikipedia.org/wiki/Wikispam]!_
2
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.
8
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.
14
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.
20
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
25 webserver.
26 ----
27 <pre>
28 ; allow ACL based permissions on pages - the default
29 ;ENABLE_PAGEPERM = true
30
31 ; allow unknown/anonymous users to by default read the content
32 ALLOW_ANON_USER = true
33
34 ; prevent unknown/anonymous users from editing/creating pages
35 ALLOW_ANON_EDIT = false
36
37 ; prevent users just creating a temporary user
38 ; (I am skating over the complexities of this setting)
39 ALLOW_BOGO_LOGIN = false
40
41 ; to require users to have passwords
42 ; (this is not independent of the other settings above)
43 ALLOW_USER_PASSWORDS = true
44
45 ; require passwords to have a minimum length
46 ; I am not trying to protect national security,
47 ; just encourage the vandals to go elsewhere
48 PASSWORD_LENGTH_MINIMUM = 6
49
50 ; use a database to check user-ids and passwords.
51 ; Note that there many other settings database settings that
52 ; need careful attention but that is out of scope for this HOW-TO
53 USER_AUTH_ORDER = "Db"
54 USER_AUTH_POLICY = first-only
55
56 ; Store group information in wiki pages
57 ; there's no need to develop a complex front end for a database.
58 ; Note that in performance terms this is the most expensive option.
59 GROUP_METHOD = WIKIPAGE
60
61 ; the master page listing the groups - I just used the default
62 ; CATEGORY_GROUP_PAGE = ~CategoryGroup
63
64 ; The following SQL queries/statements are stored in
65 ; config/config.ini so that they can easily be changed
66 ; if there an existing user database. Several of these have
67 ; alternatives documented in config/config.ini
68 DBAUTH_AUTH_USER_EXISTS = "SELECT userid FROM user WHERE userid="$userid""
69 DBAUTH_AUTH_CHECK = "SELECT IF(passwd=PASSWORD("$password"),1,0) AS ok
70 FROM user WHERE userid="$userid""
71 DBAUTH_AUTH_CRYPT_METHOD = plain
72 DBAUTH_AUTH_UPDATE = "UPDATE user SET passwd=PASSWORD("$password") WHERE
73 userid="$userid""
74 DBAUTH_AUTH_CREATE = "INSERT INTO user SET
75 passwd=PASSWORD("$password"),userid="$userid""
76 DBAUTH_PREF_SELECT = "SELECT prefs FROM pref WHERE userid="$userid""
77 DBAUTH_PREF_UPDATE = "REPLACE INTO pref SET
78 prefs="$pref_blob",userid="$userid""
79
80 ; I am paranoid about undiscovered cross-site scripting
81 ; vulnerabilities so I prevent users injecting HTML directly into
82 ; pages. It may be safe to allow the latter 2 options
83 ENABLE_RAW_HTML = false
84 ENABLE_RAW_HTML_LOCKEDONLY = false
85 ENABLE_RAW_HTML_SAFE = false
86 </pre>
87 ----
88
89 !!!2 - User Group management
90 Create group pages in the wiki.
91 *First, in page CategoryGroup, add the name of the group in the bulleted
92 list.  This may either be a WikiWord or enclosed in "~[" and "~]" and
93 there must be nothing else on the line. For example, while editing
94 CategoryGroup, add
95 <pre>* ~[Writers]
96 * ~UserManagement
97 </pre>
98   and save. I will use these two groups as examples.
99
100 * Create the two group pages by clicking on the links in the CategoryGroup
101 page and add the list of users as a bulleted list (as above).
102   - In the Writers group, list the users that are allowed to edit and
103 create pages.
104   - In the UserManagement group, list the users that may authorise new
105 users (or remove existing users).
106   - A user may be a member of both groups and new users may be added at
107 any time.
108 * Lock all three pages CategoryGroup, Writers and UserManagement.
109 * Unlock all three pages. _I am not certain that these last two steps are
110 necessary but various comments around the documentation indicate that it
111 is and, anyway, it did no harm._
112
113 !!!3 - change the default page permissions.
114
115 Create a page named . to hold these default permissions. _Yes, named "."._
116
117 The recommended way to do this is to
118 * go your HomePage
119 * remove "HomePage" from the url and replace with the parameters
120   "?pagename=.&action=create"
121 * enter some text like "This page holds the default ACLs for all pages"
122   and save
123 * go your HomePage
124 * remove "HomePage" from the url and replace with the parameters
125   "?pagename=.&action=setacl"
126 * change the ACLs for EDIT and for CREATE to
127   - +Administrators
128   - +Owner
129   - +Writers
130   - -Authenticated Users
131   - -Signed Users
132   - -Bogo Users
133 * _Where + means the ACL allows that kind of access and x means the ACL
134   does not allow that kind of access._
135 * change the ACLs for CHANGE and REMOVE to
136   - +Administrators
137   - +Owner
138   - -Authenticated Users
139   - -Signed Users
140   - -Bogo Users
141
142 !3a Alternative method to create page "." and set the ACLs correctly.
143 I found some problems in the SetACL user interface (that I have not yet looked
144 into / fixed), so I used an alternative mechanism to set the ACLs.
145 * export a Zip Dump (via the PhpWikiAdministration page)
146 * extract one of the files from this zip - initially, it might look like
147 ----
148 <pre>Subject: ~AppendText
149 From: foo@bar (~PhpWiki)
150 To: foo@bar (~PhpWiki)
151 Date: Wed, 5 Jan 2005 17:09:46 +0800
152 Mime-Version: 1.0 (Produced by ~PhpWiki 1.3.11pre-20050108)
153 Content-Type: application/x-phpwiki;
154   pagename=~AppendText;
155   flags="";
156   author=The%20PhpWiki%20programming%20team;
157   version=1;
158   lastmodified=1104916186;
159   created=1104916186;
160   author_id=The%20PhpWiki%20programming%20team;
161   markup=2;
162   charset=UTF-8
163 Content-Transfer-Encoding: quoted-printable
164
165 ~<?plugin ~AppendText ?>
166 </pre>
167 ----
168 * rename and edit this file (I called it "dot" but this does not matter).
169 The contents should look something like
170 ----
171 <pre>Subject: .
172 From: foo@bar (~PhpWiki)
173 To: foo@bar (~PhpWiki)
174 Date: Mon, 17 Jan 2005 15:54:59 +0800
175 Mime-Version: 1.0 (Produced by ~PhpWiki 1.3.11pre-20050108)
176 Content-Type: application/x-phpwiki;
177   pagename=.;
178   flags="";
179   author=Admin;
180   version=1;
181   lastmodified=1105949000;
182   created=1105949000;
183   author_id=Admin;
184   markup=2;
185   acl="view:_EVERY;
186 edit:_ADMIN,_OWNER,Writers,-_SIGNED-_BOGOUSER,-_AUTHENTICATED;
187 create:_ADMIN,_OWNER,Writers,-_SIGNED,-_BOGOUSER,-_AUTHENTICATED;
188 list:_EVERY; remove:_ADMIN,_OWNER,-_SIGNED,-_BOGOUSER,-_AUTHENTICATED;
189 change:_ADMIN,_OWNER,-_SIGNED,-_BOGOUSER,-_AUTHENTICATED; dump:_EVERY";
190   charset=UTF-8
191 Content-Transfer-Encoding: quoted-printable
192
193 This page holds the default permissions for all pages
194 </pre>
195 ----
196 * The author and author_id should be the name of the administrator account.
197 * The important line is the one starting "  acl=". This lists the
198 groups/login types allowed to perform various actions on a page.
199   - Names starting with an _ and all in capitals ("_ADMIN","_OWNER" etc.)
200 are built-in PhpWiki groups.
201   - A - in front of the name means that that group is not allowed perform
202 an action, so "edit:-_AUTHENTICATED" means that a user that has logged
203 in is not allowed edit a page (unless they are also a member of another
204 group that is allowed).
205 * The example acl= line above implements the policy that I described near
206 the start of this page.
207 * Load the file back into the database through the PhpWikiAdministration
208 page.
209 * Check the permissions are what you need in PhpWikiAdministration/SetAcl
210 - this can be done on any page, not just on the "." page. _Use the setacl
211 button to see the permissions on a page._
212
213 * If you have to alter the ACL, I suggest that you bump the values for
214 version, lastmodified and created before reloading (I found problems
215 removing groups in the UI, so use the dump page, manual edit and reload
216 page mechanism documented above).
217
218 * Set any additional/specific restrictions on an individual page by page
219 basis.
220 * In particular, to have a limited list of users that can manage adding
221 and removing users from the Writers group, you should
222   - on pages Writers, UserManagement, CategoryGroup and CategoryCategory
223   - add UserManagement to edit and create permissions
224   - remove Writers from edit and create permissions
225
226 * Test the permissions work as expected.
227
228 --PhpWiki:CharlesCorrigan