Commit graph

362 commits

Author SHA1 Message Date
Gergő Tisza
b1adf3c728 SECURITY: Allow extensions to supress the reauth flag on login
CVE-2025-6926

This is a workaround for extensions with some sort of "autologin"
implemented via the login page to indicate that the login flow
didn't involve the user actually logging in, it merely copied
some central login state, and so isn't appropriate for the
reauthentication flag.

This isn't the best way to provide an interface to extensions
(if we keep it, a more explicit interface, such as a
SessionPropertiesAuthenticationRequest object that's part of
the initial request set and can be modified by providers,
and can also be used for the "remember me" flag, would be
nicer), and maybe the whole approach of letting extensions
suppress the reauthentication flag is not the best way of
handling the problem in the first place, but it's simple
which is important for a security patch.

Bug: T389010
Change-Id: Ifce73837b25b0caad2d3d3cba000cceb0184c29d
2025-06-30 19:58:42 +01:00
Gergő Tisza
3340302f40 SECURITY: Do not treat autocreation as login for reauthentication
CVE-2025-6597

Auotcreation doesn't necessarily involve real-time user
identification, it can be based on some provider identifying the
user based on a session cookie or similar low-fidelity information.
Do not restart the reauthentication timer.

Bug: T389009
Change-Id: Icfb4d0ffe71a92421e8630a92ae302cc459aa9d6
2025-06-30 19:58:42 +01:00
Kosta Harlan
9d3de690e0 Use anonymous user when creating named account from temp account
Why:

- Using an anonymous user object at the start of account creation helps
  ensure that downstream code paths do not record the association
  between a temporary account and a named account

What:

- Use an anonymous user object during account creation initiated by
  temp account users
- Update the session to use the anonymous user and set the request
  context user based on the session user
- Ensure the temp account username is removed from the session, to avoid
  issues where account creation fails and code thinks that a temporary
  account username is already defined for the session
- Add a test to exercise this code path

Bug: T393628
Change-Id: I6d2df8c1d842c4fefa916ed395479f479a0051eb
(cherry picked from commit 3d80e63f109834b90a83597d6d924895b2c6ae71)
2025-05-29 12:06:33 +00:00
James D. Forrester
31509b74d9 ButtonAuthenticationRequest: Add AllowDynamicProperties directive
Bug: T381068
Change-Id: I779f2f995df1c330ce049daef2702f1af8569c33
(cherry picked from commit b691c3897a77cb0b2544f5b010bf08a8ea9b35f0)
2024-12-12 21:45:31 +00:00
Kevin Israel
7be3c1bc53 AuthManager: Add constants for callMethodOnProviders()
Why:

- Calls to callMethodOnProviders() specify bitmasks as decimal literals,
  so it is not clear which authentication providers are being called
  without referring to the doc comment and converting to binary.

What:

- Add four new private constants: three that match the values specified
  in the doc comment, and one that is the bitwise OR of all the others.
- Use them throughout the class.

Change-Id: Ib67e5174f00a080e79f0b6f35c0eeec4b95b8d8e
2024-10-18 03:20:09 -04:00
Umherirrender
e662614f95 Use explicit nullable type on parameter arguments
Implicitly marking parameter $... as nullable is deprecated in php8.4,
the explicit nullable type must be used instead

Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a

Break one long line in SpecialPage.php

Bug: T376276
Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
2024-10-16 20:58:33 +02: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
7772b58bb9 auth: Add base class for TemporaryPasswordPrimaryAuthenticationProvider
Bug: T149003
Change-Id: I38c0de0ed52f4e35db443bc22d4ed110eafac97b
2024-09-16 23:09:01 +02:00
jenkins-bot
09121089f4 Merge "auth: Disable irrelevant account creation fields for temp users" 2024-09-10 20:05:43 +00:00
Máté Szabó
d150c66840 auth: Disable irrelevant account creation fields for temp users
Why:

- When signing up for an account, temporary users are currently forced
  to provide a reason for creating an account, and also have the option
  to send a temporary password to an email address.
- Neither of these options are useful for temporary users wanting to
  create a full user account.

What:

- Don't show these two form fields on Special:CreateAccount for temporary users.
- Add a functional test for the temporary user account creation flow.

Bug: T328718
Change-Id: Ie545857f7647be89d9462ec2b0def48690f0a2bf
2024-09-10 16:45:56 +02:00
Derick Alangi
361e056b17
SUL3: Enable multiple auth providers to refresh "remember me" status
This allows a primary auth providers to update the "remember me" status
of another primary provider in the same login request flow. If authentication
that happened elsewhere and a "remember me" / "keep me logged in" (extended
login period is selected), the value of this action applied by the remote
primary provider should be applied to the local wiki when the user is
redirected back to continue authentication there.

