]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - doc/README.security
Allow bold, italics or underlined for numbers
[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 ; require the new login code - the default
29 ;ENABLE_USER_NEW = true
30
31 ; allow ACL based permissions on pages - the default
32 ;ENABLE_PAGEPERM = true
33
34 ; allow unknown/anonymous users to by default read the content
35 ALLOW_ANON_USER = true
36
37 ; prevent unknown/anonymous users from editing/creating pages
38 ALLOW_ANON_EDIT = false
39
40 ; prevent users just creating a temporary user
41 ; (I am skating over the complexities of this setting)
42 ALLOW_BOGO_LOGIN = false
43
44 ; to require users to have passwords
45 ; (this is not independent of the other settings above)
46 ALLOW_USER_PASSWORDS = true
47
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
52
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
58
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
63
64 ; the master page listing the groups - I just used the default
65 ; CATEGORY_GROUP_PAGE = ~CategoryGroup
66
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
76 userid="$userid""
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""
82
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
89 </pre>
90 ----
91
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
97 CategoryGroup, add
98 <pre>* ~[Writers]
99 * ~UserManagement
100 </pre>
101   and save. I will use these two groups as examples.
102
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
106 create pages.
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
110 any time.
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._
115
116 !!!3 - change the default page permissions.
117
118 Create a page named . to hold these default permissions. _Yes, named "."._
119
120 The recommended way to do this is to
121 * go your HomePage
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"
125   and save
126 * go your HomePage
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
130   - +Administrators
131   - +Owner
132   - +Writers
133   - -Authenticated Users
134   - -Signed Users
135   - -Bogo 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
139   - +Administrators
140   - +Owner
141   - -Authenticated Users
142   - -Signed Users
143   - -Bogo Users
144
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
150 ----
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;
158   flags="";
159   author=The%20PhpWiki%20programming%20team;
160   version=1;
161   lastmodified=1104916186;
162   created=1104916186;
163   author_id=The%20PhpWiki%20programming%20team;
164   markup=2;
165   charset=UTF-8
166 Content-Transfer-Encoding: quoted-printable
167
168 ~<?plugin ~AppendText ?>
169 </pre>
170 ----
171 * rename and edit this file (I called it "dot" but this does not matter).
172 The contents should look something like
173 ----
174 <pre>Subject: .
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;
180   pagename=.;
181   flags="";
182   author=Admin;
183   version=1;
184   lastmodified=1105949000;
185   created=1105949000;
186   author_id=Admin;
187   markup=2;
188   acl="view:_EVERY;
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";
193   charset=UTF-8
194 Content-Transfer-Encoding: quoted-printable
195
196 This page holds the default permissions for all pages
197 </pre>
198 ----
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
211 page.
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._
215
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).
220
221 * Set any additional/specific restrictions on an individual page by page
222 basis.
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
228
229 * Test the permissions work as expected.
230
231 --PhpWiki:CharlesCorrigan