Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Self-hosted web view login cookie check fails for usernames containing `@` or spaces

Aperta Adatta ai principianti
#26,115 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
ios, objective-c, swift

Direzione di ricerca

Inizia in WordPress/Classes/Utility/WebViewController/CookieJar.swift, in HTTPCookie.isWordPressLoggedIn(username:), che attualmente considera tutto ciò che precede il primo % come nome utente. Decodifica il valore del cookie con percent-decoding (PHP mappa anche gli spazi su +) e dividilo usando |, come fa isWordPressLoggedInAtomic(username:). Verifica che AuthenticationService.loadAuthCookiesForSelfHosted non effettui più un nuovo POST a wp-login.php per nomi utente come [email protected] e john doe.

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

Descrizione

[Type] Bug Self-hosted Webviews

Found while reviewing #26103. Pre-existing — not introduced by that PR, and unchanged by #26106 and #26104.

The logged-in cookie check for self-hosted sites never matches when the username contains a character that PHP URL-encodes, so the app logs in again before every authenticated web view load.

Root cause

HTTPCookie.isWordPressLoggedIn(username:) takes the username to be everything before the first % in the cookie value:

https://github.com/wordpress-mobile/WordPress-iOS/blob/3db37280b4bd84f1cc4e68526f84c35d507149a6/WordPress/Classes/Utility/WebViewController/CookieJar.swift#L156-L159

WordPress sets the cookie value to username|expiration|token|hmac and PHP's setcookie() URL-encodes it, so the check relies on the first | arriving as %7C. An encoded character inside the username breaks that:

Username Cookie value Parsed username Match
admin admin%7C… admin ✅
[email protected] user%40example.com%7C… user ❌
john doe john+doe%7C… john+doe ❌

Impact

AuthenticationService.loadAuthCookiesForSelfHosted treats a failed check as "no cookie" and POSTs the username and password to wp-login.php again:

https://github.com/wordpress-mobile/WordPress-iOS/blob/3db37280b4bd84f1cc4e68526f84c35d507149a6/WordPress/Classes/Services/AuthenticationService.swift#L31-L40

This affects sites that RequestAuthenticator authenticates with .siteLogin credentials. The login itself still succeeds, so the cost is an extra login round-trip — and a new session on the site — before each authenticated load, rather than a visible failure.

WordPress.com usernames are normally limited to lowercase letters and numbers, so the same predicate is not expected to misfire on the WordPress.com path.

Verification

Confirmed with a Foundation probe (macOS 27.0.1): HTTPCookie.cookies(withResponseHeaderFields:for:) keeps the value percent-encoded, and the predicate returns false for [email protected] and john doe.

The cookie values in the probe were built from WordPress's cookie format. We have not reproduced this against a live self-hosted site.

Suggested fix

Percent-decode the value before parsing — PHP's urlencode also turns spaces into + — and split on |, as isWordPressLoggedInAtomic(username:) already does.

Lingua principale
Swift
Stelle
3.9k
Fork
1.2k
Merge medio
1g 18h
PR unite (30g)
56

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.