Commit graph

2024 commits

Author SHA1 Message Date
C. Scott Ananian
94f193a894 SECURITY: Ensure emitted HTML is safe against Unicode NFC normalization
CVE-2025-32699

Ensure that Unicode NFC normalization can be applied to our HTML
output safely.  Even though the W3C officially recommends against
normalizing HTML

https://www.w3.org/International/questions/qa-html-css-normalization#converting

this is still easily done inadvertently, especially when using the
MediaWiki action API which normalizes parameters and results by
default.

See also I671648603c4635a35585c860b4857f5ea085e47f in Parsoid, and
T266140 / I2e78e660ba1867744e34eda7d00ea527ec016b71 for another similar
issue.

The following changes are made:

* The various HTML serializers (Remex/Tidy-derived, as well as the
  Html::* helpers) are tweaked to entity-escape U+0338 wherever it
  appears.

* Similarly, Message::escaped() is tweaked to entity-escape U+0338.

* Finally, a post-processing pass is added to the OutputTransform
  pipeline to catch any remaining U+0338 and entity-escape them.
  This catches U+0338 added during any of the previous OutputTransform
  stages (like TOC insertion, section edit links, etc).
  *When backporting* this code will likely need to be moved to
  ParserOutput::getText(), as the OutputTransform pipeline wasn't added
  until MW 1.42.

Bug: T387130
Change-Id: I66564e14e730f5393f4fa5780b80f24de6075af5
2025-04-10 15:56:06 +01:00
Kevin Israel
7d250d2109 Remove CryptHKDF and MWCryptHKDF
MWCryptHKDF was added ten years ago (in af66c04d39), and as far as
I can tell, it was never used anywhere. It seems unlikely that CryptHKDF
will be used in the future, at least in its current form, for several
reasons:

* PHP 7.1.2+ has hash_hkdf(), so HKDF() would not be needed.

* At the time MWCryptHKDF was created, access to a CSPRNG was dependent
  on server configuration: operating system, enabled PHP extensions,
  open_basedir, etc. The "clock drift" RNG used as a last resort was not
  considered to be secure or fast enough for generating large amounts of
  output.[1] random_bytes(), added in PHP 7, changed the situation.

* Depleting the input pool of Linux's RNG is no longer a concern; there
  is no more blocking output pool for /dev/random.[2][3] In 2022, this
  change and others, including some that improved performance,[4] were
  backported to stable kernels as old as 4.9.[5]

* $wgAuthenticationTokenVersion obviated the primary use case of
  quickly resetting the user_token field for all users, assuming all
  the existing tokens are unique.

* CryptHKDF seems to perform much slower than random_bytes(), at least
  on Linux, making it pointless to use given that the other reasons for
  its existence no longer apply.

[1]: https://bots.wmflabs.org/logs/%23mediawiki-core/20161004.txt
[2]: https://lwn.net/Articles/808575/
[3]: https://lore.kernel.org/all/cover.1577088521.git.luto@kernel.org/
[4]: https://www.zx2c4.com/projects/linux-rng-5.17-5.18/
[5]: https://lore.kernel.org/all/Yo3pmh9hiUFtQz77@zx2c4.com/T/

Change-Id: I29136fad826341d21728671aa30285d5551f1162
2024-11-10 22:49:37 -05:00
Timo Tijhof
e0f6f8f527 objectcache: Move RedisConnRef.php to /libs/objectcache/
Change-Id: I4c6a349afcc4039bec27413af9511639f8c0c4b0
(cherry picked from commit 72338de32b249a7cff0b758746c0896fd649e53b)
2024-11-07 08:40:54 +00:00
jenkins-bot
5c1f66bf58 Merge "WhatLinksHere: Allow extensible filters" 2024-10-22 07:52:25 +00:00
Huei Tan
ba14f43365 WhatLinksHere: Allow extensible filters
Add SpecialWhatLinksHereQueryHook hook that allow extensions
to modify the query builder to add more conditions based on
the filters added in the SpecialPageBeforeFormDisplay hook.

Bug: T216368
Change-Id: I221d4e0ad671feab6937719d4a2f894ad6154bb1
2024-10-21 14:27:53 +05:30
C. Scott Ananian
004cb43c56 ParserOutput: Introduce ParserOutput::getLinkList()
This deprecates a number of methods which returned arrays by reference and
exposed internal representation details of the ParserOutput.  It also
regularizes the return values to return consistent LinkTarget values,
working around the wide variety of different internal storage formats
used for links.

