Skip to content

Warn before self-hosted sign-in over an insecure connection - #25870

Open
crazytonyli wants to merge 4 commits into
trunkfrom
task/selfhosted-http-signin-warning
Open

crazytonyli wants to merge 4 commits into
trunkfrom
task/selfhosted-http-signin-warning

Conversation

@crazytonyli

@crazytonyli crazytonyli commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Two main changes:

  • The self-hosted sign in flow now presents an "insecure connection" warning when attempting to add a non-https site.
  • The ApplicationPasswordRepository, which creates and validates application passwords, now only work with HTTPS url.

@wpmobilebot

wpmobilebot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number34986
VersionPR #25870
Bundle IDorg.wordpress.alpha
Commit62ee886
Installation URL3b70cjhg759bo
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number34986
VersionPR #25870
Bundle IDcom.jetpack.alpha
Commit62ee886
Installation URL0uupai2jp1js8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@crazytonyli
crazytonyli force-pushed the fix/xmlrpc-https-downgrade branch from 8cf3c89 to edd751d Compare August 11, 2026 05:08
Base automatically changed from fix/xmlrpc-https-downgrade to release/27.2 August 19, 2026 23:04
@crazytonyli
crazytonyli force-pushed the task/selfhosted-http-signin-warning branch 2 times, most recently from 8b44c1b to 97e628f Compare August 26, 2026 02:43
@crazytonyli
crazytonyli changed the base branch from release/27.2 to trunk August 26, 2026 02:43
@crazytonyli
crazytonyli force-pushed the task/selfhosted-http-signin-warning branch from 97e628f to 1af1131 Compare August 26, 2026 06:48
@crazytonyli
crazytonyli marked this pull request as ready for review August 26, 2026 06:48
Present a confirmation alert at the top of the authenticate choke point when any
pre-authorization credential destination (the site URL, REST API root, or
application-password authorization URL) uses non-loopback http. Cancel reuses the
existing SignInError.cancelled, and the debug launch-argument path never reaches
this gate. The alert is presented from the topmost controller because the sign-in
entry points already present the SwiftUI login flow.

When the pre-authorization flow was fully secure, coerce an unexpectedly-http
callback site URL to https, and skip the sign-in-time XML-RPC options fetch if
discovery resolves an insecure endpoint, so a site that proved secure end-to-end
never has its credentials sent over an unencrypted connection.
ApplicationPasswordRepository must never transmit credentials to a
non-loopback http destination on its own. Each path checks the
destinations it contacts and throws insecureConnection for an insecure
one: validation (the site URL and stored REST root) is checked in
validatePasswords before any request, and self-hosted password creation
(login_url, admin_url, and the wp-json base, all derived from xmlrpc and
independently http-capable) is checked before creating. Jetpack sites
create through the WordPress.com proxy over https and are not gated on the
site's own scheme, so an https site with a valid token but a legacy http
xmlrpc is not blocked.

The REST API root resolved by discovery is validated before it is
persisted to Blog.restApiRootURL, so an insecure value is never stored
where other consumers could later send credentials to it. Getting an
application password for an insecure site instead goes through the
interactive sign-in flow, which shows the insecure-connection warning;
existing repository callers already catch the error and degrade
gracefully.
@crazytonyli
crazytonyli force-pushed the task/selfhosted-http-signin-warning branch from 1af1131 to 6f65a56 Compare August 26, 2026 06:48
@crazytonyli
crazytonyli requested a review from jkmassel August 26, 2026 06:50
@crazytonyli crazytonyli added this to the 27.3 milestone Aug 26, 2026
@wpmobilebot wpmobilebot modified the milestones: 27.3, 27.4 Sep 20, 2026
@wpmobilebot

Copy link
Copy Markdown
Contributor

Version 27.3 has now entered code-freeze, so the milestone of this PR has been updated to 27.4.