This is useful because:

In the case of Wikimedia's central domain wiki in SUL3 mode, we want to
apply the remember me (keep me logged in) flag value from the central domain
to the local domain.

Bug: T369668
Change-Id: I6e2e2d892d2b777cb4757c7c0d222afad9da506c
2024-09-10 10:05:00 +01:00
Erik Bernhardson
2e5b551a9c auth: Pass canAlwaysAutocreate from session to pre-auth providers
Session providers can provide a `canAlwaysAutocreate` flag which
indicates account creation is exempt from autocreate permission
checks. This is used, for example, for providers that provide
users for supporting applications in a wiki farm.

Pass that information along to pre-authentication providers so
they can respect the intent of the flag. We cannot simply skip
pre-authentication, it's used for non-permission-related things
like preventing CentralAuth username conflicts.

Bug: T373778
Change-Id: Ie3aeaf48e615e2fb85b2069203ab91ca0127ae05
2024-09-06 12:01:58 -07:00
Umherirrender
e44aee1f74 auth: Add missing documentation to class properties
Add doc-typehints to class properties found by the PropertyDocumentation
sniff to improve the documentation.

Once the sniff is enabled it avoids that new code is missing type
declarations. This is focused on documentation and does not change code.

Change-Id: Ib6081f5519d2294bb14f81bf399f9c45315f2b69
2024-09-01 11:27:45 +02:00
jenkins-bot
ceb2e9b2bd Merge "Revert "auth: Relax AuthManager session state check while cde00b55 is deployed"" 2024-08-29 14:57:20 +00:00
Gergő Tisza
bf100ed940 Revert "auth: Relax AuthManager session state check while cde00b55 is deployed"
This reverts commit 9c62cd1af5.

Temporary fix, not needed anymore.

Change-Id: I64211d50433f9b66c2599e5acca8e7ff5923b36f
2024-08-29 07:03:29 +00:00
jenkins-bot
e201b5414f Merge "PasswordReset: remove $wgAllowRequiringEmailForResets feature flag" 2024-08-29 02:13:46 +00:00
jenkins-bot
a0b37a5ac8 Merge "auth: Relax AuthManager session state check while cde00b55 is deployed" 2024-08-28 16:33:32 +00:00
Gergő Tisza
9c62cd1af5
auth: Relax AuthManager session state check while cde00b55 is deployed
Follows up If5435b54a4fc08f685c04fc10eb44c6d72cd78fa.

Bug: T373504
Change-Id: I7cf157f04028a69f5893c9524c1d9a277033ad38
2024-08-28 15:37:41 +02:00
MusikAnimal
ef14cd41c3 PasswordReset: remove $wgAllowRequiringEmailForResets feature flag
Update a few tests that relied on the feature flag to ignore
the 'requireemail' preference on "User1" to instead use "User2",
who doesn't have the preference set.

Bug: T242406
Change-Id: I996d3996272d704a071d1d2094c3568247b80f98
2024-08-28 00:55:43 +02:00
Gergő Tisza
dddc54d5f0
auth: Fix documentation of AuthManagerVerifyAuthentication hook
Follows up I835b2fe2f43e6e81f23348165cbb9c93832e6583.

Change-Id: Ie7e8b57bfb3e7a0caf038446ece21d3cfa6df9e9
2024-08-27 11:45:25 +02: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
Gergő Tisza
123dadc32d
Clean up after I04932d84aa0b0b5939706f3905f0fe7700d81327
$flags is not used anymore.

Bug: T369372
Change-Id: I5456f88ebb78d2fcac685efd4a1f7a9f60d2bc0e
2024-08-24 16:53:33 +02:00
James D. Forrester
bc662aec9b Move Language and friends into Language namespace
Bug: T353458
Change-Id: Id3202c0c4f4a2043bf97b7caee081acab684155c
2024-08-10 13:36:30 +02:00
Aaron Schulz
8454bf2314 deferred: pass $fname to MWCallableUpdate callbacks and improve comments
This is more convenient for callers since they can avoid the pattern
of setting $fname to __METHOD__ and needing $fname in the "use" clause.
This is also more consistent with AutoCommitUpdate/AtomicSectionUpdate.

Remove @since tags from @internal MWCallableUpdate class.

Change-Id: I67c58897dc366a55f43e0a61d56064b26d520c17
2024-08-08 15:50:00 +00:00
Ebrahim Byagowi
fab78547ad Add namespace to the root classes of ObjectCache
And deprecated aliases for the the no namespaced classes.

