Commit graph

53 commits

Author SHA1 Message Date
jenkins-bot
929fad3809 Merge "Unpersist the session on logout" 2016-03-01 02:37:47 +00:00
Gergő Tisza
9c73331810 Cache user data in memory
Stores user data looked up in WAN cache in memory so that lookups in the
same request do not result in new memcached lookups.

Quick and dirty solution, but nicer ones are more difficult:
* no idea what replacing WANObjectCache::get/set with getWithSetCallback
  (which has its own in-process cache) would do, the code is complex
  and completely different
* would be nice to wrap the logic into a proxy object (like CachedBagOStuff)
  but WANObjectCache calls set() internally (and marks it final), so
  inheriting is not safe; the interface and implementation should be
  separated, and that means updating all external callers which do a type
  check.
* ObjectCache::getInstance('hash') cannot be used because it has no
  item limit and this could eat up the memory with a script that iterates
  through lots of users

The patch does not attempt to replicate tombstoning for
User::clearSharedCache('refresh').

Based on Iec1504700a and Idef9a9d3.

Change-Id: I419f356b0c306d16711b433da95dccdb44645154
Co-Authored-By: Ori Livneh <ori@wikimedia.org>
Bug: T128157
2016-03-01 00:19:14 +00:00
Brad Jorsch
6d4436c915 Unpersist the session on logout
Clearing the cookies in this case is probably a good idea.

This also clears cookies when a non-persisted session's metadata is
dirty, for parallelism with what happens to persisted sessions.

Bug: T127436
Change-Id: I76897eaac063e5e3c3563398d0f4cb36cf93783b
2016-02-29 15:39:25 -05:00
Ori.livneh
4b9ad6ede0 Revert "Prevent duplicate memcached lookups for user record"
This reverts commit 7d67b4d919.
Caused T128246, T128263, T128275.

Change-Id: I639ea59e2d42ffbbf700451074174720f2f45cf4
2016-02-29 20:16:46 +00:00
jenkins-bot
33a52b418c Merge "Prevent duplicate memcached lookups for user record" 2016-02-26 18:38:09 +00:00
Ori Livneh
7d67b4d919 Prevent duplicate memcached lookups for user record
User::loadFromId() will look up the user in the database or in memcached -- but
it does not allow for the possibility that the record has already been
retrieved. On a typical page request on the Wikimedia cluster, this causes over
a dozen duplicate memcached lookups for the user record.

Bug: T128157
Change-Id: Iec1504700ab566ca89d0ef868d495238b151034a
2016-02-25 23:50:19 -08:00
Brad Jorsch
8dca366e11 User::isSafeToLoad() should return false if MW_NO_SESSION
Because it's never safe.

Bug: T127233
Change-Id: Ieb5824f1668dc38d1be7c7cbf799da17e581c555
2016-02-25 13:14:13 -05:00
Brad Jorsch
f61cb18b71 Enforce MW_NO_SESSION, add MW_NO_SESSION_HANDLER
When an entry point specifies MW_NO_SESSION, actually enforce that by
having both SessionManager and PHP's session handling (session_start()
and friends) throw exceptions.

If an entry point needs the old behavior of using PHP's default session
handling (as defined in php.ini), it should define
MW_NO_SESSION_HANDLER instead of or in addition to MW_NO_SESSION.

This also makes PHPSessionHandler be installed in CLI mode, where it
wasn't installed before.

Bug: T127233
Change-Id: I2a3db06ee8e44a044096c57a819b5fd5e51c5c5c
2016-02-22 12:17:31 -05:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Stephane Bisson
c762e0ced9 Add 'reason' to UserGroupsChanged hook
Used by Echo to display the reason in the 'user-rights' notifications

Bug: T126277
Change-Id: Ib9bb28a7a77602e3e729fd0bf13ab8259e15b006
2016-02-12 14:54:35 -05:00
Ricordisamoa
c38f95f62b Stop doing $that = $this in includes/user
Closures support $this as of PHP 5.4

