Commit graph

321 commits

Author SHA1 Message Date
James D. Forrester
9635dda73a includes: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Change-Id: I6f59febaf8fc96e80f8cfc11f4356283f461142a
2017-02-21 18:13:24 +00:00
Ricordisamoa
06c8656d95 Fix documentation comments for some WebRequest methods
WebRequest methods getRawVal(), getVal() and getArray()
can return null.

Change-Id: I555dfd93c7cdebc83aab89f3efe4de3018bc9de0
2017-02-20 22:25:02 +01:00
Victor Barbu
1bf8e81cdd Remove WebRequest::checkSessionCookie() method as being deprecated
Bug: T61113
Change-Id: I5285dbfc47d6429e16b7e7839bf55d48320d0bf0
2016-12-31 17:37:04 +00:00
jenkins-bot
9ac29c74ed Merge "Cleanup some incorrect return annotations" 2016-12-16 07:22:24 +00:00
jenkins-bot
3a2853e218 Merge "Add <!DOCTYPE html> to HTML responses" 2016-12-16 07:16:45 +00:00
Erik Bernhardson
d67197fa11 Cleanup some incorrect return annotations
Most of these are simply changing annotations to reflect
reality. If a function can return false to indicate failure
the @return should indicate it.

Some are fixing preg_match calls, preg match returns 1, 0 or false,
but the functions all claim to return booleans.

This is far from all the incorrect return types in mediawiki, there
are around 250 detected by phan, but have to start somewhere.

Change-Id: I1bbdfee6190747bde460f8a7084212ccafe169ef
2016-12-12 10:15:05 -08:00
Fomafix
202f695f67 Update weblinks in comments from HTTP to HTTPS
Use HTTPS instead of HTTP where the HTTP link is a redirect to the HTTPS link.

Also update some defect links.

Change-Id: Ic3a5eac910d098ed5c2a21e9f47c9b6ee06b2643
2016-11-07 15:24:46 +01:00
Fomafix
e101fa901b Add <!DOCTYPE html> to HTML responses
Change-Id: I080040913c4c9750104bc88b643a1ffdfd222502
2016-09-25 17:36:41 +02:00
Kunal Mehta
39ee83f388 Move IP::isConfigured/TrustedProxy() to ProxyLookup service
This creates a new ProxyLookup service to house the
IP::isConfiguredProxy() and IP::isTrustedProxy() functions. The main
purpose of this refactoring is to make the IP class entirely independent
from MediaWiki, so it can be split into a separate library.

Change-Id: I60434a5f3d99880352bc0f72349c33b7d029ae09
2016-09-21 20:02:09 -07:00
Timo Tijhof
83df6d8123 WebRequest: Use getRawVal instead of getGPCVal where possible
Avoid getGPCVal() for simple methods that only need a boolean,
number or specific string outcome.

This saves overhead of touching $wgContLang or UtfNormal\Validator
and makes load.php initialisation no longer depend on it.

Change-Id: I8ce1fa31f5102b3fa18b0d0b9f56c42cb90146a1
2016-09-09 15:46:08 -07:00
Timo Tijhof
1ac5474b7b WebRequest: Add more unit tests
* Complete detectServer() coverage,
  test $wgAssumeProxiesUseDefaultProtocolPorts.
* Complete getAcceptLang() coverage.
* Add tests for getGPCVal() normalisation.
* Add tests for other getter methods.

Also:

* Ignore __construct() coverage as it only sets up properties from
  global state. The use of those properties are covered.

* Make normalizeUnicode() visibility explicit.

Change-Id: I6504136e6df47e504bc2e0e91fedddd2625f19d9
2016-09-08 21:58:09 -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
Brad Jorsch
75a85b412c API: Use U+001F (Unit Separator) for separating multi-valued parameters
When a multi-valued parameter's value begins with U+001F, the values
will be split on that character instead of pipes. This will be useful
for things such as action=options&change= or meta=allmessages&amargs=.
Since MediaWiki doesn't otherwise accept C0 control characters
(WebRequest::getVal() replaces them with �), there's no possibility that
this will conflict with a literal use of U+001F.

Special:ApiSandbox and mw.Api are updated to make use of this, with the
latter having an option to disable the behavior in case something is
depending on [ 'foo', 'bar|baz' ] turning into 'foo|bar|baz'.

Pipe is still used as the separator when the value doesn't begin with
U+001F, and will be forever since it's generally more human-friendly and
is needed for backwards compatibility with basically every API client in
existence. The requirement that the value begin with U+001F, rather than
simply contain U+001F, is to avoid clients having to somehow
special-case "param=foo|bar" where that's intended to be a single value
"foo|bar" rather than two values "foo" and "bar".

