Commit graph

31 commits

Author SHA1 Message Date
petarpetkovic
3f60fb5ad1 Remove duplicated article usages
Bug: T201491
Change-Id: I72b1e7609b49b9bf182c0872f8b780d9e9e08695
2018-08-09 10:29:38 +02:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Reedy
fbc0347466 Update MediaWiki\quietCall() -> Wikimedia\quietCall()
Bug: T182273
Change-Id: Id7d8e176fcd93040e30e46cb64fc6a3d36bc8230
2018-02-10 10:49:33 +00:00
Thiemo Mättig
ef470ebf7f Remove @param comments that literally repeat what the code says
These comments do not add anything. I argue they are worse than having
no comments, because I have to read them first to understand they
actually don't explain anything. Removing them makes room for actual
improvements in the future (if needed).

Change-Id: Iee70aad681b3385e9af282d5581c10addbb91ac4
2018-01-10 14:14:26 +01:00
Kunal Mehta
7e48fdd76f session: Avoid deprecated wfMemcKey()
Change-Id: I4d77c2c52ef43cbc54878ce920595befd270a28e
2017-05-23 22:25:27 -07:00
Kunal Mehta
61adc1e146 Use namespaced ScopedCallback
The un-namespaced \ScopedCallback is deprecated.

Change-Id: Ie014d5a775ead66335a24acac9d339915884d1a4
2016-10-17 15:46:05 -07:00
Aaron Schulz
4a2085523f Make SessionBackend::save() update the user post-send
Bug: T92357
Change-Id: Id4f4991aca1ceeb74b59e980f09863041246a4fc
2016-10-12 11:14:45 -07:00
jenkins-bot
80a372f957 Merge "Expand SessionManager / AuthManager documentation" 2016-08-30 19:11:13 +00:00
Gergő Tisza
94e2aa7b55 Expand SessionManager / AuthManager documentation
Bug: T110628
Bug: T142154
Change-Id: Ib0a41f01b3d12267b2a94ea1375e6d13cacd2b69
2016-08-30 18:54:30 +00:00
Aaron Schulz
c5f92afc3b Set the WRITE_SYNC flag for SessionBackend writes
Session writes should be seen in all datacenters so users do not
randomly end up logged on the next page view on a GET request
after login. Sticky DC cookies help, but not for cross domain
redirects or page views.

Change-Id: Id533fa1b867680e6386060efa4878ad1b4638c18
2016-08-28 13:44:04 -07:00
Brad Jorsch
f1a751db94 SessionManager: Ignore Session object destruction during global shutdown
We already save all open SessionBackends when shutdown handlers are run,
which *should* make the Session object destructors that run during
global shutdown not have anything to save. But it can get fooled if the
Session data contains other objects that have already gotten destroyed
during the global shutdown, leading to spurious warnings and errors as
it tries to access partically-destroyed objects.

The solution is to set a flag when we do the shutdown handlers and just
ignore the last gasps from Session::__destruct() that might come after.

Change-Id: Ic3eb0bac2d29a30488c84b6525ad796a7f1c9ce9
2016-04-20 13:16:40 -04:00
Gergő Tisza
4085db348e Change \\ to \ in phpdoc
Remove "\\" in namespacing. This is a Doxygen compatibility hack but
does not seem needed anymore, Doxygen reads namespaced class names
correctly, see e.g. https://doc.wikimedia.org/mediawiki-core/master/php/classMediaWiki_1_1Services_1_1ServiceContainer.html

PHP IDEs, on the other hand, were broken by the double backslash.

As an unrelated small doc fix, add parameter docs to PermissionError
constructor (parent has different arguments so the inherited
documentation is wrong).

Change-Id: I6da0f512b8c84f65fd20e90e4617108fe6a8fcd2
2016-04-08 17:46:30 +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
43420a0506 SessionBackend: skip isUserSessionPrevented check for anons
For anon requests, the call to SessionManager::isUserSessionPrevented(
$this->user->getName() ) is both expensive (because of the need to
sanitize the IP) and pointless, because the session-prevention feature
is intended for named accounts. So short-circuit the check if the user is not
logged in.

Change-Id: I17386b97e229b492723b46db1e1ae16fd4b0fc5a
2016-02-24 15:36:10 -08: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
Brad Jorsch
1aedd2df73 Session: Implement ArrayAccess
Now that we dropped support for PHP 5.3.3, we can do this.

The behavior of $session['foo'] when that key doesn't already exist is a
little unexpected (it implicitly assigns null), but it's the best we can
do.

Change-Id: Ibef878867d46591a8bf542139a1719dfec3b83ab
2016-02-16 17:33:33 +00:00
Brad Jorsch
cf9fc81e96 Remove "$that" from SessionManager
Also "function () use ( &$ref )" that was being done for similar
reasons.