Change-Id: If79be54276fe2a35bdd004908cfc160e6636f7c5
2016-02-10 23:52:46 +01:00
jenkins-bot
bc86ab6eb2 Merge "Remove unused imports from Session classes" 2016-02-10 19:21:27 +00:00
Thiemo Mättig
e5159debbb Remove unused imports from Session classes
Change-Id: Ia3cdd923728870f5eff0bd90fd2f6605047291c0
2016-02-10 18:09:02 +01:00
CSteipp
01e345e04b Revert "Limit ip-all/subnet-all ping limts per wiki"
This reverts commit 461406e318.

My mistake, we've always used global keys for ip/subnet.

Change-Id: I8bc1bfdf61ae5c0988a913871a7292faed372141
2016-02-09 19:50:19 +00:00
csteipp
461406e318 Limit ip-all/subnet-all ping limts per wiki
47973faa7c used a static string for ip-all/subnet-all limits,
instead of generating a key unique to each wiki.

Change-Id: Ie8013dc959fdeba92ecd463550e3d98d83276004
2016-02-09 09:38:55 +00:00
jenkins-bot
8ea3e9135d Merge "Introduce User::INVALID_TOKEN" 2016-02-08 00:55:04 +00:00
Gergő Tisza
7072d4718e Expand documentation of User::isSafeToLoad
Change-Id: I7f018b7f7219e7a17a3059b3ec9cbdf1c2c1e043
2016-02-06 22:40:43 +00:00
jenkins-bot
4b069cd1b8 Merge "Add $wgRateLimits types ip-all and subnet-all" 2016-02-05 20:52:05 +00:00
Brad Jorsch
6eec9fb355 Avoid unstubbing $wgUser before the end of Setup.php in User::getBlockedStatus()
Autocreation needs to check if the current IP is blocked from account
creation.

There are two ways we could go here: treat $wgUser as logged-out, or
assume it will eventually be the user name specified by the session.
This patch chooses the former, by the logic that at this early point in
the setup process we don't have a logged-in user determined yet so no
username can really be considered to match the logged-in user.

Bug: T124367
Change-Id: I631bec85291b57f07c378cf6554a8f06cf3fb00c
2016-02-03 21:46:12 +00:00
Brad Jorsch
35c38ce319 Add User::isSafeToLoad() and ParserOptions::newFromAnon()
Useful for avoiding "User::loadFromSession called before the end of
Setup.php".

Bug: T124367
Change-Id: I0b018a623fc833ca95d249ee21667a8f5690d50e
2016-02-03 21:45:56 +00:00
Brad Jorsch
30a9eae821 Introduce User::INVALID_TOKEN
To avoid having to have SessionManager try to reset sessions on every
request, we set the user_token to a special value. When that value is
present, User::getToken() returns a different value every time (so
existing checks will fail) and User::setToken() refuses to alter it.

Bug: T124414
Change-Id: Ie4c84ce993e40a081288cf5a543f8ba99f98806a
2016-02-03 21:45:45 +00:00
Brad Jorsch
2257fe4228 Revert "Remove SessionManager, temporarily"
This reverts commit 823db5d63dd5200d04c63da50ba6bf16f928e70b.

Change-Id: Ibb3e023e4eb6715295586dea87d0725c344a8271
2016-02-03 21:44:59 +00:00
Brad Jorsch
fbec46e308 Add $wgAuthenticationTokenVersion
This allows for quickly invalidating everyone's session all at once by
changing a single value.

As a side effect, setting this also stops the user_token field from
the database from being served to the user as a cookie.

This mitigates but doesn't completely solve T49490, as it allows for
invalidating all existing sessions and token-cookies but does not help
if the user_token field in the database was leaked.

Bug: T49490
Change-Id: I9d316a6bbb36278d138f39a89125ebb8cc71b28f
2016-02-02 19:21:52 +00:00
Brad Jorsch
5083e810eb Remove SessionManager, temporarily
The plan here is to take it out of 1.27.0-wmf.12 and put it back in
1.27.0-wmf.13.

