Page MenuHomePhabricator

Application Security Review Request : SUL3
Closed, ResolvedPublic

Description

Project Information

Codebase/patches:

The project spans multiple existing codebases (mainly CentralAuth, to a lesser extent operations/mediawiki-config and core's AuthManager component); it did not involve the creation of new repositories.

The core SUL3 logic is in four CentralAuth files: CentralAuthRedirectingPrimaryAuthenticationProvider and RedirectingLoginHookHandler are responsible for authentication itself, SsoHookHandler,FilteredRequestTracker and CentralAuthSsoPreAuthenticationProvider for handling the shared domain approach (T363695), with SharedDomainUtils containing various helpers.

The configuration logic lives in the mediawiki::sites/vhosts hiera key for puppet (this is for Beta; something similar will have to be set up for production), a domain lookup override in MWMultiVersion, and two code blocks (1, 2 in CommonSettings.php).

The more important patches:

The full list of relevant patches can be found via the #sul3-migration hashtag.

Description of the tool/project:
SUL3 changes the login and signup workflows (and in the future, other authentication-related workflows like credentials change) used on most Wikimedia wikis so that their user interaction part will happen on the central domain. See T345249: Mitigate phase-out of third-party cookies in CentralAuth for motivation. This consists of roughly the following parts:

  • Creation of a new central cookie domain (auth.wikimedia.org) that can be served by any wiki
    • Special-casing auth.wikimedia.org in the configuration loading layer so that, instead of mapping the domain name to a wiki ID, the wiki ID is read from the path part of the URL (e.g. https://auth.wikimedia.org/enwiki/... -> enwiki)
    • An Apache rewrite to hide the extra path part from MediaWiki + configuration overrides to make the generated URLs preserve the extra path part, and behave
    • A set of CentralAuth hooks to lock down functionality of the new domain to only the pages and API endpoints that are necessary for authentication + redirect static requests to some non-central domain
  • A new login flow that goes local login page -> redirect to central login page -> user submits credentials -> set central session cookies -> redirect back -> set local session cookies (instead of the old local login page -> user submits credentials -> set local session cookies -> invisible redirects to set central session cookies)
    • Creation of a new CentralAuth primary authentication provider that uses AuthManager's remote identity provider feature to redirect users to the central domain (where they authenticate using the old CentralAuth provider) and receive information of login success via the central token store when the user is redirected back
    • A PostLoginRedirect hook that handles the redirection back / token store parts on the central domain after successful login
    • A new core hook (AuthManagerFilterProviders) to suppress all non-redirection-related authentication providers when on the local domain
    • A new core hook (AuthManagerVerifyAuthentication) to support defense in depth against accidentally suppressing authentication providers when they shouldn't have been
  • Adapting the existing CentralAuth authentication primitives (central login, central autologin) to use the new shared login domain

Dependencies
No new external dependencies are introduced.

Has this project been reviewed before?
No. The CentralAuth SUL logic (which is partially being reused here) has been subject to security reviews in the past, but it was a long time ago and I have no idea if there's any written documentation.

There was a security preview of the current project: T367995: Security Preview for shared login domain

Working test environment
The easy way to test the project is on Beta wiki, where it can currently be enabled on any wiki by setting the cookie sul3OptIn=1.

Unfortunately, getting an accurate local test environment (especially for the configuration layer parts) is pretty much impossible. To get an approximate local setup, set up a local wiki farm, including one wiki used for central login, then follow the CentralAuth install instructions, then set

$wgCentralAuthCookies = true;
$wgCentralAuthCookieDomain = '';
$wgCentralAuthStrict = true;
$wgCentralAuthLoginWiki = "<login wiki>";
$wgCentralAuthEnableSul3 = [ 'always' ];
$wgLoadScript = '<primary wiki>/w/load.php';
$wgCentralAuthSsoUrlPrefix = '<login wiki>';

Post-deployment
Name of team responsible for tool/project after deployment and primary contact: MediaWiki-Platform-Team

Details

Risk Rating
Low
Author Affiliation
WMF Technology

Related Objects

StatusSubtypeAssignedTask
OpenNone
ResolvedTgr
ResolvedOWresch-WMF
ResolvedTgr
ResolvedTgr
Resolvedsbassett
ResolvedTgr
DeclinedTgr
ResolvedTgr
ResolvedSecurityTgr
Resolvedmatmarex
Resolvedmatmarex
ResolvedArielGlenn
ResolvedArielGlenn
Resolvedmatmarex
Resolvedmatmarex
ResolvedArielGlenn
ResolvedJTweed-WMF
ResolvedDAlangi_WMF
DeclinedFeatureTgr
ResolvedDAlangi_WMF
ResolvedTgr
ResolvedArielGlenn
ResolvedArielGlenn
ResolvedTgr
Resolvedpmiazga
ResolvedDAlangi_WMF
ResolvedTgr
ResolvedTgr
Resolvedmatmarex
ResolvedTgr
ResolvedTgr
Resolvedmatmarex
DeclinedNone
ResolvedTgr
ResolvedTgr
Resolvedmatmarex
Resolvedsbassett

Event Timeline

Tgr renamed this task from [WIP] Application Security Review Request : SUL3 to Application Security Review Request : SUL3.Oct 31 2024, 8:45 PM
Tgr removed Tgr as the assignee of this task.
Tgr updated the task description. (Show Details)

There are some smaller ongoing tasks that are relevant from a security perspective (T375788, T376488, T375796, T373737), I'll update the list of patches with those in the next few days as they get done; but apart from that, I think the request is ready. I'll make some diagrams about the old and new authentication flow soon. Please let me know what other information will be useful.

@Tgr - For the more config-related patches, are there updates to now use auth. instead of sso. as the shared auth sub-domain? I understand this is a minor issue, but was curious if any of these config changes exist yet. Thanks.

sbassett changed the task status from Open to In Progress.Nov 22 2024, 5:22 PM
sbassett claimed this task.
sbassett triaged this task as Medium priority.
sbassett added a project: user-sbassett.
sbassett moved this task from Upcoming Quarter Planning Queue to In Progress on the secscrum board.
sbassett moved this task from Backlog to In Progress on the user-sbassett board.

@Tgr - For the more config-related patches, are there updates to now use auth. instead of sso. as the shared auth sub-domain?

Yeah, the changes are in T379811: Update URL structure for SUL3 shared domain.

Krinkle updated the task description. (Show Details)

In an effort to get this finished within the next week or two, I'm going to focus on the 6-ish affected CentralAuth files mentioned above along with the provided list of "important patches". There are 122+ #sul3-migration-tagged change sets, spanning about 6 months of engineering work, many of which seem to be SRE/ops config changes that we don't have much insight into from the application layers.

Security Review Summary - T378722 - 2024-12-20
Last Commits Reviewed
Summary

Overall, the SUL3 project gets us to a far better place in supporting current browser privacy safeguards and user-tracking restrictions (as noted within T345249 and related tasks). Many steps were taken during the initial development phases of the SUL3 project and a threat-modeling session to ensure that certain security concerns were mitigated. Additionally, several static analysis tools were run against code within relevant change sets and a manual review of important files under the CentralAuth extension was performed. Finally, manual pentesting in addition to dynamic-scanning was performed against relevant portions of the beta cluster where SUL3 is currently enabled. The SUL3 work (as scoped within the task description and below) currently warrants an overall risk rating of: low.

Scope

As noted within the review request, there are 6 or so files within ext:CentralAuth where most of the new SUL3-related code now exists. And several important change sets that will be the focus of this review.

Important changed files

  1. CentralAuthRedirectingPrimaryAuthenticationProvider.php
  2. RedirectingLoginHookHandler.php
  3. SharedDomainHookHandler.php (formerly SsoHookHandler.php)
  4. FilteredRequestTracker.php
  5. CentralAuthSharedDomainPreAuthenticationProvider.php (formerly CentralAuthSsoPreAuthenticationProvider.php)
  6. SharedDomainUtils.php

Important change sets

Change set URLRepositoryStatic Analysis Status
https://gerrit.wikimedia.org/r/1036230puppetN/A
https://gerrit.wikimedia.org/r/1036245mediawiki-configN/A
https://gerrit.wikimedia.org/r/1038331CentralAuth phan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1057005CentralAuth phan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1056174CentralAuth phan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1072627CentralAuth phan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1083444CentralAuthphan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1025698CentralAuthphan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1053024CentralAuthphan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1062468CentralAuthphan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1078400CentralAuthphan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1057315CentralAuthphan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1054931core phan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1034966core phan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1057413core phan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1063788core phan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1058228corephan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1069695core phan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1057994core phan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1056590core phan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1067385CheckUser phan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1029512OATHAauth phan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1029534WebAuthn phan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1025874core phan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1031627OAuth phan/securitycheckplugin passed
https://gerrit.wikimedia.org/r/1031120core phan/securitycheckplugin passed
Initial Findings

Several steps were taken to address theoretical or actual security issues as the SUL3 project progressed:

  1. As noted within the above change set table, phan and the security check plugin ran against relevant PHP codebases (primarily CentralAuth) and passed without the detection of any static analysis findings.
  2. As noted in the request, a STRIDE-based threat model (internal) was performed by the Security-Team and relevant MediaWiki engineering team members. A brief summary of these threats and their mitigations are provided in the table below:
ThreatMitigationResidual Risk
A particular web server rewrite/redirect could be seen as a potential phishing URLCommunication plan (yet to be determined). Specific details are still to be determined, likely a CentralNotice communication and on-wiki write-up of SUL3. Task to be created. low risk
An actor can exploit various mediawiki features that should not be enabled for an SSO shared domain.See: T363695#9886787 and the mitigations mentioned within T367995 (resolved).
1) APIs limited via new hook (SsoHookHandler.php)
2) should not be able to run userjs and gadget code on available special pages (T373738, resolved)
3) explore disabling extensions/skins/components not relevant to login process (T373737, resolved)
4) interface message (T373732, resolved); fix copyright message html issue (T45646, resolved) as part of this.
low risk
An attacker can find a bug within our system to bypass some portion of the login process (mfa, etc.)Use the local process to bypass several components that CA checks right now (blocks, IP reputation, etc.) Ensure config is correct for different login processes. (c1063788, merged and c1056174, merged) low risk
An attacker manipulates user feature flag during login process in some novel way to bypass some piece of the login processEnsure that the login process does not allow this variety of manipulation via unexpected feature flag/user pref changes. (the session-based consistency check in c1057413, merged) low risk
An attacker is able to access a private wiki/non-SUL wiki via the shared domain login process.Ensure that the login process does not allow this type of access to same-wiki-farm private/non-SUL wikis. (c1036245, merged) low risk
An attacker can exploit our login migration process from loginwiki to the new shared sso.Code already exists to accommodate this issue, this will just be reused/repurposed. Reference: https://w.wiki/CSQE, relevant in-progress task: T375796. medium risk
Additional Static Analysis Performed