ReplicatedBagOStuff that already is deprecated isn't moved.

Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
2024-07-10 00:14:54 +03:30
Kosta Harlan
742fd566bf AuthManager: Read from primary in account autocreation
Why:

- User::loadFromId must avoid doing a replica read when the newly
  autocreated user record isn't replicated yet; that would turn $user
  into an anonymous user object, and eventually log the user out.
  The old code tried to avoid this by using the same recency flag
  for which UserIdentityLookup::getUserIdentityByName() returned a
  non-anonymous user identity, but that's not actually a guarantee
  that the user is in the database, because getUserIdentityByName()
  has an internal in-process cache.
- For a specific example of this, Icf6be65a91437aa32684769c2858 broke
  temp account autocreation because inserting the log entry triggered
  ActorNormalization::acquireActorId() which set the in-process cache.
  With this patch applied, temp account autocreation will work again
  on wikis with database replication setup.

What:

- Use READ_LATEST flag when loading a user in an account
  autocreation context
- See also I5456f88ebb78d2fcac685efd4a1f7a9f60d2bc0e for a proposed
  follow-up to this patch

Bug: T369372
Change-Id: I04932d84aa0b0b5939706f3905f0fe7700d81327
2024-07-08 19:18:29 +00:00
Derick Alangi
493ffea9e9
Introduce hook to preserve query params after authentication
This hook enables extensions such as CentralAuth to preserve and
use query parameters needed for an authentication flow. Since there
is a provider that handles logins in a different wiki (central login
wiki), and movement to a different URL, this hook preserves query
parameters that can be used between these requests.

Bug: T363483
Bug: T362713
Change-Id: I86e629b07e6e4a0f1d1a4c78a6c77d41b4d68e18
2024-07-08 13:37:54 +02:00
Dreamy Jazz
d64c0ef9b3 Don't link temporary account and named account in newusers log
Why:
* When a temporary account creates a named account, the 'newusers'
  log currently links the temporary account username and the new
  named account.
* This is an issue because temporary accounts are intended to be
  anonymous and there is no path for a temporary account to
  link their contributions to their new account. As such, there
  should be no link between them.

What:
* Update AuthManager::continueAccountCreation to only mark the
  performer of the 'newusers' log entry as the creator account
  if the creator is named.

Bug: T364716
Change-Id: Ib95374949c5c72c9f7ee665943c16d177f2e31c0
2024-06-20 13:59:14 +01:00
Umherirrender
472891385d Use namespaced classes (2)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Id9f3e775e143d1a17b6b96812a8230cfba14d9d3
2024-06-16 20:23:55 +02:00
Wandji69
1665ea876f User objectCacheFactory methods not deprecated ObjectCache methods
Bug: T363770
Change-Id: I2335b315bec6a540409492df4891c518640966d5
2024-06-06 09:59:24 +01:00
Ebrahim Byagowi
b5727d94b5 Import InvalidArgumentException at top of the source
It was asked in a patch review to apply fully import
InvalidArgumentException where possible. I was guessing some
of my other already merged patches have but turned out such
thing exists other places style so for the sake of consistency
I've turned rest of inline import of the specific exception at
top of the file.

There are instances of source files that aren't in any namespace but
have fully qualified import which this patch doesn't touch.

Change-Id: I4071fc698b65746d9594cf4d5f45bae82843d436
2024-05-19 23:57:44 +03:30
Reedy
5ab70409f5 Namespace includes/password
Bug: T353458
Change-Id: I1a701b5b7ff65356692abb0efde9a2207b6135b6
2024-05-18 16:17:38 +01:00
jenkins-bot
5559c60b15 Merge "AuthManager: perform auto-creation as target user" 2024-05-04 19:33:42 +00:00
jenkins-bot
e5699d2e21 Merge "Formally deprecate code marked with @deprecated" 2024-05-04 12:47:59 +00:00
James D. Forrester
3ed6668745 Formally deprecate code marked with @deprecated
Some of these have been marked in-code as deprecated for a long while,
but haven't ever been announced in the RELEASE-NOTES (and later,
HISTORY) file, so let's mark them up now so we can get the ball rolling
at least.

Per Gergo, the AuthManager one was 'born deprecated' and should only
have been used by humans also reading the deprecation notice given in
the code, and indeed no uses are known to code search, so also emit
deprecation warnings there immediately; others will have to wait until
uses have been migrated.

Change-Id: I0c1c71d8f4293623039302da35d58d2a24367e97
2024-05-03 18:25:03 +03:00
Kosta Harlan
18811c59f0
AuthManager: Add setRequestContextUserFromSessionUser method
Why:

- We want to be able to reuse this method in other places, e.g. in
  temporary user account autocreation

What:

- Move LoginSignupSpecialPage's setSessionUserForCurrentRequest method
  into AuthManager, while splitting out the logic that is specific to
  LoginSignupSpecialPage

Bug: T364121
Change-Id: I9c96420eca4a756cc846e4ff16e7698365b044d8
2024-05-03 17:25:14 +03:00
xtex
50dd99eefb
AuthManager: perform auto-creation as target user
By doing this, auto-creation get available for users who use blocked IP and hold ipblock-exempt or globalblock-exempt, as autocreateaccount permission is checked on the user theirself rather than on anonymous IP user.

Bug: T316303
Change-Id: I2ad825317e900e865fffa39d4ea644f07beb4cf8
Signed-off-by: Bingwu Zhang <xtexchooser@duck.com>
2024-05-03 21:35:42 +08:00
Umherirrender
8d97313f81 Fix some line indent
Change-Id: I8f82724197d20f9289d80e138d80310f1eab29f2
2024-04-20 00:25:15 +02:00
Umherirrender
723134eade Add explicit parentheses around mixed boolean operator
Mixing different binary boolean operators within an expression
without using parentheses to clarify precedence is not allowed (T358966)

Change-Id: I24ca752d5dac7c948fdbcabf721f6f0aef8a466f
2024-03-23 01:58:59 +01:00
Umherirrender
f3524224f0 build: Fix line indents
Fixed SkinModuleTest::provideGetFeatureFilePathsOrder as nesting of
arrays for parameters is wrong

Change-Id: I9875008adf62d284c48662ebfbd245d72e5be064
2024-03-11 00:14:16 +01:00
Sergio Gimeno
999d894a51 AuthManager: add creator to AuthManagerLoginAuthenticateAudit calls
Why: the authentication mechanism replaces the user in session
(eg: anon, temporary user) for the logged in user in login
authentication requests. As a result neither postAuthentication
interface in AbstractPreAuthenticationProvider or the
AuthManagerLoginAuthenticateAudit hook provide information about
the user that performed the request, the "creator"

What: add the performer user of login requests to the $extraData
array when calling AuthManagerLoginAuthenticateAudit

Bug: T356249
Change-Id: I487c0da87a7215d3a49a8c432109205f8789247b
2024-03-05 09:57:06 +01:00
James D. Forrester
eeb5a740b3 Namespace Message, move to appropriate directory
Bug: T353458
Change-Id: I088cbc53fbcdb974e5b05b45a62e91709dacc024
2024-02-14 15:10:36 -05:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
jenkins-bot
4842f12bb7 Merge "Drop deprecated configs $wgMinimalPasswordLength and $wgMaximalPasswordLength" 2024-02-05 13:59:44 +00:00
Gergő Tisza
c92baadd1e AuthManager: Be consistent about the remember flag on autocreate
With Id3a316e relying on calling autoCreateAccount() multiple times, make sure the various login paths behave the same.

Change-Id: I3d3a1c9d4d8146f24451a7e9e5f407a6b24a3156
2024-02-05 11:07:40 +00:00
Amir Sarabadani
2d66025fdf Drop deprecated configs $wgMinimalPasswordLength and $wgMaximalPasswordLength
Soft-deprecated since 1.26 and hard-deprecated since at least
I9776d11d4e2d184 (1.39).

Not set in production.

Change-Id: I55e4569c5a40f77a719bc7ab1924eaa706e0da53
2024-02-01 16:29:05 +01:00
Erik Bernhardson
56ca271a45 SessionProvider: add ability to declare maintenance users
Adds a new method to the SessionProviderInterface that declares if the
session provide is exempt from user creation authorization.  This is
intended to support use cases where the SessionProvider is providing
access to maintenance related users external to MediaWiki itself. For
example in a supporting application to a wiki farm. This lets the
SessionProvider declare that account creation, in it's context, is
allowable even if anonymous account registration is disabled.

Bug: T345185
Change-Id: Iab3d93a3457e73eff408c1938fbdcb01d8be9a7a
2024-01-24 14:27:54 -08:00
Amir Sarabadani
014bc61006 Remove more indirect calls to IDBAccessObject::READ_* constants
Found via (?<!IDBAccessObject)::READ_

We are planning to deprecate and remove implementing IDBAccessObject
interface just to use the constants.

Bug: T354194
Change-Id: I89d442fa493b8e5332ce118e5bf13f13b8dd3477
2024-01-23 15:42:38 +01:00
Amir Sarabadani
72a8c3b433 Introduce DBAccessObjectUtils::getDBFromRecency()
And general clean up of db connection handling in core

Bug: T354194
Change-Id: Icb3685f1d7f8d1f4bcadf8e292ddf9450180fcdb
2024-01-19 16:54:05 +01:00