Change-Id: If4ec263a9a9c02c1c6a414b26a0e77ba144437f1
2016-02-10 12:10:38 -05:00
Bryan Davis
f60fd42b33 Update session log messages
* Use PSR-3 templates and context where applicable
* Add log coverage for exceptional events

Bug: T125452
Change-Id: I8f96fa1c5766c739a21219abcae2dbb76de53e2a
2016-02-06 16:18:01 -07:00
jenkins-bot
a55b821f3a Merge "Disable automatic cache headers associated with starting a session" 2016-02-04 16:29:20 +00:00
Bryan Davis
514725e7fe Disable automatic cache headers associated with starting a session
Follow up to 7491b52. The 'private, must-revalidate' argument to
session_cache_limiter() does not match any expected values for the
function. This results in the PHP runtime treating it like the
documented empty string argument which completely disables the automatic
addition of cache related headers. Change the implementation to use the
empty string argument explicitly rather than continuing to rely on
the undocumented and potentially confusing existing behavior.

session_cache_limiter( '' ) is called unconditionally in
MediaWiki\Session\PHPSessionHandler::install(). This is safe now that it
is understood that we are disabling the setting of the automatic
headers.

Bug: T124510
Change-Id: I63164f8b7a408e370ff01dead42be27a0135dd35
2016-02-03 21:45:28 +00:00
Brad Jorsch
25dbd91513 Clean up after Ie161e0f
Ie161e0f was done in a hurry, and so didn't do things in the best ways.
This introduces a new "CachedBagOStuff" that transparently handles all
the logic that had been copy-pasted all over in Ie161e0f.

The differences between CachedBagOStuff and MultiWriteBagOStuff are:
* CachedBagOStuff supports only one "backend".
* There's a flag for writes to only go to the in-memory cache.
* The in-memory cache is always updated.
* Locks go to the backend cache (with MultiWriteBagOStuff, it would wind
  up going to the HashBagOStuff used for the in-memory cache).

Change-Id: Iea494729bd2e8c6c5ab8facf4c241232e31e8215
2016-02-03 21:45:18 +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
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
Brad Jorsch
fcdd643a46 SessionManager: Don't save non-persisted sessions to backend storage
This introduces an in-process cache (using a HashBagOStuff) for session
data, and only saves to the external cache when the session is
persisted.

Bug: T125267
Change-Id: Ie161e0f7522cd68515b060ad8cf8c151b7198b0b
2016-01-30 00:26:03 +00:00
Brad Jorsch
b5c0c03bb7 SessionManager: Save user name to metadata even if the user doesn't exist locally
Bug: T125133
Change-Id: I12ff84db614f0d5839457aa92be58c62b3a4e8fd
2016-01-28 16:22:02 -05:00
Brad Jorsch
305bc75b27 SessionManager: Don't generate user tokens when checking the tokens
Looking at the pre-SessionManager token checking, it's apparently valid
to log in despite user_token being empty. The stored token just gets
compared against the empty string that got returned previously.

This also cleans up some checks that assumed $user->getToken() didn't
automatically create the token if one wasn't already set.

Bug: T125114
Change-Id: Ia3d2382e96e2a0146f33fb7193a2e00ea72e51a0
2016-01-28 13:36:43 -05:00
Brad Jorsch
296ccfd4a9 SessionManager: Save 'persisted' flag in session metadata
This allows SessionManager::getSessionById()->isPersisted() to be
reliably set. Otherwise it depends on whether the SessionBackend is
still loaded or not.

Change-Id: I17733559ac5d8fff13881664333f61d36f610b6d
2016-01-27 17:13:35 -05:00
Bryan Davis
7491b52f70 Call session_cache_limiter() before starting a session
Call `session_cache_limiter( 'private, must-revalidate' );` before
starting a session to specify the cache control headers that PHP will
automatically emit. The calls are wrapped in MediaWiki\quietCall to
suppress "headers have already been sent" warnings that may come from PHP.

If not called explicitly PHP will default to using
the value of the session.cache_limiter ini setting. Some values of that
setting will cause PHP to add a "Pragma: no-cache" header to the
response. Certain user agents (e.g. Firefox) treat that particular
header as a signal to aggressively flush the response from local cache
to the point that back button navigation will not work.

The value used was present in `wfSetupSession` prior to a73c5b7.

Bug: T124510
Change-Id: I942f8420c39c8cec5781ea8f6cc5619fd15f13cd
2016-01-25 11:23:14 -07:00
Brad Jorsch
50c5256352 SessionManager: Add SessionBackend::setProviderMetadata()
Providers might need to update their metadata at times other than when
they're creating the SessionInfo.

Bug: T124409
Change-Id: Ia9d113c93726205de85df65bf85faef74c73c949
2016-01-22 11:10:42 -05: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