In the future, once these methods which expose the internal representation
are removed, we can simplify our internal storage as well.  But for the
moment we add the new getter without changing the internal representation.

Note that by returning TitleValue objects this new interface also provides
a means to fix the issue identified in T204792 where interwiki and namespace
prefixes were getting confused.  A TitleValue properly distinguishes between
these -- although the callers will still have to be careful to use it as
a TitleValue and not attempt to reparse it.

These methods also correctly handle fragments, which are present for the
language link type but stripped for the other linkt types.

Bug: T204792
Change-Id: I48a2077b9645124f83082afd953d6bf7a861270b
2024-10-18 13:24:10 -04:00
Sergio Gimeno
37985a198d ConditionalDefaultsLookup: allow to dynamically add conditions for evaluation
Why:
To facilitate the evaluation of conditions not directly
"known" by the lookup, eg: owned by extensions

What:
- Add ConditionalDefaultOptionsAddCondition hook which
runs before instantiating ConditionalDefaultsLookup allowing
to add conditions for evaluation in the $extraConditions
array.
- Evaluate the configured conditional default against the
 extra added conditions after evaluation of "known"
conditions.

Bug: T376918
Change-Id: Ife6f96397eafd61fdb40528aac315ddde1ef2774
2024-10-16 17:39:12 +02:00
jenkins-bot
5579e0647c Merge "[JsonCodec] Use wikimedia/json-codec to implement JsonCodec" 2024-10-16 00:54:33 +00:00
C. Scott Ananian
3bc172d0e4 [JsonCodec] Use wikimedia/json-codec to implement JsonCodec
This adds support for serializing/deserializing objects which
implement the JsonCodecable interface from the wikimedia/json-codec
library used by Parsoid.  JsonCodecable allows customizing the encoding
of objects of a given class using a class-specific codec object, and
JsonCodecable is an interface which is defined and can be used outside
mediawiki core.

In addition json-codec supports deserialization in the presence of
aliased class names, fixing T353883.

Backward and forward compatibility established via the mechanism
described in
https://www.mediawiki.org/wiki/Manual:Parser_cache/Serialization_compatibility

Test data generated by this patch was added in
I109640b510cef9b3b870a8c188f3b4f086d75d06 to ensure forward
compatibility with the output after this patch is merged.

Benchmarks:
                        PHP 7.4.33          PHP 8.2.19          PHP 8.3.6
                      BEFORE    AFTER     BEFORE    AFTER     BEFORE    AFTER
Serialize:            926.7/s  1424.8/s   978.5/s  1542.4/s  1023.5/s  1488.6/s
Serialize (assoc):    930.2/s  1378.6/s   974.6/s  1541.9/s  1022.4/s  1463.4/s
Deserialize:         1942.7/s  1961.3/s  2118.8/s  2175.9/s  2129.8/s  2063.5/s
Deserialize (assoc): 1952.0/s  1905.7/s  2107.5/s  2192.1/s  2153.3/s  2011.1/s

These numbers definitely do not have as many significant digits as
written here.  But they should be sufficient to demonstrate that
performance is not impaired by this patch and in fact serialization
speed improves slightly.

Bug: T273540
Bug: T327439
Bug: T346829
Bug: T353883
Depends-On: If1d70ba18712839615c1f4fea236843ffebc8645
Change-Id: Ia1017dcef462f3ac1ff5112106f7df81f5cc384f
2024-10-15 20:09:51 -04:00
James D. Forrester
a5387c7c20 Namespace all remaining classes in includes/parser
Bug: T353458
Change-Id: If02cc9b1ff78e26c1cf8c91ee4695845eb133829
2024-10-15 23:54:32 +01:00
jenkins-bot
23ec5ff94e Merge "Add namespace to maintenance/includes classes" 2024-10-15 22:50:33 +00:00
Reedy
fc2852f44f Remove MediaWikiVersionFetcher
Change-Id: I3a44557ed5e4ab06dde0eb8aaaba2be785faff27
2024-10-14 12:00:08 +00:00
jenkins-bot
3bf6821e2d Merge "Use MetricsTrait to DRY out stats code" 2024-10-14 10:14:31 +00:00
James D. Forrester
9f02d18eac Add namespace to maintenance/includes classes
Also a few other fixes of PHP class aliases spotted by phan.

