WordPressKit REST requests build the wrong URL on self-hosted sites that use plain permalinks

Aperta
#26,337 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
57/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
swift
Ambito
api, backend

Direzione di ricerca

Read Modules/Sources/WordPressKit/WordPressOrgRestApi.swift and Modules/Sources/WordPressKit/HTTPRequestBuilder.swift, then trace how dotOrgRESTAPI and appendURLString handle the discovered query-form REST root. Check the existing URL resolver behavior mentioned in the issue and inspect relevant tests. Done means plain-permalink requests target https://site/index.php?rest_route=/wp/v2/… with request query parameters merged correctly, while path-based REST roots continue to work.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

[Type] Bug
Description

WordPressOrgRestApi assumes a path-based REST root, so on a self-hosted site with plain permalinks it crashes debug builds and, in release builds, sends requests to the wrong resource.

  • The root comes from discovery unchanged. WordPressOrgRestApi(blog:) uses Blog.selfHostedRestApiRootURL, which is restApiRootURL from REST API discovery. On a plain-permalink site that is the query form, e.g. https://site/index.php?rest_route=/.
  • Debug builds hit an assertion. init(selfHostedSiteWPJSONURL:…) asserts apiURL.lastPathComponent == "wp-json", and dotOrgRESTAPI asserts the same.
  • Release builds append routes to the path. HTTPRequestBuilder.dotOrgRESTAPI → appendURLString adds the route to the URL path, producing https://site/index.php/wp/v2/…?rest_route=/.
  • WordPress answers that URL with the API index. The trailing ?rest_route=/ routes to the REST index, so the request returns 200 with the API index instead of the requested resource. GutenbergKit hit the same silent failure (wordpress-mobile/GutenbergKit#563).

Affected callers include BlockEditorSettingsService, ApplicationPasswordRepository, PluginStore, GutenbergNetworking and JetpackConnectionWebViewController (via Blog.selfHostedSiteRestApi).

The expected URL is https://site/index.php?rest_route=/wp/v2/…, with any request query merged using &. That's what wordpress-rs (WpOrgSiteApiUrlResolver), GutenbergKit (wordpress-mobile/GutenbergKit#573) and #25859 now produce. Longer term, wordpress-mobile/GutenbergKit#579 proposes moving these joins onto the wordpress-rs resolver rather than adding another copy.

Related: #25604 (self-hosted login on plain-permalink sites); ApplicationPasswordRepository.createPassword builds a WordPressOrgRestApi for self-hosted sites, so login can reach this path.

Step-by-step reproduction instructions
  1. Use a self-hosted site set to Settings ▸ Permalinks ▸ Plain. Confirm its Link header advertises ?rest_route=/: curl -sI https://your-site.com/ | grep -i '^link'.
  2. Sign in to the site in a debug build with an application password.
  3. Observe the assertion failure below.
Screenshots, screen recording, code snippet

Debug build, signed in to a plain-permalink site:

WordPressKit/WordPressOrgRestApi.swift:52: Assertion failed: Not a REST API URL: https://example.com/index.php?rest_route=/

The URL a release build would request (the route path-appended, per appendURLString) returns the API index, while the correct form returns the resource:

GET /index.php/wp/v2/types?rest_route=/  -> 200 {"name":…,"namespaces":[…],…}   # REST API index
GET /index.php?rest_route=/wp/v2/types   -> 200 {"post":…,"page":…,…}          # post types

Relevant code on trunk:

  • Modules/Sources/WordPressKit/WordPressOrgRestApi.swift: both wp-json asserts, and dotOrgRESTAPI
  • Modules/Sources/WordPressKit/HTTPRequestBuilder.swift: appendURLString
  • Modules/Sources/WordPressData/Swift/Blog+SelfHostedRestApi.swift: selfHostedRestApiRootURL
Environment info

WordPress-iOS trunk (bbb4da2b3d), debug build; self-hosted site with plain permalinks, signed in with an application password.

Please confirm that you have searched existing issues in the repo.
  • Yes
Lingua principale
Swift
Stelle
3.9k
Fork
1.2k
Merge medio
1g 23h
PR unite (30g)
136

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di wordpress-mobile/WordPress-iOS

Tutte le issue di wordpress-mobile/WordPress-iOS

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.