Commit graph

212 commits

Author SHA1 Message Date
jenkins-bot
970fc15f95 Merge "Move CRSF token generation to CsrfTokenSet" 2021-06-21 15:03:30 +00:00
Thiemo Kreuz
2ba01c7ee7 Remove some more comments that literally repeat the code
… including PHPDoc tags like `@return <type> $variableName`.
A return value doesn't have a variable name. I can see that
some people do this intentionally, repeating the variable
name that was used in the final `return $var;` at the end
of a method. This can indeed be helpful. I leave a lot of
these untouched and removed them only when it's obviously
wrong, or does not provide any additional information in
addition to what the code already says.

Change-Id: Ia18cd9f25ef658b08ad25b97a744897e2a8deffc
2021-06-18 21:23:56 +00:00
Petr Pchelko
6260074a8c Move CRSF token generation to CsrfTokenSet
Change-Id: Idf68f1cc63fb2e01e004ff353fcda026fa4ec10f
2021-06-18 12:24:19 -07:00
jenkins-bot
96c6af6878 Merge "Use null coalecing operators everywhere consistenctly." 2021-06-04 15:31:52 +00:00
Petr Pchelko
0dfa846653 Use null coalecing operators everywhere consistenctly.
Auto-generated with rector.

Change-Id: I4f27e10cf029bb067b7bc57d82f7a64e21ea8d42
2021-06-03 21:42:06 -07:00
vladshapik
484fe84177 Edit the documentation of SessionProvider, AbstractAuthenticationProvider::init
The documentation of SessionProvider::init says that the method can be used in implementation tests.
Now all tests must use SessionProviderTestTrait::initProvider in order to initialize a SessionProvider.
So the entire description after @internal was rewritten. Also the
similar note was added to the documentation of
AbstractAuthenticationProvider::init.

Bug: T283931
Change-Id: I1cde6fd12666ef3a7c9b1e33a718592c11cf9e29
2021-06-02 12:25:02 +03:00
Vlad.shapik
9763c48d17 Reapply "Hard Deprecate User ::getCanonicalName, ::isUsableName, ::isCreatableName""
This reverts commit ecf826a2ee.

Reason for revert: need to edit the patch and then it will be GTG in order to finish hard deprecating of User ::getCanonicalName, ::isUsableName, ::isCreatableName

Change-Id: I2f57f56728fcbeada96dc2228f07dc8bcaa5d4f6
2021-05-31 16:01:36 +03:00
jenkins-bot
297d1bfb0e Merge "Remove unused default values from class properties" 2021-05-13 00:58:34 +00:00
vladshapik
39d093a49f Hard deprecate the setters of SessionProvider class
Bug: T282256
Change-Id: I97244429bb4aa05ffdeda381f89db5dbda182d31
2021-05-12 19:49:50 +00:00
Thiemo Kreuz
6805f39a30 Remove unused default values from class properties
In all these cases the property is unconditionally set in
the constructor. The extra initialisation is effectively
dead code and an extra source of errors and confusion.

Change-Id: Icae13390d5ca5c14e2754f3be4eb956dd7f54ac4
2021-05-12 13:44:28 +02:00
Ppchelko
ecf826a2ee Revert "Hard Deprecate User ::getCanonicalName, ::isUsableName, ::isCreatableName"
This reverts commit b491279268.

Reason for revert: caused CentralAuth tests to fail.

Change-Id: Icb3ed094578df427622e0da2a7462645adcc3d6f
2021-05-05 02:14:47 +00:00
vladshapik
b491279268 Hard Deprecate User ::getCanonicalName, ::isUsableName, ::isCreatableName
Bug: T275030
Change-Id: I60689ee6519c2dbd6d000afa8ac05c3e6b7895d2
2021-05-04 21:20:50 +03:00
vladshapik
5c1a60a0ce Create an initialization method in the SessionProvider class
init() method was added to SessionProvider. It helps to inject
dependecies. Overridable postInitSetup() method was added to
SessionProvider. A provider can override this to do
any necessary setup.
SessionProvider ::setLogger(), ::setManager(), ::setConfig(),
::setHookContainer() were soft deprecated. Now developers must use
SessionProvider::init()

Bug: T275030
Change-Id: I958797881251572e4ec22e7dd9d13f74f7e216a3
2021-05-04 13:56:04 +03:00
Reedy
fb771021ea Use some more neutral language
Bug: T277987
Change-Id: Ieceb01f7a61693a0f03cc331213cb8f93163b8e9
2021-04-18 16:49:36 +01:00
jenkins-bot
0af0b25565 Merge "SessionManager: Document expectations for storage backend" 2021-04-14 15:20:37 +00:00
ZabeMath
15881aefe9 Avoid using User::isValidUserName()
User::isValidUserName is deprecated since 1.35 and should be replaced with the UserNameUtils service