Bug: T353458
Change-Id: Ie79d65722c47c24f8f20f1293355cfd3c2e8c2ad
2024-10-09 11:02:09 -04:00
Máté Szabó
16ec1a3703 Introduce minimal OTEL tracing library
In T340552, the official PHP OpenTelemetry client was effectively
rejected for inclusion in MediaWiki due to its size. Implement a minimal
tracing library instead that eschews conformance with the OTEL client
specification in favor of simplicity, while remaining capable of
emitting trace data in OTLP format and thus retaining compatibility with
any ingestion endpoint capable of handling OTLP.

In its current state, the library supports a basic feature set that
should be sufficient for basic tracing integration:

* Span creation, inclusive span activation and automatic parent span
  assignment,
* Span attributes and span kinds,
* Basic resource (process/request)-level metadata generation,
* Data export over OTLP.

Additional functionality, such as trace propagation, can then be
incrementally added to the library.

Bug: T340552
Change-Id: Ibc3910058cd7ed064cad293a3cdc091344e66b86
2024-10-09 15:55:31 +02:00
James D. Forrester
9203493606 Add namespace to remaining parts of Wikimedia\FileBackend
Bug: T353458
Change-Id: I49c843c9d8f6459c0fbf774afeea7a82fa564b59
2024-10-03 16:21:22 +00:00
jenkins-bot
4627fe60af Merge "Add namespace to remaining parts of Wikimedia\Mime and Wikimedia\Stats" 2024-10-03 14:16:24 +00:00
jenkins-bot
db7ee3db99 Merge "Add namespace to remaining parts of Wikimedia\ObjectCache" 2024-10-03 14:02:47 +00:00
jenkins-bot
831a027afd Merge "Add namespace to Wikimedia\Redis libs" 2024-10-03 13:59:08 +00:00
jenkins-bot
a80da8eacf Merge "resourceloader: Add/change ResourceLoaderModifyEmbeddedSourceUrls hook" 2024-10-02 16:12:30 +00:00
James D. Forrester
cc28acc455 Add namespace to remaining parts of Wikimedia\Mime and Wikimedia\Stats
Bug: T353458
Change-Id: If0137003ab625017d322d57870448a02569668c3
2024-09-27 16:19:10 -04:00
James D. Forrester
53b67ae0a6 Add namespace to remaining parts of Wikimedia\ObjectCache
Bug: T353458
Change-Id: I3b736346550953e3b2977c14dc3eb10edc07cf97
2024-09-27 16:19:10 -04:00
James D. Forrester
2144fef6d1 Add namespace to Wikimedia\Redis libs
Bug: T353458
Change-Id: I7a874e1ee1d41a75e34b8a6b6f4d065b5b812c43
2024-09-27 16:19:10 -04:00
James D. Forrester
9e5c1e8ac7 Add namespace to IDBAccessObject and DBAccessObjectUtils
Bug: T353458
Change-Id: I23cf7991f8792d4d000d1780463d8ce76dc0aee0
2024-09-27 16:19:10 -04:00
Bartosz Dziewoński
531ba3aad0 resourceloader: Add/change ResourceLoaderModifyEmbeddedSourceUrls hook
We've discovered some new requirements.

Follow-up to 31f614f732.
The hook was not in a release yet, so we can rename it.

Bug: T371530
Change-Id: I82d8ae69c27a38c45eab5d19c063f0b9515b8ec8
2024-09-27 20:28:30 +02:00
Bartosz Dziewoński
943d089008 Replace raw HTML copyright footer message with wikitext one
Replaces 'copyright' with 'copyright-footer' and 'history_copyright'
with 'copyright-footer-history' (the original still takes precedence
if set). Adds SkinCopyrightFooterMessage hook which works the same
way as SkinCopyrightFooter for the new messages. Allows disabling
the old messages by setting $wgAllowRawHtmlCopyrightMessages = false.

