Page MenuHomePhabricator

Invalid username errors goes unchecked
Closed, ResolvedPublic

Description

Author: kwi

Description:
Adds checks for invalid usernames.

Note: I encountered this issue on a wiki with very specific rules on username composition. Errors are unlikely (but not impossible) on vanilla installs.

Per the code docs, User::newFromName returns a "User object, or false if the username is invalid (e.g. if it contains illegal characters or is an IP address). If the username is not present in the database, the result will be a user object with a name, zero user ID and default settings." Username validity may, among other things, be constrained by plugins through the AuthPlugin interface.

Due to the creation of "mock" User objects for non-existent users with valid usernames, and since almost any name is valid by default, newFromName rarely returns false on vanilla installs. This explains why a lot of code doesn't handle the case where the result is false.

Note that User::newFromName can return false even when the validate argument is false, as getCanonicalName always performs at least minimal validation (no '#' in names).

In an attempt to fix these errors, I've reviewed all invocations of User::newFromName in r80702.

For maintenance scripts, simply dying with an error message seems reasonable.

For include files, I've tried to handle invalid usernames appropriately.

For the last 4 files in the attached diff, I'm unsure how to properly handle the error condition. The diff for these files consist only of a FIXME code comment indicating the problem.


Version: 1.18.x
Severity: minor

Attached:

Details

Reference
bz26854

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:18 PM
bzimport set Reference to bz26854.
bzimport added a subscriber: Unknown Object (MLST).

sumanah wrote:

Søren Løvborg, I'm sorry for the wait. Thanks for the patch. I'm adding the "need-review" keyword to ask developers to review your patch. Thanks for contributing.

Applied most of the patch in r103745, and fixed SpecialContributions and SpecialDeletedContributions in r103751.

kwi wrote:

Thanks guys, much appreciated.