Bug: T277398
Change-Id: Iaef995b992e2f38f651453092b23c928479e7d18
2021-03-14 18:04:12 +01:00
jenkins-bot
5ea464b234 Merge "Use static closures where safe to use" 2021-02-14 23:05:48 +00:00
Gergő Tisza
9c578c1416
Call __toString explicitly when passing an object to the logger
The logstash formatter for Monolog 2 doesn't do this automatically
anymore, and it wasn't really correct anyway to rely on a formatter
when we have no guarantee it's going to be used.

Follows up If92d60289fa925d19261ef912e2f2a5d31db31dc.

Bug: T269680
Change-Id: Ia7875346cec95fbc30bc4579ec8b7fb60e911d12
2021-02-12 22:08:02 +01:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Cole White
14f78ee2c1 Update SessionManager to pass session string representation to logger
Sending the object to the logger renders an object in the logging
pipeline.  This type-conflicts with other uses of this field as it is
expected to be a string.

Bug: T269680
Change-Id: If92d60289fa925d19261ef912e2f2a5d31db31dc
2021-01-26 09:51:56 -07:00
Timo Tijhof
2d32ab9271 SessionManager: Document expectations for storage backend
Bug: T270225
Change-Id: I2dcf0c979d8ad6e41e583bde056d21526b1bce9a
2021-01-08 18:08:54 +00:00
C. Scott Ananian
665eae14ac ParserTestRunner: share more code w/ MediaWikiIntegrationTestCase
Refactor the database setup code to share more code between
ParserTestRunner and MediaWikiIntegrationTestCase.  Made
`::setupAllTestDBs` static so it can be reused from
ParserTestRunner.

Made ParserTestRunner::addArticle more like
MediaWikiIntegrationTestCase::addCoreDBData().  Some additional
refactoring work could be done here in the future to share more code.

After the refactoring the ParserTestTables hook is no longer necessary
and so has been (soft) deprecated.  MediaWikiIntegrationTestCase
clones all database tables, so ParserTestRunner no longer needs to ask
extensions for a list of specific tables it should clone.  Cleaning up
the handful of extensions which define this hook will be left to a
future patch set.

Change-Id: I5124789fac333a664b73b4b4a1e801ecc0a618ca
2021-01-07 23:31:12 -05:00
Tim Starling
9af96ef4c7 Improve custom folding and grouping
PHPStorm can use custom folding regions defined in either the
VisualStudio style or the NetBeans style. The VisualStudio style is more
pleasing to the eye and also works as a vim foldmarker. So get rid of
the previous vim foldmarkers, and use region/endregion.

region/endregion need to be in a single-line comment which is not a doc
comment, and the rest of the comment is used as a region heading (by
both PHPStorm and vim). So to retain Doxygen @name tags, it is
necessary to repeat the section heading, once in a @name and once in a
region. Establish a standard style for this, with a divider and three
spaces before the heading, to better set off the heading name in plain
text.

Besides being the previous vim foldmarker, @{ is also a Doxygen
grouping command. However, almost all prior usages of @{ ... @} in this
sense were broken for one reason or another. It's necessary for the @{
to be in a doc comment, and DISTRIBUTE_GROUP_DOC doesn't work if any of
the individual members in the group are separately documented.

@name alone is sufficient to create a Doxygen section when the sections
are adjacent, but if there is ungrouped content after the section, it
is necessary to use @{ ... @} to avoid having the Doxygen group run on.
So I retained, fixed or added @{ ... @} in certain cases.

I wasn't able to test the changes to the trait documentation in Doxygen
since trait syntax is not recognised and the output is badly broken.

Change-Id: I7d819fdb376c861f40bfc01aed74cd3706141b20
2020-12-23 12:41:47 +11:00
Umherirrender
f46ca9a63c build: Updating mediawiki/mediawiki-phan-config to 0.10.5
Change-Id: I343d2bae626a3903eb1e67c05bf5caef4314b7dd
2020-12-12 14:42:25 +01:00
daniel
f95c7321c5 UserInfo: use UserFactory
This allows integration tests to control User instances by
setting a fake UserFactory service.

Change-Id: I006d18b3bc4e8c7eee5da243bac663b10238ae1c
2020-12-01 15:11:02 +00:00
Thiemo Kreuz
1fc8d79ac6 Remove documentation that literally repeats the code
For example, documenting the method getUser() with "get the User
object" does not add any information that's not already there.
But I have to read the text first to understand that it doesn't
document anything that's not already obvious from the code.

Some of this is from a time when we had a PHPCS sniff that was
complaining when a line like `@param User $user` doesn't end
with some descriptive text. Some users started adding text like
`@param User $user The User` back then. Let's please remove
this.

Change-Id: I0ea8d051bc732466c73940de9259f87ffb86ce7a
2020-10-27 19:20:26 +00:00
Daimona Eaytoy
d9ebc49147 Typehint SessionManager::getGlobalSession and RequestContext::getMain
These methods use a static property to cache the return value, and
although they're guaranteed to return an object (as per documentation,
current code, and current usage), some static analysis tool may fail to
understand this.