Co-Authored-By: Gergő Tisza <tgr.huwiki@gmail.com>
Bug: T45646
Change-Id: I5fd5607f8d43b6e934c8d4d35097cec430c56043
2024-09-26 16:18:52 +02:00
James D. Forrester
984076f98e Add namespace to includes/api classes
Bug: T353458
Change-Id: I3ea6b08c5018ba03ba45c5766e1f46e12f6b8597
2024-09-25 19:31:14 +00:00
Dreamy Jazz
6547b639d8 Add SpreadAnyEditBlock hook
Why:
* A hook is needed which is called when User::spreadAnyEditBlock
  is called, so that extensions which provide alternative blocking
  mechanisims (such as the GlobalBlocking extension) can spread
  their blocks when local blocks are spread.

What:
* Add SpreadAnyEditBlockHook which is called from User
  ::spreadAnyEditBlock when it is called except when the user is
  not registered.
** The hook is called even if the user is not locally blocked
* The return value of User::spreadAnyEditBlock is modified to
  return true if either a local block or alternative blocking
  mechanism spread blocks.
* Update UserTest to test this new behaviour.

Bug: T374857
Change-Id: Id302a6362d6177c89da9cdf4e677b3822ecb85f1
2024-09-24 12:04:20 +01:00
daniel
84fe1b9ccd REST: Introduce discovery endpoint
The discovery endpoint provides basic information about accessing the
wiki's APIs, as well as a directory of available modules.

Bug: T365753
Change-Id: I161aa68566da91867b650e13c8aadc87cd0c428c
2024-09-20 17:02:59 +00:00
C. Scott Ananian
ad8e0624a4 Use MetricsTrait to DRY out stats code
Change-Id: Ic123145e61d65cca38545ab2b33489dbeaf7bc31
2024-09-19 14:40:15 -04:00
Bartosz Dziewoński
7772b58bb9 auth: Add base class for TemporaryPasswordPrimaryAuthenticationProvider
Bug: T149003
Change-Id: I38c0de0ed52f4e35db443bc22d4ed110eafac97b
2024-09-16 23:09:01 +02:00
Dreamy Jazz
44cad41d03 Fix old autoblock unblock log entries with namespace in log_title
Why:
* The logging table on en.wikipedia.org contains an entry from
  2005 which is an unblock of an autoblock. However, the log_title
  contains the namespace, which makes the code that looks for
  logs which target an autoblock fail (because it checks for the
  first character being '#').
* Fixing the log_title to remove the 'User:' prefix from rows which
  are autoblocks (i.e. searching for log_titles which start with
  'User:#') should address the exceptions seen on Special:Log for
  these rows.
** The search can be limited to rows which have the 'unblock'
   log_action, as this has only been seen for this type of log.

What:
* Create fixAutoblockLogTitles.php which searches for the entries
  and then updates the log_title value to no longer include the
  'User:' prefix
** The queries to search are split, such that the expensive LIKE
   query is performed on batches of row IDs. If the LIKE query is
   applied directly to all rows in the table, the query takes 30s
   to run on WMF production.
* Add this maintenance script to update.php. It will be run once
  as the class extends LoggedUpdateMaintenance.
* Test the newly added maintenance script to ensure it works.

Bug: T373929
Change-Id: Ia62db56eda456bb764303b5f4b5a29be8f2d8fff
2024-09-13 12:18:32 +00:00
Timo Tijhof
8268b5e72c
objectcache: Improve overall BagOStuff class docs
Fix file doc blocks while at it.

> Remove duplicate description from file block in favour of class doc.
> This reduces needless duplication and is often incorrect or outdated,
> and helps make file headers more consistently (visually) ignorable.
>
> Add missing `ingroup` to class doc (and remove any from file doc)
> as otherwise the file is indexed twice (e.g. in Doxygen) which makes
> navigation on doc.wikimedia.org rather messy.
>
> Ref https://gerrit.wikimedia.org/r/q/message:ingroup+is:merged+owner:Krinkle+branch:master

Bug: T364652
Change-Id: Icc36566da1c7190b0f4269719f34d3d6a83026c1
2024-09-11 11:55:10 +01:00
jenkins-bot
dbb984360a Merge "objectcache: Remove WinCache support" 2024-09-06 01:19:59 +00:00
Máté Szabó
f89aa38f69 objectcache: Remove WinCache support
WinCache is an APCu equivalent for use with Microsoft IIS, but in recent
years has been unmaintained and lacks support for PHP 8 and newer.[1]
So, remove support for it as MediaWiki will be raising the minimum
supported PHP version to 8.1.