Bug: T141960
Change-Id: I45f69997667b48887a2b67e93906364a652ace5a
2016-08-29 11:00:25 -04:00
Kevin Israel
5063fa6ee8 WebRequest::getText(): Update more of the doc comment
Support for server-side input transliteration, not just its
implementation for Esperanto, was removed in 3b5f60f2c8.
Now we only do Unicode and line ending normalizations.

Change-Id: Ie6172ee2d76a79006286a5f3c51b89bb762c258e
2016-07-21 03:37:10 -04:00
Brion Vibber
3b5f60f2c8 Remove old Esperanto character conversion support
Deletes LanguageEo.php class which only had remains of the server-side
character conversion (sx <-> ŝ, etc). This is being obsoleted in favor
of client-side IMEs provided by UniversalLanguageSelector extension.

Removes deprecated $wgEditEncoding, which was only used for this.

Turns Language::recodeInput() and Language::recordForEdit() into no-ops
for any old or extension code that happened to still use them.

Bug: T62677
Change-Id: Ib647353538d258dee941f2f7c571191060bc9c7d
2016-07-18 19:20:49 +00:00
Aaron Schulz
7f8d016f5a Avoid DBPerformance warnings on PURGE/TRACE requests
The former sometimes show up in the logs as they were causing
CentralAuth to use the master but the expectations treated
the request as a GET request. This makes things more
consistent.

Bug: T92357
Change-Id: I55bf3139c68f5926fe67a51cf0eb1b2ffe55d17b
2016-05-25 18:22:26 -07:00
Aaron Schulz
549af8bf91 Add WebRequest methods for determining "safe" requests
* This is useful for logic that decides what DB (master/slave) to use
  based on the nature of the web request. It could also be used to
  enforce clear read/write distinctions via exceptions if DB_MASTER
  is misused.
* Also fixed two IDEA errors while editing this class.

Bug: T134608
Change-Id: I43f4bc06c19d823d7d1ffd9cee8bbe60563c7f82
2016-05-10 11:17:28 -07:00
Erik Bernhardson
afc3b5a120 Track which web request created a job
We currently push a request id into structured logging (monolog/
logstash) to allow seeing all logs that were triggered by the same
request. This extends that to pass the id through jobs so jobs triggered
by a web request also share the same id and can be tracked together.
This web request id will follow jobs both directly created by a request,
and jobs created by those jobs.

This should give us some more visibility when debugging into what
started a particular job, and if a large number of jobs blowing up the
job queue are somehow related.

Change-Id: Iedbd031e6e9bb18fd6f7b923c8c305102255ab4b
2016-04-13 10:41:13 -07: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
Ori Livneh
5360a3497f Provide a unique request identifier
When MediaWiki encounters an unhandled exception, the error message it produces
includes a randomly-generated token, which allows the exception details to be
looked up in the error logs. This is useful but narrow: would it not be useful
to have the ability to retrieve all log records associated with a particular
request, rather than just exception details? (Hint: yes.)

So: introduce the notion of a request-global unique ID, retrievable via
WebRequest::getRequestId(). When MediaWiki is behind Apache + mod_unique_id
(which provides the same facility) or some other software which sets a
UNIQUE_ID envvar, the value of that envvar is used as the request ID.
Otherwise, it is a randomly-generated 24-character string.

The request ID supplants exception-specific IDs; MWExceptionHandler::getLogId()
is deprecated, accordingly. The request ID is also added as an annotation to
all Monolog-processed log records, and is exposed client-side as 'wgRequestId'.
This allows developers to associate a page view with log records even when the
page view does not result in an unhandled exception. (For the WMF, I also
intend to add it as an annotation to profiling data).

The request ID is not a tracking token; it does not persist, and it is
associated with a backend request, not with a particular user or a particular
session. Like the data in the NewPP report, the request ID is designed to be
cacheable, so that if, for example, a developer notices something weird in the
HTML, s/he can associate the output with a backend request regardless of
whether the response was served from the cache or directly from the backend.

Some prior art:
* https://httpd.apache.org/docs/2.4/mod/mod_unique_id.html
* http://api.rubyonrails.org/classes/ActionDispatch/RequestId.html
* https://github.com/dabapps/django-log-request-id
* https://packagist.org/packages/php-middleware/request-id
* https://github.com/rhyselsmore/flask-request-id

Change-Id: Iaf90c20c330e0470b9b98627a0228cadefd301d1
2016-03-25 16:09:05 +00:00
Brad Jorsch
b84fae0173 Use header_register_callback to avoid caching responses with Set-Cookie headers
This change mirrors logic that has been in use on the Wikimedia
Foundation production cluster's Varnish cache system for over 2 years to
guard against accidentally caching backend responses which include
Set-Cookie headers.