(Note: static analysis was performed on relevant files from the SUL3 work when possible, as opposed to entire repositories.)

Semgrep (run with various CI, PHP, secret-finding and general rulesets/policies)

Repo@commitRiskNotes
CentralAuth@92680dc752 low riskminor gripes about md5/unserialize
CheckUser@dbaa1678a0 low riskno findings
OATHAuth@a5fb1ee448 low riskno findings
OAuth@594e7a67aa low riskfalse positive around http leaks, html::rawElement and bare print statement
WebAuthn@7c438011a7 low riskno findings
core@92680dc752 PHP low riskminor gripes about md5
core@92680dc752 JS low riskno findings in resources/src/mediawiki.authenticationPopup/

Bearer SAST (default policies)

Repo@commitRiskNotes
CentralAuth@92680dc752 low riskfalse positives related to PII in logger actions
CheckUser@dbaa1678a0 low riskfalse positives related to db sanitization
OATHAuth@a5fb1ee448 low riskno findings
OAuth@594e7a67aa low riskfalse positives related to PII in logger actions
WebAuthn@7c438011a7 low riskno findings
core@92680dc752 PHP low riskno findings
core@92680dc752 JS low riskno findings in resources/src/mediawiki.authenticationPopup/

Horusec SAST (default policies)

Repo@commitRiskNotes
CentralAuth@92680dc752 low riskfalse positives around secret leaks
CheckUser@dbaa1678a0 low riskno findings
OATHAuth@a5fb1ee448 low riskno findings
OAuth@594e7a67aa low riskfalse positives around secret leaks
WebAuthn@7c438011a7 low riskno findings
core@92680dc752 PHP low riskfalse positives around secret leaks
core@92680dc752 JS low riskno findings in resources/src/mediawiki.authenticationPopup/
Dynamic Scanning And Manual Pentesting Against Beta Cluster

ZAP (default attack policy)

URLRiskNotes
https://auth.wikimedia.beta.wmflabs.org/enwiki/ low riskThe results contained unrelated or low-risk items that were not specific to the SUL3 work. The full report PDF can be found under the WMF's G Suite.

Wapiti (policies: backup, buster, cookieflags, crlf, csp, csrf, http_headers, methods, redirect, shellshock, ssl, ssrf, takeover)

URLRiskNotes
https://auth.wikimedia.beta.wmflabs.org/enwiki/ low riskThe results contained unrelated or low-risk items that were not specific to the SUL3 work. The full report PDF can be found under the WMF's G Suite.

Manual pentesting

I also performed a small amount of manual pentesting against the beta cluster, just to ensure that my basic understanding of the security concepts addressed within SharedDomainHookHandler.php, FilteredRequestTracker.php and SharedDomainUtils.php were performing as expected. I confirmed basic concepts such as only the small, curated list of special pages are available on the shared domain (T373738#10265552), that userJS does not run under the shared domain, that various extensions and other features appear disabled under the shared domain (T373737#10352026), etc. I did notice some different behavior between various wiki directories under auth.wikimedia.beta (e.g. /officewiki/ [404] vs /foundationwiki/ [503] vs /loginwiki/ [200, perm error] vs /commonswiki/ [503] vs /enwiktionary/ [200, perm error], etc.) But I didn't find a clever way to really exploit that as I imagine these are expected behaviors. I also noticed that I'm able to move easily between Special:Userlogin on enwiki.beta, auth.w.beta/enwiki, et al where I can enable/disable my OATH TOTP (if I set it under enwiki.beta, it checks for it during reauth under auth.w.beta/enwiki during a new auth). There are many additional rabbit holes one could likely go down during a pentest like this, but in my opinion, the critical security concerns surfaced and addressed during the threat-model seem well-implemented and warrant a rating of low risk.

sbassett moved this task from In Progress to Our Part Is Done on the secscrum board.
sbassett moved this task from In Progress to Done on the user-sbassett board.