[1] https://www.php.net/manual/en/install.windows.recommended.php

Bug: T365691
Change-Id: I4d2dc01a9119bb1f858132f0146b894750c1e86d
2024-09-05 17:59:26 +00:00
Fomafix
b43860cc09 Add new hook OutputPageRenderCategoryLink
This allows to change the category link rendering by extension
CategoryTree without missing update of mCategoryData and mCategories
which leads to wgCategories = [] (T372155).

The new hook will be used in extension CategoryTree by
Ic86f210474cbc0e2dcebf664cf2309a4a4408f60.

Bug: T372155
Change-Id: Id82a77a57d1f12233d974ea4c1b093f50c5ab74f
2024-09-05 15:53:43 +00:00
jenkins-bot
7ffa04d155 Merge "Remove UIDGenerator, deprecated since 1.35" 2024-09-05 11:01:25 +00:00
Ebrahim Byagowi
c0d1f7694c objectcache: Remove ReplicatedBagOStuff, deprecated since 1.42
Bug: T352481
Change-Id: I4e1ee5680b7ba0207dfe30a1208db35eca07e218
2024-09-04 20:21:29 +00:00
Ebrahim Byagowi
f903bae012 Remove UIDGenerator, deprecated since 1.35
Change-Id: I5e47ecd560218df7e48af68e6aee351bc2a57823
2024-09-04 14:38:30 +03:30
jenkins-bot
d7a2a2bf56 Merge "recentchanges: Move rcfeed/ to includes/recentchanges/RCFeed/" 2024-08-30 09:03:43 +00:00
Aaron Schulz
3833d2d3d3 rdbms: remove deprecated MaintainableDBConnRef class
Bug: T373655
Change-Id: I1d1ccb862d4356af146ee39f0fd4081acd82a9ce
2024-08-30 01:19:51 +00:00
Timo Tijhof
8fb118cb8b recentchanges: Move rcfeed/ to includes/recentchanges/RCFeed/
It is part of the component at
https://phabricator.wikimedia.org/tag/mediawiki-recent-changes/
and
https://www.mediawiki.org/wiki/Developers/Maintainers
and
since Ifac20da51f7e809f under the same "Recent changes" doc group.

The Maintainers list oddly enough lists only rcfeed and completely
forgets the majority of it under /includes/changes (or now,
/includes/recentchanges).

Bug: T364652
Change-Id: I94e6705672c1e2821bdc726aa7a383d9e7c1f7b5
2024-08-29 03:51:40 +01:00
jenkins-bot
3abfedbcbb Merge "auth: Add AuthManagerVerifyAuthentication hook" 2024-08-27 01:16:31 +00:00
jenkins-bot
8cf23d37ef Merge "auth: Add AuthManagerFilterProviders hook" 2024-08-27 01:16:14 +00:00
Gergő Tisza
e3cea8e11f auth: Add AuthManagerVerifyAuthentication hook
Add a new hook that can be used to prevent authentication just
before AuthManager takes the main action (writing the session
for login, creating the local user account for account creation).

The driving use case is a wiki which supports both a local and
a central (wiki-farm-level) login or signup flow - various
security options (such as 2FA) are needed during local login
but unnecessary during central login (which will have those
security features centrally), so we need to skip much of the
security when the user is taking the central route, and a bug
in how that's done could result in circumvention of security
features during local login. The hook makes it easy to inspect
and potentially interrupt login near the end, when we know for
sure what route it took. (Specifically, we know which primary
provider was used. The hook doesn't expose other details,
such as the list of preauth or secondary provders that were
invoked, because they were not needed for the immediate use
case, but they are easy to add in the future.)

The hook is called after the secondary providers for login
and before them for account creation, since secondaries can
interrupt login but cannot interrupt account creation.

A shortcoming is that since the hook is called after a primary
provider succeeded, it cannot prevent the primary provider from
doing work, ie. it cannot prevent creation of the remote account
during account creation (although it will prevent the creation
of the local account). This is not great but acceptable, since
creating a new account isn't very security-sensitive.
This also means the hook would not be useful during account
linking, as AuthManager does not do anything there, all the work
happens in the primary provider. This is even less great but
few authentication extensions implement account linking.