Bug: T127993
Change-Id: Ic79cf6c959dd870d6458874a9bffe9e25aba4919
2016-03-08 14:38:22 -05: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
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
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
43f904b51a SessionManager: Kill getPersistedSessionId()
It's not guaranteed that loadSessionFromStore() will succeed after
whatever alterations the SessionProvider might have made later in the
request.

So instead, let's make a new global object that stores the SessionId
of the persistent session that was loaded during Setup.php, if any. Then
we can check that when we need to know whether the session was
persisted.

Bug: T124468
Change-Id: I1e8e616c83b16aadd86b0a0a40826d40f6e8abe4
2016-01-22 14:47:33 -05:00
Brad Jorsch
4f5057b84b SessionManager: Change behavior of getSessionById()
It's easily possible for SessionManager::getSessionById() to not be
able to load the specified session and to not be able to create an empty
one by that ID, for example if the user's token changed. So change this
from an exceptional condition to an expected one, and adjust callers to
deal with it appropriately.

Let's also make the checks for invalid data structure when loading the
session from the store delete the bogus data entirely.

At the same time, let's change the silly "$noEmpty" parameter to
"$create" and make the default behavior be not to create an empty
session.

Bug: T124126
Change-Id: I085d2026d1b366b1af9fd0e8ca3d815fd8288030
2016-01-20 12:45:26 -05: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
Chad Horohoe
3f7ecb4027 WebRequest::appendQuery*() functions no longer take $onlyquery
Deprecated since 1.25, unused anywhere

Change-Id: I52224635cfeaf4748abeaa07b0c92e7f452fa93f
2016-01-06 15:15:10 -08:00
Chad Horohoe
a40f39922f Remove WebRequest::appendQuery()
Deprecated in 1.25, nothing uses it. You should use appendQueryValue()
or appendQueryArray()

Change-Id: Ia2347a1eaf6d9c6cfc600947e577c08cd482a5ac
2016-01-06 15:04:30 -08:00
jenkins-bot
04fdc78370 Merge "Documentation: Remove paragraph about not creating a 2nd WebRequest" 2016-01-05 22:23:55 +00:00
Justin Du
f8450b63cb Split WebRequest.php classes
Change autoload.php file to accomodate the split

Bug: T122633
Change-Id: I0b2260da7cc086659fdd0894f7bb94798dff1163
2016-01-04 21:34:25 +00:00
Reedy
21dcd29a80 Add @since tags to FauxRequest::getRequestURL()/setRequestURL()
Change-Id: I6c104fe2df258eda15ebf8df089390dcdb80a3ef
2015-12-20 23:04:24 +00:00
Ori Livneh
7628a11d8e Remove .php5 entrypoints and $wgScriptExtension
* The '.php5' entrypoints were deprecated in I68b1ae842, $wgScriptExtension
  in I3690f78bc.
* Drop the associated ResourceLoader configuration variable, too. `mwgrep`
  shows no usage in the MediaWiki namespace.
* Keep the scriptExtension configuration parameter for FileRepo for people who
  would like to interoperate with older MediaWiki installations that still use
  '.php5'.

Change-Id: I17c8a15484b7e82cd5970d34e688109a2aae3840
2015-10-08 15:45:31 +01:00
Timo Tijhof
6d412cf028 Move WebRequestUpload class to its own file
Moving out of WebRequest.php. It's not even a subclass.

Change-Id: I87e5c01afe215a084e39b442c65d22d9d0cc1015
2015-10-06 19:24:58 -07:00
Amir E. Aharoni
d928aac86c WebRequest.php: Make lines shorter to make phpcs happier
Change-Id: Icdc91bc32c526065009b18ece34205aa765cfd46
2015-09-26 14:19:03 +00:00
umherirrender
3ab5510ef7 FauxRequest: Avoid header leak
Actually override initHeaders to avoid init of the header, if no header
was set.

The tests was taken from I4c06369968e.
Follows-up 578a0c082f.

Change-Id: I86b2a9bae2f5938374fd9e5e46997c3fdfe87e39
2015-09-16 16:52:58 +00:00
jeroendedauw
578a0c082f Remove unused private methods in FauxRequest
Change-Id: I49a0a8ced0819eeef3ff404fc14b0b90c36b0922
2015-09-15 19:08:22 +00:00
Timo Tijhof
45d7d21140 FauxRequest: Add @since for new setHeaders and setCookie methods
Follows-up 53b0df09ab.

Change-Id: Ia854aef848062624eccc6a5b25b7d1f1f8fbc444
2015-07-03 03:38:38 +00:00
Brad Jorsch
53b0df09ab Add cookies and improve headers in FauxRequest
For testing, it can be useful for a FauxRequest to actually contain
cookies. And for convenience, it's useful to allow setting headers by
passing an array rather than by making multiple calls to ->setHeader().

