Skip to content

Commit 529a5de

Browse files
JeroenDeDauwclaude
andcommitted
Give members opaque usernames
Member accounts were named after the address they were admitted with, so every enumeration defence in this extension worked around that name, and each release found another place where MediaWiki prints one. Members now get an opaque name: `Member` plus six characters drawn with `random_int` from a 32-symbol alphabet, checked for availability against the primary database rather than a replica, and redrawn on a collision. Names are never reused, since a removed member's account stays. The address lives only in the account's confirmed email and in the roster, which is already how the extension looks members up: a code login for a known address lands in the account the roster names, and an address the roster has never seen gets an account of its own. Where to look hardest: `MediaWikiUsernameMinter` (the primary read and the retry), the two wrappers in `RegistrationHandler::nameTheMembersSingleSignOnAdmits()`, the shape check in `SsoAuthorizationHandler::admitANewAccount()`, and the two selections in `OpaqueNameUpdate`. ### Single sign-on The PluggableAuth plugin settles on the username before this extension is consulted. OpenIDConnect gives a say over both the address and the name, in that order within one login: the extension wraps `OpenIDConnect_EmailProcessor` to learn the address the plugin resolved — not always in the token payload a processor is handed, since the plugin falls back to the userinfo endpoint — and `OpenIDConnect_PreferredUsernameProcessor` to mint an opaque name when the allowlist admits that address. Processors the wiki configured itself run first and are kept; a login the allowlist does not admit keeps the plugin's name. Other plugins offer no such hook, so a new allowlisted login arriving through one is refused rather than provisioned under an identifying name: the member sees PluggableAuth's authorization-failed page and the `MemberAccess` log channel says why. Members who already have an account are admitted by the roster as before, whatever the plugin. Holding single sign-on to the allowlist therefore requires OpenIDConnect; the README states this under platform requirements, with the settings that bypass the hook (`UseRandomUsernames`, a per-provider processor, `MigrateUsersByUserName`). `MigrateUsersByEmail` does not bypass it — it attaches the login to an existing account, which the roster then judges — and is what joins the code-route account and the single sign-on login of one address. ### Removed The `@` in `$wgInvalidUsernameCharacters`, the `$wgUserrightsInterwikiDelimiter` flip, and the rename step of member removal — removal is now: forget the roster row, invalidate the address, invalidate the sessions. `RemovalResult::ReservedNameTaken`, `RemovalFailed` and the `reserved_name_taken` and `removal_failed` REST error codes went with it; the admin panel, their only consumer, no longer receives them. ### Kept as defence in depth The reader-group revocations and provenance rule, the password veto and password-reset filtering, the blocked special pages and API modules, and the `newusers`, `block` and `renameuser` log restrictions — the last because the migration renames through `RenameuserSQL`, whose log entry names the old username. ### Migration A `LoadExtensionSchemaUpdates` callback, run by every `update.php`, renames roster members whose name the extension did not mint (single sign-on members carry their provider's name, with no `@` in it) and reader-group accounts with no roster row whose name holds an `@`; a reader-group account with neither is left alone, since a wiki may point the group at one it already had. Members cannot edit, so the rename touches the account, its actor row, its log entries and any block on it; the old name survives only in the restricted rename log, and nothing reverses it. It runs as a `MemberAccess` system user, taking over an existing account of that name and reserving it from then on; it logs by user id, and on failure by exception class alone, since a database error message carries the statement and with it the name. A second run finds nothing. `User:` pages keep their old titles and core logs both names at debug level; the README's `update.php` paragraph says both. ### Verification 846 tests, up from 763 on master; phpcs and phpstan clean; every new test seen failing against a mutation of the code it covers. Browser-verified on MediaWiki 1.43: a first login minted `Member LWDOHG` with the address confirmed and the reader group, the same address returned to that account, `update.php` renamed two legacy accounts keeping address, confirmation and group, and `Special:ListUsers` stayed refused. ### Known limitation `memberaccess_member.mam_email` has no unique index. Two first logins for one address in flight — two browser tabs — each get an account and a roster row, as does an address admitted by code that later arrives by single sign-on without `MigrateUsersByEmail`. The index alone would leave the losing account roster-less and refused at every later login; fixing it also needs the `ignore()` dropped from the roster insert and a dedupe step in the updater. Also omitted: a configurable name prefix, forcing `MigrateUsersByUserName` off from code, and moving `User:` pages in the migration. ### Related Follows-up to #23 and #25. #22, #24 and #26 each close one place that prints a username; with an opaque name they become defence in depth rather than the only defence, so none is closed by this. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent d05e3ee commit 529a5de