The hook is not called for authentication happening via
CreatedAccountAuthenticationRequest, which is a weird internal
hack hook handlers should not have to know about.

Also rename a confusingly named variable.

Change-Id: I835b2fe2f43e6e81f23348165cbb9c93832e6583
2024-08-26 23:57:31 +00:00
Gergő Tisza
cde00b5585 auth: Add AuthManagerFilterProviders hook
Allow disabling authentication providers. This allows for
extensions to replace core providers with their own.

This is using the $wgAuthManagerAutoConfig keys instead of
AuthenticationProvider::getUniqueId() as the keys to filter.
This makes it more useful for site administrators, and also
it's probably the better known of the two identifiers so
more intuitive.

No effort is made to prevent the hook from filtering
differently in different steps of the same authentication
process.

Bug: T369180
Change-Id: If5435b54a4fc08f685c04fc10eb44c6d72cd78fa
2024-08-26 23:56:49 +00:00
Dreamy Jazz
feba425a10 Remove fixDefaultJsonContentPages.php
Why:
* The fixDefaultJsonContentPages.php maintenance script was added
  in 2986d47c90 which was MW 1.27
* Per the version policy, wikis wishing to upgrade to MW 1.43
  should upgrade via 1.35 or 1.39 before moving to 1.43.
* As such, this script will have been already run for any wiki
  upgrading to 1.43 and therefore this script is unused.
* Removing the script is useful to reduce the amount of untested
  code in the maintenance directory and reducing unnecessary
  maintenance on now unused code.

What:
* Remove fixDefaultJsonContentPages.php

Bug: T373335
Change-Id: Ie20f55c6a8723573aa7e9acd67766af9dfb67269
2024-08-26 13:17:04 +00:00
Dreamy Jazz
21fae91b4a Remove populatePPSortKey.php
Why:
* The populatePPSortKey.php maintenance script was added in
  993ce4d411 which was in at
  least MW 1.34.
* Per the version policy, wikis wishing to upgrade to MW 1.43
  should upgrade via 1.35 or 1.39 before moving to 1.43.
* As such, this script will have been already run for any wiki
  upgrading to 1.43 and therefore this script is unused.
* Removing the script is useful to reduce the amount of untested
  code in the maintenance directory and reducing unnecessary
  maintenance on now unused code.

What:
* Remove populatePPSortKey.php

Bug: T373334
Change-Id: Iaa86bb193bf8feae9f5e2fe33255182e864d2e4f
2024-08-26 13:16:48 +00:00
Dreamy Jazz
30668e638f Remove populateBacklinkNamespace.php
Why:
* The populateBacklinkNamespace.php maintenance script was
  added to update.php in MW 1.24 in
  b8c038f678
* Per the version policy, wikis wishing to upgrade to MW 1.43
  should upgrade via 1.35 or 1.39 before moving to 1.43.
* As such, this script will have been already run for any wiki
  upgrading to 1.43 and therefore this script is unused.
* Removing the script is useful to reduce the amount of untested
  code in the maintenance directory and reducing unnecessary
  maintenance on now unused code.

What:
* Remove populateBacklinkNamespace.php

Bug: T373333
Change-Id: Ia70fdd5c5ae087d7f5bdf4499185701bbb106c1f
2024-08-26 13:16:04 +00:00
Dreamy Jazz
de1f704035 Remove addRFCandPMIDInterwiki.php
Why:
* The addRFCandPMIDInterwiki.php maintenance script last had
  it's update key modified in MW 1.23 in commit
  bd38435848.
* Per the version policy, wikis wishing to upgrade to MW 1.43
  should upgrade via 1.35 or 1.39 before moving to 1.43.
* As such, this script will have been already run for any wiki
  upgrading to 1.43 and therefore this script is unused.
* Removing the script is useful to reduce the amount of untested
  code in the maintenance directory and reducing unnecessary
  maintenance on now unused code.

What:
* Remove addRFCandPMIDInterwiki.php

Bug: T373331
Change-Id: Ie6791c0cc2cfab5e09aa0b1c7ddcea1099cd1f79
2024-08-26 13:15:41 +00:00