Repository navigation
Warn before self-hosted sign-in over an insecure connection - #25870
crazytonyli wants to merge 4 commits into
Conversation
|
| App Name | WordPress | |
| Configuration | Release-Alpha | |
| Build Number | 34986 | |
| Version | PR #25870 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | 62ee886 | |
| Installation URL | 3b70cjhg759bo |
|
| App Name | Jetpack | |
| Configuration | Release-Alpha | |
| Build Number | 34986 | |
| Version | PR #25870 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | 62ee886 | |
| Installation URL | 0uupai2jp1js8 |
8cf3c89 to
edd751d
Compare
8b44c1b to
97e628f
Compare
97e628f to
1af1131
Compare
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.
1af1131 to
6f65a56
Compare
|
Version |
| // 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) | ||
| } |
There was a problem hiding this comment.
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:
| // 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
xmlrpcvalue 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
xmlrpcvalue 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")
}…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.
Generated by 🚫 Danger |
|
Version |
|
Version |


Two main changes:
ApplicationPasswordRepository, which creates and validates application passwords, now only work with HTTPS url.