Change-Id: I4317e1bb11e9793de721356a579a7677137e52cc
2020-10-22 19:37:23 +02:00
Gergő Tisza
56aacd4467
SessionManager: Always log IP/UA in session-ip
Bug: T264799
Change-Id: I25257cde897db684a8438923487f80b09abe16c0
2020-10-09 09:45:22 -07:00
Gergő Tisza
d5d3c90152
Log IP/device changes within the same session
Store IP and device information in the session and log when
it changes. The goal is to detect session leakage when the
session is accidentally sent to another user, which is a
hypothetical cause of T264370. The log will be noisy since
users do change IP addresses for a number of reasons,
but we are mainly interested in the ability of correlating
user-reported incidents where we have a username to filter
by, so that's OK.

Based on I27468a3f6d58.

Bug: T264799
Change-Id: Ifa14fa637c1b199159ea11e983a25212ae005565
2020-10-08 13:13:25 -07:00
Gergő Tisza
c33a539a5c
Deduplicate SessionBackend::logPersistenceChange calls
If all goes well, this should cut INFO-level log volume on the
session channel to about a third.

Bug: T264793
Change-Id: I268b57747a1449456df2c98696807c50b05e7147
2020-10-08 10:48:42 -07:00
Gergő Tisza
a6cdedad8d
Log when SessionManager is emitting cookies
This is very noisy (logs several times in the same request), but
I'm not sure much can be done about that. It is a flaw in
SessionManager, which does call SessionProvider::persist/unpersist
that many times, and relies on cookie deduplication in WebResponse.
But it should give some idea of when cookies are emitted, and does
not log on normal requests (where no cookies are emitted) so it
shouldn't overload the logging backend.

Bug: T264793
Change-Id: I93733d73af1dfcf539a94b17cf5e4de76cc59748
2020-10-07 09:39:23 -07:00
jenkins-bot
72a90d3d06 Merge "Document hook names in hook interfaces." 2020-10-02 16:15:21 +00:00
Umherirrender
d790580fda Fix typos related to repeated words
Change-Id: Ibc187d95b003017255bc87adf56afae7a59bd3db
2020-09-27 10:25:36 +00:00
daniel
2e57447c58 Document hook names in hook interfaces.
Bug: T258665
Change-Id: Ifddbf57f8aa2e3eb0d5845601376cbafa08ed407
2020-09-27 12:03:12 +02:00
jenkins-bot
a5f4732261 Merge "Replace "@stable for implementation" with "@stable to implement"" 2020-07-13 09:31:44 +00:00
jenkins-bot
39705eb311 Merge "Replace "@stable for subclassing" with "@stable to extend"" 2020-07-13 09:31:38 +00:00
jenkins-bot
0270990f0b Merge "Replace "@stable for calling" by "@stable to call"" 2020-07-13 09:27:04 +00:00
daniel
e6e0ad2472 Replace "@stable for implementation" with "@stable to implement"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: I17e5e92e24c708ffc846945a136347670a3a20c7
2020-07-13 11:05:49 +02:00
daniel
3c50afa46b Replace "@stable for subclassing" with "@stable to extend"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: Ie32c1b11b3d16ddfc0c83a757327d449ff80b2e4
2020-07-13 11:00:30 +02:00
daniel
f7116bb3a2 Replace "@stable for overriding" with "@stable to override"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: I5ffbb91882ecce2019ab644839eab5e8fb8a1c5f
2020-07-13 10:57:12 +02:00
daniel
272db6afde Replace "@stable for calling" by "@stable to call"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: If560596f5e1e0a3da91afc36e656e7c27f040968
2020-07-13 08:55:28 +00:00
daniel
7572a152fc Annotate extensible classes.
This marks some base classes as stable for subclassing.

Bug: T247862
Change-Id: I7b77075849aa40960f2486b463e498a3ea8058e9
2020-07-09 11:07:38 +02:00
daniel
102c9573b3 Mark exceptions as @newable
Exceptions classes are nearly always value objects, and should in most
cases by newable.