Comment on lines +292 to +304
// Creating a password here uses cookie and nonce authentication, contacting the site's
// login_url, admin_url, and wp-json base. Each derives from `xmlrpc` (or its own option),
// so each can use http independently. Gate on every credential destination before
// sending anything.
let destinations = try await coreDataStack.performQuery { context in
let blog = try context.existingObject(with: blogId)
var destinations: [URL] = [try blog.getUrl()]
if let restApiRootURL = blog.restApiRootURL, let parsed = URL(string: restApiRootURL) {
destinations.append(parsed)
}
if let restBase = blog.url(withPath: "wp-json/"), let parsed = URL(string: restBase) {
destinations.append(parsed)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check stops some https sites from getting an application password, even though nothing would be sent over http.

What happens

The list of addresses checked here includes one the app never contacts: the wp-json/ address built from the saved xmlrpc value. The app really uses the stored REST API root, which is already on the list.

An older app bug could save xmlrpc as http for an https site (GHSA-qxpr-7v78-mh5g). For those sites every address the app contacts is https, but this extra entry is http, so the check throws insecureConnection.

Who is affected

Sites added with a username and password (before #25645), where the site is https and the saved xmlrpc value is http.

What they see

Before this change, these sites get an application password when the site loads. With this change they don't, and screens like Users show "Application Password Required" instead.

Suggested fix

Check the REST API root the app is built from, and drop the extra entry:

Suggested change
// Creating a password here uses cookie and nonce authentication, contacting the site's
// login_url, admin_url, and wp-json base. Each derives from `xmlrpc` (or its own option),
// so each can use http independently. Gate on every credential destination before
// sending anything.
let destinations = try await coreDataStack.performQuery { context in
let blog = try context.existingObject(with: blogId)
var destinations: [URL] = [try blog.getUrl()]
if let restApiRootURL = blog.restApiRootURL, let parsed = URL(string: restApiRootURL) {
destinations.append(parsed)
}
if let restBase = blog.url(withPath: "wp-json/"), let parsed = URL(string: restBase) {
destinations.append(parsed)
}
// Creating a password here uses cookie and nonce authentication, contacting the site's
// login_url, admin_url, and REST API root. Each can use http independently, so gate on
// every credential destination before sending anything. The REST root is the one
// `WordPressOrgRestApi(blog:)` is built from, not one re-derived from `xmlrpc`.
let destinations = try await coreDataStack.performQuery { context in
let blog = try context.existingObject(with: blogId)
var destinations: [URL] = [try blog.getUrl()]
if let restApiRootURL = blog.selfHostedRestApiRootURL {
destinations.append(restApiRootURL)
}

How this was checked

On iOS 27.0 simulators, compared with the merge-base (016312d41b):

Merge-base This branch With the suggestion
New test (below) passes fails passes
A real site in the app password created refused, no password password created
  • The real site runs WordPress 7.1.3. Its login and admin addresses are https. Only the saved xmlrpc value was set to http, by hand.
  • It was added with a temporary launch-argument hook that repeats what the old username-and-password sign-in did.
  • The same site with an https xmlrpc value works on this branch as it is.
  • With the suggestion, the other 19 tests in this suite still pass. That includes insecureXMLRPCDerivedDestinationDoesNotTransmitCredentials, where the login and admin addresses really are http and the check should still refuse.
Test for this case
    @Test
    func httpsSiteWithInsecureXMLRPCCreatesPassword() async throws {
        defer { HTTPStubs.removeAllStubs() }

        // Only the persisted `xmlrpc` string is http. The site URL, the discovered REST root, and
        // the `login_url` and `admin_url` options are https, so nothing in the creation flow leaves
        // over http and it must not be refused.
        let host = "https-site-http-xmlrpc.example.com"
        let blog = try await coreDataStack.performAndSave { context in
            let blog = Blog(context: context)
            blog.url = "https://\(host)"
            blog.xmlrpc = "http://\(host)/xmlrpc.php"
            blog.setValue("https://\(host)/wp-login.php", forOption: "login_url")
            blog.setValue("https://\(host)/wp-admin/", forOption: "admin_url")
            blog.username = "demo"
            blog.password = "pass"
            return TaggedManagedObjectID(blog)
        }

        stubApiDiscovery(siteHost: host)
        stubSelfHostedSiteWpV2GetUser()
        stubSelfHostedSiteCreateApplicationPassword(host: host, password: "abcd efgh")
        // Added last so it is checked first.
        stub(condition: isHost(host) && isScheme("http")) { _ in
            Issue.record("No request should be sent over http")
            return HTTPStubsResponse(error: URLError(.notConnectedToInternet))
        }

        let repository = ApplicationPasswordRepository.forTesting(coreDataStack: coreDataStack, keychain: keychain)
        try await repository.createPasswordIfNeeded(for: blog)

        let password = await password(of: blog)
        #expect(password == "abcd efgh")
    }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 62ee886

…word

The insecure-connection gate rebuilt the list of URLs from `Blog`, and
included a `wp-json/` URL derived from `xmlrpc` that `WordPressOrgRestApi`
never contacts. Sites whose stored `xmlrpc` is http but whose discovered
REST root, login_url, and admin_url are https were wrongly refused.

`WordPressOrgRestApi` now reports the URLs it sends credentials to, and the
repository checks that list, so the gate cannot drift from the request path.
@dangermattic

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ This PR is larger than 500 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@crazytonyli
crazytonyli requested a review from jkmassel October 14, 2026 01:03
@wpmobilebot wpmobilebot modified the milestones: 27.4, 27.5 Oct 20, 2026
@wpmobilebot

Copy link
Copy Markdown
Contributor

Version 27.4 has now entered code-freeze, so the milestone of this PR has been updated to 27.5.

@crazytonyli
crazytonyli requested review from jkmassel and removed request for jkmassel November 16, 2026 20:37
@wpmobilebot wpmobilebot removed this from the 27.5 milestone Nov 20, 2026
@wpmobilebot wpmobilebot added this to the 27.6 milestone Nov 20, 2026
@wpmobilebot

Copy link
Copy Markdown
Contributor

Version 27.5 has now entered code-freeze, so the milestone of this PR has been updated to 27.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants