File: README.security

package info (click to toggle)
phpwiki 1.3.12p3-5etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 16,956 kB
  • ctags: 21,608
  • sloc: php: 82,335; xml: 3,840; sh: 1,522; sql: 1,198; perl: 625; makefile: 562; awk: 28
file content (231 lines) | stat: -rw-r--r-- 8,807 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
_I hate [WikiSpam|http://en.wikipedia.org/wiki/Wikispam]!_

Being technically minded and based in the Asia time zone while my
co-authors are mainly in Europe and some in the US, it became my
unofficial role to clean up the WikiSpam each day in a 1.2 based PhpWiki.
The WikiSpam that I see is mostly created during the evening in the US
time zone - which is the morning for me.

I started working on PhpWiki 1.3/1.4 with a view to upgrade our wiki,
implementing security to:
* let anyone view our work,
* let anyone register themselves as users,
* but require new users to be authorised before editing or creating pages.

While testing and fixing bugs, I discovered some interesting and useful
things about security in PhpWiki. I hope my knowledge will help others.
This is the recipe that I used. There are many variations that will work
just as well or even better for you. Note that for most of the actions,
you need to be logged into the wiki as an administrator.

!!!1 - Generic security setup.
For the configuration that I describe above, the following parameters
should be set in config/config.ini (and are further documented there).
This requires that you have read and write access to the filestore on the
webserver.
----
<pre>
; require the new login code - the default
;ENABLE_USER_NEW = true

; allow ACL based permissions on pages - the default
;ENABLE_PAGEPERM = true

; allow unknown/anonymous users to by default read the content
ALLOW_ANON_USER = true

; prevent unknown/anonymous users from editing/creating pages
ALLOW_ANON_EDIT = false

; prevent users just creating a temporary user
; (I am skating over the complexities of this setting)
ALLOW_BOGO_LOGIN = false

; to require users to have passwords
; (this is not independent of the other settings above)
ALLOW_USER_PASSWORDS = true

; require passwords to have a minimum length
; I am not trying to protect national security,
; just encourage the vandals to go elsewhere
PASSWORD_LENGTH_MINIMUM = 6

; use a database to check user-ids and passwords.
; Note that there many other settings database settings that
; need careful attention but that is out of scope for this HOW-TO
USER_AUTH_ORDER = "Db"
USER_AUTH_POLICY = first-only

; Store group information in wiki pages
; theres no need to develop a complex front end for a database.
; Note that in performance terms this is the most expensive option.
GROUP_METHOD = WIKIPAGE

; the master page listing the groups - I just used the default
; CATEGORY_GROUP_PAGE = ~CategoryGroup

; The following SQL queries/statements are stored in
; config/config.ini so that they can easily be changed
; if there an existing user database. Several of these have
; alternatives documented in config/config.ini
DBAUTH_AUTH_USER_EXISTS = "SELECT userid FROM user WHERE userid="$userid""
DBAUTH_AUTH_CHECK = "SELECT IF(passwd=PASSWORD("$password"),1,0) AS ok
FROM user WHERE userid="$userid""
DBAUTH_AUTH_CRYPT_METHOD = plain
DBAUTH_AUTH_UPDATE = "UPDATE user SET passwd=PASSWORD("$password") WHERE
userid="$userid""
DBAUTH_AUTH_CREATE = "INSERT INTO user SET
passwd=PASSWORD("$password"),userid="$userid""
DBAUTH_PREF_SELECT = "SELECT prefs FROM pref WHERE userid="$userid""
DBAUTH_PREF_UPDATE = "REPLACE INTO pref SET
prefs="$pref_blob",userid="$userid""

; I am paranoid about undiscovered cross-site scripting
; vulnerabilities so I prevent users injecting HTML directly into
; pages. It may be safe to allow the latter 2 options
ENABLE_RAW_HTML = false
ENABLE_RAW_HTML_LOCKEDONLY = false
ENABLE_RAW_HTML_SAFE = false
</pre>
----

!!!2 - User Group management
Create group pages in the wiki.
*First, in page CategoryGroup, add the name of the group in the bulleted
list.  This may either be a WikiWord or enclosed in "~[" and "~]" and
there must be nothing else on the line. For example, while editing
CategoryGroup, add
<pre>* ~[Writers]
* ~UserManagement
</pre>
  and save. I will use these two groups as examples.

* Create the two group pages by clicking on the links in the CategoryGroup
page and add the list of users as a bulleted list (as above).
  - In the Writers group, list the users that are allowed to edit and
create pages.
  - In the UserManagement group, list the users that may authorise new
users (or remove existing users).
  - A user may be a member of both groups and new users may be added at
any time.
* Lock all three pages CategoryGroup, Writers and UserManagement.
* Unlock all three pages. _I am not certain that these last two steps are
necessary but various comments around the documentation indicate that it
is and, anyway, it did no harm._

!!!3 - change the default page permissions.

Create a page named . to hold these default permissions. _Yes, named "."._

The recommended way to do this is to
* go your HomePage
* remove "HomePage" from the url and replace with the parameters
  "?pagename=.&action=create"
* enter some text like "This page holds the default ACLs for all pages"
  and save
* go your HomePage
* remove "HomePage" from the url and replace with the parameters
  "?pagename=.&action=setacl"
* change the ACLs for EDIT and for CREATE to
  - +Administrators
  - +Owner
  - +Writers
  - -Authenticated Users
  - -Signed Users
  - -Bogo Users
* _Where + means the ACL allows that kind of access and  means the ACL
  does not allow that kind of access._
* change the ACLs for CHANGE and REMOVE to
  - +Administrators
  - +Owner
  - -Authenticated Users
  - -Signed Users
  - -Bogo Users

!3a Alternative method to create page "." and set the ACLs correctly.
I found some problems in the SetACL user interface (that I have not yet looked
into / fixed), so I used an alternative mechanism to set the ACLs.
* export a Zip Dump (via the PhpWikiAdministration page)
* extract one of the files from this zip - initially, it might look like
----
<pre>Subject: ~AppendText
From: foo@bar (~PhpWiki)
To: foo@bar (~PhpWiki)
Date: Wed, 5 Jan 2005 17:09:46 +0800
Mime-Version: 1.0 (Produced by ~PhpWiki 1.3.11pre-20050108)
Content-Type: application/x-phpwiki;
  pagename=~AppendText;
  flags="";
  author=The%20PhpWiki%20programming%20team;
  version=1;
  lastmodified=1104916186;
  created=1104916186;
  author_id=The%20PhpWiki%20programming%20team;
  markup=2;
  charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

~<?plugin ~AppendText ?>
</pre>
----
* rename and edit this file (I called it "dot" but this does not matter).
The contents should look something like
----
<pre>Subject: .
From: foo@bar (~PhpWiki)
To: foo@bar (~PhpWiki)
Date: Mon, 17 Jan 2005 15:54:59 +0800
Mime-Version: 1.0 (Produced by ~PhpWiki 1.3.11pre-20050108)
Content-Type: application/x-phpwiki;
  pagename=.;
  flags="";
  author=Admin;
  version=1;
  lastmodified=1105949000;
  created=1105949000;
  author_id=Admin;
  markup=2;
  acl="view:_EVERY;
edit:_ADMIN,_OWNER,Writers,-_SIGNED-_BOGOUSER,-_AUTHENTICATED;
create:_ADMIN,_OWNER,Writers,-_SIGNED,-_BOGOUSER,-_AUTHENTICATED;
list:_EVERY; remove:_ADMIN,_OWNER,-_SIGNED,-_BOGOUSER,-_AUTHENTICATED;
change:_ADMIN,_OWNER,-_SIGNED,-_BOGOUSER,-_AUTHENTICATED; dump:_EVERY";
  charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

This page holds the default permissions for all pages
</pre>
----
* The author and author_id should be the name of the administrator account.
* The important line is the one starting "  acl=". This lists the
groups/login types allowed to perform various actions on a page.
  - Names starting with an _ and all in capitals ("_ADMIN","_OWNER" etc.)
are built-in PhpWiki groups.
  - A - in front of the name means that that group is not allowed perform
an action, so "edit:-_AUTHENTICATED" means that a user that has logged
in is not allowed edit a page (unless they are also a member of another
group that is allowed).
* The example acl= line above implements the policy that I described near
the start of this page.
* Load the file back into the database through the PhpWikiAdministration
page.
* Check the permissions are what you need in PhpWikiAdministration/SetAcl
- this can be done on any page, not just on the "." page. _Use the setacl
button to see the permissions on a page._

* If you have to alter the ACL, I suggest that you bump the values for
version, lastmodified and created before reloading (I found problems
removing groups in the UI, so use the dump page, manual edit and reload
page mechanism documented above).

* Set any additional/specific restrictions on an individual page by page
basis.
* In particular, to have a limited list of users that can manage adding
and removing users from the Writers group, you should
  - on pages Writers, UserManagement, CategoryGroup and CategoryCategory
  - add UserManagement to edit and create permissions
  - remove Writers from edit and create permissions

* Test the permissions work as expected.

--PhpWiki:CharlesCorrigan