Change-Id: I3b84246e954aae594490927d2b0a57336af2e3a5
2015-07-02 12:43:02 -04:00
Gilles Dubuc
b276829806 Make proxy behaviour of detectServer() configurable
Bug: T75510
Change-Id: Ia6540962f8d913d925547189e101124f76d969c7
2015-06-22 21:19:22 +02:00
daniel
9f34e31d33 Allow limit and offset to be restricted in subclasses of QueryPage.php
Change-Id: Ib54b50619a0f412e53f92d48821221a243f19756
2015-06-18 19:51:10 +00:00
Alex Monk
e7c9096ecc HTTPS-ify links to Wikimedia's sites in MW core source
See https://blog.wikimedia.org/2015/06/12/securing-wikimedia-sites-with-https/

Ignoring SVN stuff because svn.wikimedia.org's SSL certificate has expired, and
ignoring wgSharedUploadPath because T25122 wants to get rid of it.

Also a couple of BZ -> phab changes

Change-Id: I02fd23ac6c30a4a4c718e57d4dedbc693dd653c0
2015-06-13 19:23:23 +01:00
Kunal Mehta
f6e5079a69 Use mediawiki/at-ease library for suppressing warnings
wfSuppressWarnings() and wfRestoreWarnings() were split out into a
separate library. All usages in core were replaced with the new
functions, and the wf* global functions are marked as deprecated.

Additionally, some uses of @ were replaced due to composer's autoloader
being loaded even earlier.

Ie1234f8c12693408de9b94bf6f84480a90bd4f8e adds the library to
mediawiki/vendor.

Bug: T100923
Change-Id: I5c35079a0a656180852be0ae6b1262d40f6534c4
2015-06-11 18:49:29 +00:00
Ori Livneh
9622c07f46 WebRequest::getHeader: add optional flag to get back list
* Add a stub FauxRequest::initHeaders method. This allows FauxRequest to
  use WebRequest's getHeader implemention, leading to less code duplication.
* Add an optional $flags parameter to WebRequest::getHeader. When the flag
  WebRequest::GETHEADER_LIST is set, treat the header as a comma-separated
  list of values (per RFC 2616 § 4.2) and return an array.
  (Initial use-case: Ibb292d241's treatment of If-None-Match header.)
* Add test.

See <http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html>.

Change-Id: I2760f57adfa7b886c84044a6e9348a47ac307229
2015-05-08 17:58:54 -07:00
Ori Livneh
667fa3e264 Make WebRequest objects time-aware
* Deprecate $wgRequestTime in favor of $_SERVER['REQUEST_TIME_FLOAT'], which is
  more accurate. Because $_SERVER['REQUEST_TIME_FLOAT'] is only set for PHP
  5.4+, set it to microtime( true ) in WebStart.php for back-compatibility.
* Add a 'requestTime' property to WebRequest objects, set to
  $_SERVER['REQUEST_TIME_FLOAT'] for WebRequest or the instance creation time
  for FauxRequest instances.
* Use that to provide WebRequest::getElapsedTime(), which gets the time since
  the request was initiated.
* In wfLogProfilingData(), get the user and request objects from the context
  object rather than from global scope.

Opportunistic clean-up: move the magic quotes check to WebStart.php and make
the error message more helpful.

Change-Id: I7e07e22eaf16b5141b80ad9f843285c542a127b7
2015-04-01 18:21:26 -07:00
Kunal Mehta
13975fe76a Use wikimedia/utfnormal library, add backwards-compatability layer
This drops support for the custom utf8 normal PHP extension in favor
of the intl extension.

Bug: T90825
Change-Id: Ifbaeb2ef684217cf6187ccc4fb4d303f89608300
2015-03-24 12:59:26 -07:00
Jaroslav Škarvada
89a5f17463 Fix HTTPS protocol detection
According to PHP documentation:
http://www.php.net/manual/en/reserved.variables.server.php
The $_SERVER['HTTPS'] is set to a non-empty value if the script was queried
through the HTTPS protocol. There is also note that for ISAPI with IIS, the
value is set to 'off' if the request was not made through the HTTPS protocol.

To follow the PHP documentation the $_SERVER['HTTPS'] == 'on' doesn't seem
to be the correct way how to detect the HTTPS protocol (there maybe e.g. '1'
instead of 'on').

Bug: 46511
Change-Id: I5675fed9b7d54711b96b25702181112ef3692f3c
2015-01-16 16:22:54 +00:00
Aaron Schulz
e369f66d00 Replace wfRunHooks calls with direct Hooks::run calls
* This avoids the overhead of an extra function call

Change-Id: I8ee996f237fd111873ab51965bded3d91e61e4dd
2014-12-10 12:26:59 -08:00