Since BotPasswords depends on SessionManager, that's getting temporarily
removed too.

This reverts the following commits:
* 6acd424e0d SessionManager: Notify AuthPlugin before calling hooks
* 4d1ad32d8a Close a loophole in CookieSessionProvider
* fcdd643a46 SessionManager: Don't save non-persisted sessions to backend storage
* 058aec4c76 MessageCache: Don't get a ParserOptions for $wgUser before the end of Setup.php
* b5c0c03bb7 SessionManager: Save user name to metadata even if the user doesn't exist locally
* 13f2f09a19 SECURITY: Fix User::setToken() call on User::newSystemUser
* 305bc75b27 SessionManager: Don't generate user tokens when checking the tokens
* 7c4bd85d21 RequestContext::exportSession() should only export persisted session IDs
* 296ccfd4a9 SessionManager: Save 'persisted' flag in session metadata
* 94ba53f677 Move CSRF token handling into MediaWiki\Session\Session
* 46a565d6b0 Avoid false "added in both Session and $_SESSION" when value is null
* c00d0b5d94 Log backtrace for "User::loadFromSession called before the end of Setup.php"
* 4eeff5b559 Use $wgSecureCookie to decide whether to actually mark secure cookies as 'secure'
* 7491b52f70 Call session_cache_limiter() before starting a session
* 2c34aeea72 SessionManager: Abstract forceHTTPS cookie setting
* 9aa53627a5 Ignore auth cookies with value 'deleted'
* 43f904b51a SessionManager: Kill getPersistedSessionId()
* 50c5256352 SessionManager: Add SessionBackend::setProviderMetadata()
* f640d40315 SessionManager: Notify AuthPlugin when auto-creating accounts
* 70b05d1ac1 Add checks of $wgEnableBotPasswords in more places
* bfed32eb78 Do not raise a PHP warning when session write fails
* 722a7331ad Only check LoggedOut timestamp on the user loaded from session
* 4f5057b84b SessionManager: Change behavior of getSessionById()
* 66e82e614e Fix typo in [[MediaWiki:Botpasswords-editexisting/en]]
* f9fd9516d9 Add "bot passwords"
* d7716f1df0 Add missing argument for wfDebugLog
* a73c5b7395 Add SessionManager

Change-Id: I2389a8133e25ab929e9f27f41fa9a05df8147a50
2016-02-01 22:06:49 +00:00
addshore
91825ea180 Remove WatchedItem::IMMEDIATE and DEFERRED
It looks like this used to actually be used
since Ie60e20162fd833e64d81763a6aa1dc3faf2162f3
but since the global wgActivityUpdatesUseJobQueue
seems to have been removed from the code.

Thus this stuff is doing nothing and
things are always DEFERRED.

Change-Id: I08cb6051f52e0f0402542d8326f03f115bb00943
2016-01-29 20:34:38 +01:00
Brad Jorsch
76d790623c User: Fix loading of user_token
Similar to T124414, we should always load user_token from the row even
if user_email is unset.

Also, I notice that maintenance/tables.sql defines the column as
"binary(32)", which is going to append ASCII NUL bytes to the default
empty-string. And before that it was "char(32)", which will append
spaces. So trim both of those off when reading the field so the
following check for === '' actually works.

The latter doesn't seem to affect *most* WMF wikis, since they have the
column defined as "varbinary(32)" for some reason. But there are a few
with "binary(32)", I have no idea why.

Change-Id: I50a813bb530639275628d9560c79a773676aa36d
2016-01-28 13:51:45 -05:00
Brad Jorsch
94ba53f677 Move CSRF token handling into MediaWiki\Session\Session
User keeps most of its token-related methods because anon edit tokens
are special. Login and createaccount tokens are completely moved.

Change-Id: I524218fab7e2d78fd24482ad364428e98dc48bdf
2016-01-27 15:27:20 -05:00
cenarium
47973faa7c Add $wgRateLimits types ip-all and subnet-all
These apply to all ping-limitable users, unlike ip and subnet that apply only
to anons and non-autoconfirmed users. However, if an autoconfirmed user is in
a group with less restrictive limits, then those are ignored.

This is necessary to move the account creation throttle into the ping limiter.

Bug: T50373
Change-Id: Ifc70a605bb8848070bdf2af8f2c3f80f68dcc085
2016-01-26 15:07:55 +01:00
Brad Jorsch
c00d0b5d94 Log backtrace for "User::loadFromSession called before the end of Setup.php"
Fixing the bug will be much easier if we know where it's being called
from.

Bug: T124367
Change-Id: I69cd8bc2bb0677819763c59a221f098d564c92cd
2016-01-25 22:58:52 +00:00
Niklas Laxström
7c131627b9 Add missing @since to new IdLookup classes
Follow up I49568358ec35fdfd0b9e53e441adabded5c7b80f

Change-Id: I9f2e9a7c9bb5dd8608cfc6678a3557d916f0b09f
2016-01-22 20:17:31 +00:00
Brad Jorsch
92ba9fa33d User: Fix loading of user_touched
Always load user_touched from the row if present, don't gate it on
user_email being non-null.

Bug: T124414
Change-Id: I68fcbb560ddfa349b83126298534161971a88871
2016-01-22 12:49:06 -05:00
Brad Jorsch
70b05d1ac1 Add checks of $wgEnableBotPasswords in more places
Bug: T124335
Change-Id: I3c13e7c7b84d5b72437f9ebdba35aad29b403b9c
2016-01-21 15:06:02 -05:00
Brad Jorsch
722a7331ad Only check LoggedOut timestamp on the user loaded from session
This avoids infinite loops when trying to load other User objects, and
should still preserve the intent of the timestamp (that being as an
invalidation date for client-side caching).

Bug: T124143
Change-Id: Ie304cc3839fdc36a1cb2895e26f7700f4b725159
2016-01-20 13:26:44 -05:00
jenkins-bot
e024b4e93c Merge "Remove proxyunbannable from core" 2016-01-15 18:34:42 +00:00
cenarium
1e98af0796 Remove proxyunbannable from core
This removes the userright 'proxyunbannable' from core, because it has
no uses. It is never checked for users with 'ipblock-exempt', yet all
usergroups with 'proxyunbannable' also have 'ipblock-exempt'.

Bug: T75414
Change-Id: I1e4f6ca439c0274af89f3280fbc519df2b68312c
2016-01-15 10:19:20 -08:00
jenkins-bot
2b2f8570a2 Merge "Remove patrol config check in User::isAllowed()" 2016-01-13 21:47:55 +00:00
Florian
3931a564ee Remove User::generateToken()
Bug: T122754
Depends-On: I8b46e5232b9a40390143d04577c9356fb03cf23e
Depends-On: Idcad2af992e46a1fb67ac66ca3fcbe9d6fa681a1
Change-Id: I3f125ff432d45f0fdb36076183e01954bc3f84e9
2016-01-13 20:21:19 +00:00
Brad Jorsch
f9fd9516d9 Add "bot passwords"
Bot passwords are something like OAuth-lite, or Google's application
passwords: the bot can use API action=login to log in with the special
username and password, and will then be allowed to use the API with a
restricted set of rights.

This is intended to provide an easy migration path for legacy bots and
for bots on wikis without OAuth, since AuthManager is going to greatly
complicate non-interactive authentication. If OAuth is available, an
owner-only consumer would be a better choice.

Bug: T121113
Change-Id: Iaa4015e00edbfbfaedcc8b2d27a2d3fd25009159
Depends-On: I7e15331efb162275c4116bcae61f19d6b884cbe3
2016-01-12 22:37:44 +00:00
Brad Jorsch
ef5bd7347b Move grant and IP restriction logic from OAuth to core
This also adds code to User to allow SessionProviders to apply the grant
restrictions without needing to hook UserGetRights.

