unreachable-host-leaves-blank-retrying-purchase.md (8093B)
1 <!-- 2 This file is part of GNU Taler 3 (C) 2026 Taler Systems S.A. 4 5 GNU Taler is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 --> 16 17 # A prompt the app cannot prepare shows an empty screen and retries for ever 18 19 Found by random exploration (seeds 31 and 33, from the hostile-URI corpus) and 20 reproduced deliberately. 21 22 **Severity: moderate.** The original trigger was a URI the wallet cannot reach 23 — a stale QR code, a typo, a developer pointing the wallet at `127.0.0.1` — 24 and what the user gets is a screen with nothing on it and a transaction that 25 never stops trying. Fault injection then showed the same empty screen for 26 eleven unrelated failures of the exchange, including ones that look like an 27 attack, and that it does not recover when the failure goes away. 28 29 ## What happens 30 31 Sharing `taler+http://pay/127.0.0.1:8080/instances/sim/AAAA…/` into the wallet: 32 33 * the purchase screen opens with **no content at all** — the only labels are 34 "Purchase", "Go back" and the developer-mode log button; 35 * the request is refused by the platform, 32 times in the first ten seconds: 36 37 ``` 38 D taler-wallet: java.net.UnknownServiceException: CLEARTEXT communication to 39 127.0.0.1 not permitted by network security policy 40 ``` 41 42 * wallet-core records it as a retried operation and keeps going — the retry 43 counter was still climbing (7 → 8 → …) a minute later, and in the 44 exploration runs it reached 12. 45 46 `[::1]` behaves identically. The refusal is permanent: the app's 47 `res/xml/network_security_config.xml` permits cleartext for the name 48 `localhost` only, so no number of retries will ever make `127.0.0.1` or `::1` 49 work. 50 51 ## Reproduce by hand 52 53 1. Install a debug build and enable **Developer mode** (needed for 54 `taler+http://`; an `https://` URI to an unreachable host shows the same 55 empty screen without it). 56 2. Run `adb logcat | grep -E "CLEARTEXT|taler-wallet"`. 57 3. Share the URI into the wallet: 58 59 ```bash 60 adb shell am start -a android.intent.action.SEND -t text/plain \ 61 -n net.taler.wallet.fdroid.debug/net.taler.wallet.main.MainActivity \ 62 --es android.intent.extra.TEXT \ 63 'taler+http://pay/127.0.0.1:8080/instances/sim/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/' 64 ``` 65 66 4. The wallet opens an empty "Purchase" screen. The log fills with cleartext 67 refusals, and they keep coming. 68 69 Expected: the screen says what went wrong, and a refusal the platform will 70 never allow is not retried. 71 72 ## Reproduce with the simulator 73 74 ```bash 75 ssh root@tripwire.taler.net 76 cd /opt/taler-sim/driver 77 python3 ../findings/repro_unreachable_host_zombie_purchase.py 78 ``` 79 80 ## The empty prompt is not specific to this cause 81 82 Fault injection showed the same screen for every way of spoiling the 83 exchange's replies. With `taler-twister` in front of the exchange, a 84 withdrawal whose preparation fails renders as 85 86 ``` 87 ['Go back', 'Withdraw UNKNOWN', 'Internal event log'] 88 ``` 89 90 — no amount, no error, and "UNKNOWN" where the currency belongs. That held for 91 a truncated response, HTTP 500, 404, 403 and 502, a wrong content type, and 92 for structural damage (a deleted `denoms`, a deleted signature, a flipped 93 master public key, a rewritten version or currency). 94 95 In that run the wallet was in fact refusing for a different reason — 96 `WALLET_EXCHANGE_BASE_URL_MISMATCH` (7030), logged six times — which makes the 97 point more sharply: the wallet detected a problem and told the user nothing. 98 A prompt with no error state looks the same whatever went wrong. 99 100 A later fault-injection run put a number on "whatever went wrong". With 101 `taler-twister` between the wallet and the exchange, kept armed for the whole 102 withdrawal, **eleven different faults all produced the same screen**: 103 104 ``` 105 ['Go back', 'Withdraw UNKNOWN', 'Internal event log'] 106 ``` 107 108 a truncated response, HTTP 500, 404, 403 and 502, a response with the wrong 109 content type, a `/keys` with its denomination list deleted, with a flipped 110 master public key, with a forged denomination signature, with no wire fees, and 111 with an impossible protocol version. The withdrawal prompt is empty in all 112 eleven cases, and the title reads "Withdraw UNKNOWN" — the placeholder 113 currency, because the wallet has no exchange configuration to take a currency 114 from. 115 116 Two things make this worse than the original observation: 117 118 * **It does not recover.** The run disarmed each fault and waited; the screen 119 was still `['Go back', 'Withdraw UNKNOWN', 'Internal event log']` afterwards 120 for every fault that damaged `/keys`. There is nothing on the screen to 121 retry with, so a withdrawal interrupted by a bad reply is lost even once the 122 exchange is healthy again. 123 * **The same screen means "your exchange is lying to you".** A forged 124 denomination signature and a flipped master public key are what an attack 125 looks like, and the wallet shows the same blank page it shows for a 126 typo. 127 128 ## Why 129 130 Two separate things meet here. 131 132 * **The screen renders nothing while it has nothing.** `PromptPayment` is 133 waiting for contract terms that will never arrive, and there is no state for 134 "still fetching" or "could not fetch" — so the user is left looking at an 135 empty page rather than a spinner or an error. 136 * **A policy refusal looks like a network blip.** `UnknownServiceException` 137 reaches wallet-core as a generic HTTP failure (code 7003), which is retried 138 with backoff like any transient error. It is not transient: the cleartext 139 policy is fixed at build time. 140 141 ## The cheapest reproduction of the empty prompt 142 143 No proxy needed at all: one injected error does it. With developer mode on, 144 145 ```bash 146 adb shell am start -a android.intent.action.VIEW -d \ 147 'taler+http://dev-experiment/api-error?operation=getWithdrawalDetailsForAmount&detail=eyJjb2RlIjogNzAwMSwgImhpbnQiOiAiaW5qZWN0ZWQifQ&count=4' 148 ``` 149 150 then tapping **Withdraw** gives 151 `['Go back', 'Withdraw from bank', 'Internal event log']` — the same empty 152 screen, from a single failed call. This is one of the screens 153 [`a-failed-query-is-shown-as-an-empty-wallet.md`](a-failed-query-is-shown-as-an-empty-wallet.md) 154 sweeps. 155 156 ## Reproduce with fault injection 157 158 No manual reproduction for this half: it needs a proxy between the wallet and 159 the exchange. 160 161 ```bash 162 ssh root@tripwire.taler.net 163 cd /opt/taler-sim/driver 164 ./phase.sh sim-twister.conf twister_withdraw_faults twister_field_faults 165 ``` 166 167 The phase swaps in `backend/sim-twister.conf` (the exchange behind 168 `taler-twister` on port 8088), runs the scenarios and restores the ordinary 169 stack. Each scenario's notes list what every fault produced, and how many 170 times the fault was re-armed — a fault is one-shot, so it has to be re-armed 171 continuously or it lands on an unrelated poll instead of on the request under 172 test. 173 174 ## Suggested fix 175 176 Give the payment and withdrawal prompts something to show while they are 177 loading, and an error state when the load fails — the error sheet used 178 elsewhere would do. The withdrawal prompt additionally needs a title that does 179 not say "UNKNOWN" when it has no currency yet, and a way to try again. 180 181 For the retries, treat `UnknownServiceException` (and the cleartext refusal in 182 particular) as permanent in `NetworkInterface`, so the transaction fails with 183 an explanation instead of looping. A user-visible "this address cannot be 184 reached over plain HTTP" is far more useful than silence. 185 186 Worth considering separately: `network_security_config.xml` permits cleartext 187 for the name `localhost` but not for `127.0.0.1` or `::1`, which are the same 188 machine. Adding both would save developers this exact confusion.