42 files changed

Lines changed: 2295 additions & 579 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 75 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ admitted by an allowlist of addresses and domains organized into named groups.
1414
the scenes is revoked.
1515
* Accounts create themselves at first login. Removing an allowlist entry ends access at the next
1616
login; deactivating a member blocks them at once.
17-
* Single sign-on logins through [PluggableAuth] can be held to the same allowlist; staff accounts
17+
* Single sign-on logins through [OpenIDConnect] can be held to the same allowlist; staff accounts
1818
are exempt.
19-
* Nothing gives the member list away: code and password-reset requests answer the same for every
20-
address, and account listings and the logs that record members are restricted.
19+
* Nothing gives the member list away: a member's account is named after nobody, code and
20+
password-reset requests answer the same for every address, and account listings and the logs that
21+
record members are restricted.
2122
* Groups, allowlist entries and the member roster are managed over a REST API.
2223
* It does not make the wiki private: restricting who may read stays a wiki configuration decision.
2324

@@ -52,17 +53,21 @@ can ask for another code, which replaces the one before it, or go back and enter
5253
address. Asking for another is counted by the same rate limits as asking for the first; once they
5354
are spent the offer is withdrawn, and the code already sent goes on working.
5455

55-
Entering the right code logs the visitor in, and the first time also creates their account: the
56-
username is their email address, they are placed in the reader group, and the address is recorded as
57-
confirmed. The allowlist is consulted again at that point, so removing an entry ends access at the
58-
next login. A code never opens an account that was created some other way.
56+
Entering the right code logs the visitor in, and the first time also creates their account: it is
57+
named after nobody, placed in the reader group, and the address is recorded as confirmed. The
58+
allowlist is consulted again at that point, so removing an entry ends access at the next login. A
59+
code never opens an account that was created some other way.
5960

6061
### Usernames
6162

62-
The username is the address lowercased and then put through MediaWiki's username rules: the first
63-
letter is capitalized and underscores become spaces, so `John_Doe@Example.com` logs in as
64-
`John doe@example.com`. Addresses that cannot become a username, and addresses whose username is
65-
already taken by an account that is not that member, are refused.
63+
A member's account is named `Member` and six characters drawn at random, `Member A7K2M4` for
64+
instance, which says nothing about who holds it. Everywhere MediaWiki names an account is a place a
65+
member could be recognised, which a name that identifies nobody makes harmless.
66+
67+
The address is on the account as its confirmed email and in the roster, which is what joins an
68+
address to an account: a code login goes to the account the roster names for that address. Nothing
69+
about the address constrains the name, so an address that could never have been a username is
70+
admitted like any other.
6671

6772
### Passwords
6873

@@ -79,10 +84,18 @@ address checked is the one recorded when they were admitted, so removing their e
7984
too. Accounts that are not members are exempt, so staff signing in through the identity provider are
8085
unaffected; when such a login uses an address the allowlist would not admit, it is written to the log
8186
channel. An account that carries the reader group without being on the roster is no staff account
82-
but a forgotten member account — a removed member's parked account, or one left behind by a failed
87+
but a forgotten member account — a removed member's closed account, or one left behind by a failed
8388
provisioning — and is refused rather than exempted. A refusal is final: no other handler of the same
8489
hook can hand the login back. Without PluggableAuth the check never runs.
8590

91+
The account is created by the identity provider's plugin, which settles on its name before the
92+
extension is asked anything. [OpenIDConnect] offers a say over that name, which the extension takes
93+
for the logins the allowlist admits, so that a member is named after nobody here as well. A
94+
processor the wiki configured itself is kept and runs first, and decides the name of every login
95+
that is not a member's. A plugin offering no such say would name the account itself, so a login the
96+
allowlist admits arriving through one is refused, and the refusal is written to the log channel.
97+
Holding single sign-on to the allowlist therefore works with OpenIDConnect and no other plugin.
98+
8699
### Deactivation and removal
87100

88101
Deactivating a member blocks their account sitewide and indefinitely; removing their allowlist entry
@@ -95,13 +108,12 @@ A block placed by hand, for some other reason, is neither replaced when the memb
95108
nor lifted when they are reactivated. Deactivating is refused while such a block would not keep the
96109
member out by itself, because it runs out or is only partial.
97110