Change-Id: Ida2b686157aab7c8240d6a7a5a5046374ef86d52
2016-01-12 22:37:33 +00:00
Brad Jorsch
a73c5b7395 Add SessionManager
SessionManager is a general-purpose session management framework, rather
than the cookie-based sessions that PHP wants to provide us.

While fallback is provided for using $_SESSION and other PHP session
management functions, they should be avoided in favor of using
SessionManager directly.

For proof-of-concept extensions, see OAuth change Ib40b221 and
CentralAuth change I27ccabdb.

Bug: T111296
Change-Id: Ic1ffea74f3ccc8f93c8a23b795ecab6f06abca72
2016-01-12 21:57:01 +00:00
cenarium
273c54bff5 Remove patrol config check in User::isAllowed()
The isAllowed() function of the User class checks $wgUseRCPatrol and
$wgUseNPPatrol in case the action is 'patrol' or 'autopatrol'.
Considering we have the useRCPatrol and such functions, it shouldn't.
getUserPermissionsErrors of the Title class doesn't and extensions may
use patrol regardless of core config. If we don't remove it, we would
have to also check the new $wgUseFilePatrol.

Change-Id: I671a6b3aa3bd1dc274f2f8e61fb739235ced198c
2016-01-12 01:34:19 +01:00
jenkins-bot
6505e5f278 Merge "Allow patrol of uploads" 2016-01-07 01:06:02 +00:00
cenarium
c53f647658 Allow patrol of uploads
This allows to patrol file uploads, both new files and new file
versions, from the description page, provided $wgUseFilePatrol
is set to true. Special:NewFiles can be filtered to hide patrolled
files.

Bug: T11501
Change-Id: If71af58719a4461f12d125455b7bef07164525ca
2016-01-06 14:57:22 -08:00
Reedy
7cc092645f User::getSkin() was removed
Change-Id: I7602ab7609b13b807e67296c8ce0a1d184c88521
2016-01-02 19:34:22 +00:00
jenkins-bot
e53676d3dd Merge "Show user names as subpages of special pages in autocomplete search" 2015-12-30 00:16:20 +00:00
umherirrender
3e0f3cfd43 Show user names as subpages of special pages in autocomplete search
The autocomplete search allows special pages to define the list of
subpages to be excepted. Use user names on the following special pages,
because these special pages can be called with a user name as subpage.

Special:Block
Special:Contributions
Special:DeletedContributions
Special:Emailuser
Special:Listfiles
Special:Unblock
Special:Userrights

This makes it easier to navigate to this special pages with a prefilled
user name field.

Hidden user names are always not shown, because the suggestion is cached
between priviliged user and non-priviliged user.

Change-Id: I7db575bf66caaa5136489ed99f1655673b55adaf
2015-12-29 11:49:58 +01:00
umherirrender
54c1e18eec Remove various double empty newlines
The double empty newline is not needed between functions, variable or at
end of file

Change-Id: Ib866a95084c4601ac150a2b402cfa184ebc18afa
2015-12-27 18:55:12 +00:00
Reedy
4b328d6c2e Removed User::editToken() (deprecated since 1.19)
Change-Id: I734e9637317c0737e96e963bafb10ef966d6d172
2015-12-20 15:09:08 +00:00
Gergő Tisza
f5db0b307b Use hash_equals in User::matchEditToken
There is no point in using hash_equals for the return value if we
do a normal comparison before.

Bug: T119309
Signed-off-by: Chad Horohoe <chadh@wikimedia.org>
Change-Id: Ia44ec5ed492105b27d0fddd845d58d27a29dc072
2015-12-17 16:38:53 -08:00
Aaron Schulz
b046b93d93 Avoid "CAS updated failed" errors on Special:Preferences double post
* This does the same thing ApiOptions does to avoid these errors.
  A new getInstanceForUpdate() method is now in the User class to
  simplify this pattern.
* Avoid overriding $user in ApiOptions for code readability.
* Fixed IDEA errors around Preferences::getFormObject() return type.

Bug: T95839
Change-Id: If2385b7486c043bd70d7031ff35e37dfb079a4d2
2015-12-15 02:50:16 +00:00