Bug: T247862
Change-Id: I4faa8ec6ea8bc44086cfc8075b32d10eea61e9df
2020-07-08 17:51:38 +00:00
jenkins-bot
35e26a8d0e Merge "Annotate newable classes" 2020-07-07 18:46:12 +00:00
daniel
bd5c3d06a2 Annotate newable classes
This annotates classes that can safely be instantiated by
extensions, per the Stable Interface Policy.

Bug: T247862
Change-Id: Ia280f559874fc0750265ddeb7f831e65fd7d7d6a
2020-07-07 15:38:57 +02:00
Tim Starling
f8a7a1ace8 Support SameSite=None cookies
* Add $wgCookieSameSite, which controls the SameSite attribute for login
  cookies. This will need to be set to "None" on WMF and other wikis
  with a CentralAuth installation spanning multiple registrable domains.
* Add $wgUseSameSiteLegacyCookies, which causes a "legacy" cookie to be
  sent without a SameSite attribute whenever a SameSite=None cookie is
  sent. I used the prefix "ss0" since it's like SameSite version 0, and
  that's shorter than "legacy". It's a prefix instead of a suffix to
  avoid the need to update the VCL config which identifies cookie types
  by their name suffix.
* Simplify WebRequest::getCookie() removing the unnecessary unicode
  normalization. This was added by analogy with GET/POST, I don't
  believe it was ever necessary for cookies.
* Add WebRequest::getCrossSiteCookie(), which implements the read side
  of the legacy SameSite cookie support.
* Fix Doxygen formatting of the parameter list in
  WebResponse::setCookie().
* To work around the lack of SameSite cookie support in PHP 7.2, emulate
  setcookie() with header() where necessary.

Bug: T252236
Change-Id: I141ea114fea007a72a4f24bfc34dd81100854d68
2020-07-07 02:18:45 +01:00
Tim Starling
c75eef91bf Introduce $wgForceHTTPS
Add $wgForceHTTPS. When set to true:

* It makes the HTTP to HTTPS redirect unconditional and suppresses the
  forceHTTPS cookie.
* It makes session cookies be secure.
* In the Action API, it triggers the existing deprecation warning and
  avoids more expensive user/session checks.
* In login and signup, it suppresses the old hidden form fields for
  protocol switching.
* It hides the prefershttps user preference.

Other changes:

* Factor out the HTTPS redirect in MediaWiki::main() into
  maybeDoHttpsRedirect() and shouldDoHttpRedirect(). Improve
  documentation.
* User::requiresHTTPS() reflects $wgForceHTTPS whereas the Session
  concept of "force HTTPS" does not. The documentation of
  User::requiresHTTPS() says that it includes configuration, and
  retaining this definition was beneficial for some callers. Whereas
  Session::shouldForceHTTPS() was used fairly narrowly as the value
  of the forceHTTPS cookie, and injecting configuration into it is not
  so easy or beneficial, so I left it as it was, except for clarifying
  the documentation.
* Deprecate the following hooks: BeforeHttpsRedirect, UserRequiresHTTPS,
  CanIPUseHTTPS. No known extension uses them, and they're not compatible
  with the long-term goal of ending support for mixed-protocol wikis.
  BeforeHttpsRedirect was documented as unstable from its inception.
  CanIPUseHTTPS was a WMF config hack now superseded by GFOC's SNI
  sniffing.
* For tests which failed with $wgForceHTTPS=true, I mostly split the
  tests, testing each configuration value separately.
* Add ArrayUtils::cartesianProduct() as a helper for generating
  combinations of boolean options in the session tests.

Bug: T256095

Change-Id: Iefb5ba55af35350dfc7c050f9fb8f4e8a79751cb
2020-06-30 15:38:11 +10:00
daniel
db4ac19f7e Replace @protected tag
This patch replaces all usages of @protected in core.
The @protected tag was removed in cases where it was redundant or
contradictory. It has been replaced by @internal where usage outside of
core is not desired, and with @note for cases where use by extensions
is desired, but should be limited.

Bug: T247862
Change-Id: I5da208e5cb4504dde4113afb3a44922fd01325a3
2020-06-26 14:31:16 +02:00
daniel
f59bf8a22f Use @internal instead of @private per policy
https://www.mediawiki.org/wiki/Stable_interface_policy mandates the use
of @internal. The semantics of @private was never properly defined.

Bug: T247862
Change-Id: I4c7c6e7b5a80e86456965521f88d1dfa7d698f84
2020-06-26 14:14:23 +02:00
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00