98-
Removing a member makes the roster forget them and renames their account to
99-
`Removed member <userId>`, so their address is free again and reaches a new account at the next
100-
code login. The rename ends the account's open sessions, but not the member's admission: the
101-
allowlist entry that admits them stays, and a deactivation block stays behind on the renamed
102-
account rather than reaching the new one. An identity provider that recorded the account still
103-
points at the parked one, so a removed member's single sign-on logins arrive there and are refused
104-
rather than reaching a fresh account.
111+
Removing a member makes the roster forget them and closes their account: the address goes off it
112+
and the open sessions with it, so their address is free again and reaches a new account at the next
113+
code login. What is removed is the member, not their admission: the allowlist entry that admits
114+
them stays, and a deactivation block stays behind on the closed account rather than reaching the new
115+
one. An identity provider that recorded the account still points at the closed one, so a removed
116+
member's single sign-on logins arrive there and are refused rather than reaching a fresh account.
105117

106118
### Rate limits and logging
107119

@@ -112,15 +124,15 @@ address hashed.
112124

113125
### The roster
114126

115-
A member's username is their email address, so anything that names accounts names the roster. The
116-
action API query modules whose purpose is enumerating accounts are closed to the reader group, and
117-
three logs are closed to anyone who cannot manage members: the new user log, where every member's
118-
account creation is recorded, the block log, where every deactivation is, and the rename log, which
119-
names what a removed member was called. Restricting a log type also keeps it out of recent changes.
120-
The special pages that list or resolve accounts are closed to the reader group as well, and
121-
transcluding `Special:ListUsers` renders it empty for everyone, since what a transclusion renders
122-
is not kept to the reader who asked for it. `Special:Redirect` is closed whole, so members lose its
123-
other lookups too, and `Special:FilePath`, which redirects through it.
127+
A member's name gives nothing away, so what is left to keep is that they exist at all. The action
128+
API query modules whose purpose is enumerating accounts are closed to the reader group, and three
129+
logs are closed to anyone who cannot manage members: the new user log, where every member's account
130+
creation is recorded, the block log, where every deactivation is, and the rename log, which holds
131+
what members were called before the update that gave them opaque names. Restricting a log type also
132+
keeps it out of recent changes. The special pages that list or resolve accounts are closed to the
133+
reader group as well, and transcluding `Special:ListUsers` renders it empty for everyone, since what
134+
a transclusion renders is not kept to the reader who asked for it. `Special:Redirect` is closed
135+
whole, so members lose its other lookups too, and `Special:FilePath`, which redirects through it.
124136

125137
Page histories and recent changes still name whoever acted, which on a members-only wiki means the
126138
staff who edit: members cannot appear there, since they cannot change anything.
@@ -173,19 +185,25 @@ Whatever the login routes are set to, loading the extension:
173185
information or preferences, which closes `Special:ChangeEmail` to them;
174186
* sets `$wgBlockDisablesLogin`, so blocking a member keeps them out of a private wiki;
175187
* restricts the `newusers`, `block` and `renameuser` logs to the `memberaccess-manage` right, unless
176-
the wiki already restricted them;
188+
the wiki already restricted them, so that who joined, who was deactivated, and what members were
189+
called before the update renamed them stay out of view;
190+
* reserves the username `MemberAccess`, which the update that renames members records its renames as,
191+
so that no real account can be there for it to take over;
177192
* refuses members a password, whatever the routes: setting one and having a temporary one mailed
178193
stay refused;
179194
* closes the account-listing API modules to the reader group;
180195
* closes the special pages that list or resolve accounts to the reader group, and transcluding
181-
`Special:ListUsers` to everyone;
182-
* removes `@` from `$wgInvalidUsernameCharacters`, and changes `$wgUserrightsInterwikiDelimiter` from
183-
`@` to `@@`, so that staff can use `Special:UserRights` on an account named after an address.
196+
`Special:ListUsers` to everyone.
184197

185198
While the code route is turned on, it also turns off ConfirmEdit's `badloginperuser` captcha trigger,
186199
so failed logins no longer escalate to a captcha for the account they name, for everyone on the wiki
187200
and not only for members; the per-IP `badlogin` trigger is left alone.
188201

202+
While the allowlist governs single sign-on, it also sets `$wgOpenIDConnect_PreferredUsernameProcessor`,
203+
so that the accounts that route creates for members are named after nobody, and
204+
`$wgOpenIDConnect_EmailProcessor`, so that the address the plugin resolved is the one the allowlist is
205+
asked about. Processors the wiki configured itself are kept and run first.
206+
189207
While any route can log a member in — the code route turned on, or the allowlist governing single
190208
sign-on — it also:
191209

@@ -194,10 +212,10 @@ sign-on — it also:
194212
* sets `$wgExtendedLoginCookieExpiration` to `$wgMemberAccessSessionDurationSeconds`, which decides
195213
how long a remembered login lasts for everyone on the wiki, not only for members.
196214

197-
A wiki with the code route off and single sign-on left alone gets the first list and nothing else: what
198-
an anonymous visitor may do, what ConfirmEdit does, and how long a remembered login lasts are left as
199-
the wiki has them. That is a wiki that has just loaded the extension, since neither route is offered
200-
until a setting says so.
215+
A wiki with the code route off and single sign-on left alone gets the first list and nothing else:
216+
what an anonymous visitor may do, what ConfirmEdit does, how single sign-on names the accounts it
217+
creates, and how long a remembered login lasts are left as the wiki has them. That is a wiki that has
218+
just loaded the extension, since neither route is offered until a setting says so.
201219

202220
## Installation
203221

@@ -207,6 +225,14 @@ Platform requirements:
207225
* [MediaWiki] 1.43 or later
208226
* MySQL, MariaDB or SQLite. No PostgreSQL schema is shipped
209227
* Working outgoing email while the code route is offered, since login codes are sent by mail
228+
* [OpenIDConnect] 8.3 or later while single sign-on is held to the allowlist, with
229+
`$wgOpenIDConnect_UseRandomUsernames` left off and its preferred username processor left to this
230+
extension rather than set per provider. Every other way of naming a single sign-on account is one
231+
the extension cannot make opaque, and a member's login is then refused.
232+
`$wgOpenIDConnect_MigrateUsersByUserName` has to be off as well, since it hands a login the account
233+
whose name it presents as its `preferred_username`, which is a member's account claimed without
234+
their address. `$wgOpenIDConnect_MigrateUsersByEmail` is what joins a single sign-on login to the
235+
account the code route created for the same address; without it that address gets a second account
210236

211237
Clone into the wiki's `extensions/` directory:
212238

@@ -234,6 +260,13 @@ Run `php maintenance/run.php update --quick` to create the extension's tables. U
234260
warning on the `MemberAccess` log channel says so, and anything that reads them fails with a database
235261
error.
236262

263+
The same command gives an opaque name to every member the extension did not name, which is what
264+
earlier versions left them under. It is recorded in the rename log, which is why that log is
265+
restricted, and on the `MemberAccess` log channel by user id alone. It does not move a `User:` or
266+
`User talk:` page titled after the old name, so a wiki that has any moves them by hand, without
267+
leaving a redirect. Core's rename code names both the old and the new name at debug level, so run it
268+
without `$wgDebugLogFile` pointing at a file you keep. Running it again has nothing left to rename.
269+
237270
## Management API
238271

