Fix NPE in parseUriLogin when site_url query param is missing#22824
Fix NPE in parseUriLogin when site_url query param is missing#22824
Conversation
ApiRootUrlCache.get now accepts a nullable key, since UrlUtils.normalizeUrl returns null for missing/malformed site_url params and the runtime non-null check threw before the BadData path could surface a recoverable error. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Generated by 🚫 Danger |
|
|
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #22824 +/- ##
=======================================
Coverage 37.15% 37.15%
=======================================
Files 2314 2314
Lines 124323 124340 +17
Branches 16892 16895 +3
=======================================
+ Hits 46187 46201 +14
- Misses 74390 74393 +3
Partials 3746 3746 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This seems like a larger issue – if we need the I suspect this issue might be caused by folks who hit "Reject" on the authorization page – if that's the case, it should be pretty easy to reproduce, but this bug makes me think we're not handling it properly. |
WordPress's authorize-application.php redirects to the success_url with success=false (and no credentials) when the user clicks "No, I do not approve this connection". The activity blindly tried to parse credentials from this URI, leading to bad_data Sentry reports and a misleading error toast for a deliberate user choice. Detect success=false at the top of setupSite, skip the crash report, and show an "Authorization cancelled" toast instead. Track the rejection via the existing storing-failed analytics event so we can measure how often it happens. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jkmassel I had Claude review your comment and you are correct - this PR fixed the NPE but we weren't handling rejection at all. I've updated the PR and its description to address this. |
This comment was marked as resolved.
This comment was marked as resolved.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>


Description
Fixes two related issues in the Application Password login deep-link callback flow:
1. NullPointerException in
parseUriLogin(Sentry 3CBF, 756 users)UrlUtils.normalizeUrl(null)returnsnullwhen the auth-callback URI lacks asite_urlquery param, butApiRootUrlCache.getdeclaredkey: String(non-null), so Kotlin's runtime null check threw an NPE before any recoverable error could be surfaced.Fix: relax
ApiRootUrlCache.getto acceptString?and returnnullfor null/empty input.2. User-rejection callback handled as crash (Sentry 3F8V, 287 users)
WordPress's
wp-admin/authorize-application.phpredirects to the configuredsuccess_urlwith?success=false(and no credentials) when the user clicks "No, I do not approve this connection". The activity blindly tried to parse credentials from this URI, which:BadData, sent a"A_P: bad_data"report to Sentry, and shown a misleading error toast to a user who deliberately cancelled.Fix: detect
success=falseat the top ofsetupSite, skip the crash report, and show an "Authorization cancelled" toast instead. The rejection is still tracked via the existingAPPLICATION_PASSWORD_STORING_FAILEDanalytics event with reasonuser_rejected, so we can measure how often it happens.Testing instructions
Automated
./gradlew :WordPress:testJetpackDebugUnitTest --tests "org.wordpress.android.ui.accounts.login.ApiRootUrlCacheTest" --tests "org.wordpress.android.ui.accounts.applicationpassword.ApplicationPasswordLoginViewModelTest"get returns null for null keyandgiven user rejected authorization, when setup site, then emit user_rejected without crash report.Manual: rejection flow
wp-admin/authorize-application.phpconsent page.Manual: happy path regression