239272
Groups, allowlist entries and the roster are managed over REST, under `/rest.php/member-access/v0/`.
@@ -289,9 +322,8 @@ human-readable `error`: `not_logged_in`, `permission_denied`, `invalid_csrf_toke
289322
`invalid_request_body`, `invalid_group_name`, `group_name_too_long`, `duplicate_group_name`,
290323
`group_not_found`, `group_not_empty`, `group_has_members`, `too_many_entry_values`, `entry_not_found`,
291324
`not_a_member`, `cannot_deactivate_self`, `block_right_required`, `block_failed`, `unblock_failed`,
292-
`cannot_remove_self`, `reserved_name_taken`, `removal_failed`. A request the REST framework refuses
293-
first — an id that is not a number, a body it cannot read — carries MediaWiki's error shape rather
294-
than this one.
325+
`cannot_remove_self`. A request the REST framework refuses first — an id that is not a number, a
326+
body it cannot read — carries MediaWiki's error shape rather than this one.
295327

296328
## Configuration
297329

@@ -356,15 +388,16 @@ Initial version for MediaWiki 1.43+ with these features:
356388
* A code screen that names the address the code went to, offers another code in its place, and
357389
offers a way back to enter a different address
358390
* An allowlist of email addresses and domains, organized into named groups, decides who is admitted
359-
* Accounts create themselves at first login, into a reader group that may read and nothing else
391+
* Accounts create themselves at first login, into a reader group that may read and nothing else,
392+
under a name that identifies nobody
360393
* Single sign-on logins through [PluggableAuth] can be held to the same allowlist, with staff
361394
accounts exempt
362395
* Settable login routes, neither offered until a setting says so: the code route admits the addresses
363396
an allowlist entry matches, every address, or nobody; single sign-on is held to the allowlist or
364397
left alone
365398
* Members never have a password: setting one and having a temporary one mailed are both refused
366399
* Deactivation blocks a member's account sitewide, reactivation lifts that block again, and
367-
removal frees their address for a new account
400+
removal closes the account and frees their address for a new one
368401
* Code requests rate limited per email address and per client IP, with a burst and a daily limit,
369402
and codes stored hashed and burned after five wrong entries
370403
* Uniform responses, restricted account-listing API modules and special pages, and restricted new
@@ -380,3 +413,4 @@ Initial version for MediaWiki 1.43+ with these features:
380413
[MediaWiki Consulting]: https://professional.wiki/en/mediawiki-consulting-services
381414
[PHP]: https://www.php.net
382415
[PluggableAuth]: https://www.mediawiki.org/wiki/Extension:PluggableAuth
416+
[OpenIDConnect]: https://www.mediawiki.org/wiki/Extension:OpenID_Connect

‎i18n/en.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"memberaccess-special-page-denied": "This special page is not available to members.",
4141
"memberaccess-block-reason": "Membership ended",
4242
"memberaccess-unblock-reason": "Membership resumed",
43-
"memberaccess-rename-reason": "Member removed",
43+
"memberaccess-opaque-name-reason": "Email addresses are no longer used as usernames",
4444
"right-memberaccess-manage": "Manage the member allowlist and roster",
4545
"action-memberaccess-manage": "manage the member allowlist and roster",
4646
"group-reader": "Readers",

‎i18n/qqq.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
"memberaccess-auth-code-outstanding": "Shown on the code entry screen when no new code was sent, so the one already sent is what to enter. Parameters:\n* $1 - the email address the code was sent to",
3535
"memberaccess-auth-code-expired": "Error shown when the code is used up, expired, or out of attempts.",
3636
"memberaccess-auth-not-authorized": "Error shown when a correct code was entered but the address is not on the allowlist.",
37-
"memberaccess-auth-failed": "Error shown when logging in cannot continue: the session lost track of the code request, the address cannot become a username, or that username belongs to a different account. Deliberately vague; only the first case is fixable by requesting a new code.",
37+
"memberaccess-auth-failed": "Error shown when a code login cannot continue, for any of several internal reasons. Deliberately vague, so keep the translation unspecific rather than naming a cause.",
3838
"memberaccess-auth-password-refused": "Error shown when setting or resetting the password of a member account is attempted.",
3939
"memberaccess-api-module-denied": "Action API error shown when a member asks for a query module that lists the wiki's accounts.\n\nParameters:\n* $1 - the name of the query submodule, for example allusers",
4040
"memberaccess-special-page-denied": "Error page shown when a member opens a special page that lists or resolves the wiki's accounts.",
4141
"memberaccess-block-reason": "Reason recorded in the block log when a member is deactivated. Reactivation recognises the extension's own block by this text in the wiki's content language: after a rewording, blocks placed under the old wording are reported as foreign instead of lifted.",
4242
"memberaccess-unblock-reason": "Reason recorded in the block log when a member is reactivated.",
43-
"memberaccess-rename-reason": "Reason recorded in the rename log when a member is removed.",
43+
"memberaccess-opaque-name-reason": "Reason recorded in the rename log when the update that gives members opaque usernames renames a member account.",
4444
"right-memberaccess-manage": "{{doc-right|memberaccess-manage}}",
4545
"action-memberaccess-manage": "{{doc-action|memberaccess-manage}}",
4646
"group-reader": "{{doc-group|reader}}",

‎src/Application/MemberRemover.php‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44

55
namespace ProfessionalWiki\MemberAccess\Application;
66

7+
use Throwable;
8+
79
/**
8-
* Forgets a member: the roster row goes, the account gives up their address, and the username the
9-
* address maps to is freed by parking the account under a reserved name.
10+
* Forgets a member: the roster row goes and the account gives up their address and their sessions.
1011
*
11-
* Freeing the name is what a removal is for. A roster row deleted on its own would leave the
12-
* account holding the name the address maps to, which is where every later login with that address
13-
* arrives, so the address would be refused for good.
12+
* The account itself stays, holding nothing of the member and no longer reachable by either login
13+
* route. The address is free again and reaches a new account at the next login, since the roster
14+
* is what joins an address to an account.
1415
*/
1516
interface MemberRemover {
1617

1718
/**
18-
* Either all of it happens or none does: an account holding a name that admits nobody is the
19-
* state a removal exists to undo, so it is never one a removal leaves behind.
19+
* Either all of it happens or none does: a forgotten roster row whose account kept the address
20+
* is a way back in, so it is never a state a removal leaves behind.
2021
*
21-
* @return RemovalResult Never NotAMember: whether the account is a member is the caller's to know
22+
* @throws Throwable Whatever the writes throw, having left nothing of the removal behind
2223
*/
23-
public function removeMember( int $userId, int $performerId ): RemovalResult;
24+
public function removeMember( int $userId ): void;
2425

2526
}

0 commit comments

Comments
 (0)