add-payment-service-fails-silently.md (6343B)
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 # Payment-service failures are never shown: four error channels have no observer 18 19 Found by the `exchange_url_fuzz` scenario, which fed twelve hostile addresses 20 to Settings → Payment services → **Add payment service**. Every rejection 21 looked identical to the user: the dialog closes and the list comes back 22 unchanged. 23 24 **Severity: moderate.** This is not developer-mode gated — "Payment services" 25 is in the ordinary settings list. A mistyped address is indistinguishable from 26 one that is still being added, since a *successful* add also takes several 27 seconds to appear in the list. 28 29 The same gap covers the whole screen, not just adding: `ExchangeManager` 30 publishes four error channels and **none of them has a reader**, so failures to 31 add, list, delete or reload a payment service are all silent. 32 33 ## What happens 34 35 Entering `file:///etc/passwd` and tapping OK: the dialog closes, nothing is 36 shown at +0.6 s, +1.5 s or +3 s, and no payment service is added. wallet-core 37 did reject it, in the log only: 38 39 ``` 40 {"type":"error","operation":"addExchange","id":109, 41 "error":{"code":7048,"detail":"scheme \"file:\" is not supported, expected \"https:\""}} 42 {"type":"error","operation":"addExchange","id":100, 43 "error":{"code":7048,"detail":"URL cannot be parsed"}} 44 ``` 45 46 For contrast, a good address does work — `http://localhost:8081/` appears in 47 the list as "Currency: EUR" — but only after a few seconds, which is why the 48 silence is misleading rather than merely untidy. 49 50 Injecting a failure into the operation behind the *list* shows the same thing 51 from the other side: with `listExchanges` made to fail 52 (`taler://dev-experiment/api-error?operation=listExchanges&…`), Settings → 53 Payment services renders its list as if nothing had happened. Whatever it 54 shows is whatever it had before; the user is given no reason to doubt it. 55 56 The same silence covers the case that matters most in practice: a *well-formed* 57 address that simply cannot be reached. Adding `http://localhost:8091/` on a 58 device where nothing answers on that port behaves exactly like adding nothing 59 at all — the screen returns to the list, the service is absent, and the user is 60 given no reason to suspect a network problem rather than a typo. This was 61 noticed the other way round: a simulator scenario that adds a second payment 62 service "passed" while silently achieving nothing, because the port had not 63 been routed into the emulator. 64 65 ## Reproduce by hand 66 67 1. Open the wallet, go to **Settings → Payment services**. 68 2. Tap **Add payment service**. 69 3. Type `file:///etc/passwd` (or `not a url`, or `http://`) and tap **OK**. 70 4. The dialog closes. Nothing else happens — no message, no entry in the list. 71 `adb logcat | grep addExchange` shows the rejection. 72 73 Expected: the dialog stays open with the reason, or an error is shown — the 74 string for it already exists. 75 76 ## Reproduce with the simulator 77 78 ```bash 79 ssh root@tripwire.taler.net 80 cd /opt/taler-sim/driver 81 python3 ../findings/repro_add_exchange_fails_silently.py 82 ``` 83 84 ## Why 85 86 `ExchangeManager.add()` does publish the error 87 (`exchanges/ExchangeManager.kt:97-112`): 88 89 ```kotlin 90 }.onError { 91 Log.e(TAG, "Error adding exchange: $it") 92 mProgress.value = false 93 mAddError.value = it.toEvent() 94 } 95 ``` 96 97 but `addError` has no observer anywhere in the app — and neither do its three 98 siblings: 99 100 | Channel | Set when | Readers | 101 | --- | --- | --- | 102 | `addError` (`ExchangeManager.kt:58`) | `addExchange` fails | none | 103 | `listError` (`:61`) | listing exchanges fails | none | 104 | `deleteError` (`:64`) | deleting one fails | none | 105 | `reloadError` (`:67`) | reloading one fails | none | 106 107 ```console 108 $ grep -rn "addError\|deleteError\|listError\|reloadError" \ 109 --include=*.kt wallet/src/main/java | grep -v "private val m" 110 wallet/.../ExchangeManager.kt:58: val addError: LiveData<Event<TalerErrorInfo>> = mAddError 111 wallet/.../ExchangeManager.kt:61: val listError: LiveData<Event<TalerErrorInfo>> = mListError 112 wallet/.../ExchangeManager.kt:64: val deleteError: LiveData<Event<TalerErrorInfo>> = mDeleteError 113 wallet/.../ExchangeManager.kt:67: val reloadError: LiveData<Event<TalerErrorInfo>> = mReloadError 114 ``` 115 116 Four declarations, no readers. Two matching string resources exist and are 117 never referenced either — `R.string.exchange_add_error` ("Could not add 118 payment service") and `R.string.exchange_list_error` ("Could not list payment 119 services") — so the error path was designed and then left unwired. There are no 120 strings at all for the delete and reload cases. 121 122 `ExchangeListScreen.kt:136` also closes the dialog immediately 123 (`exchangeManager.add(url); showAddDialog = false`), before the asynchronous 124 call has any result to report. 125 126 ## Suggested fix 127 128 Observe all four channels on the exchange list and show them — the screen 129 already has a snackbar host, and two of the strings are waiting (the delete and 130 reload cases need new ones). Keeping the add dialog open while `progress` is 131 true, and closing it only on success, would also tell the user that something 132 is happening during the seconds a good address takes. 133 134 A lint rule or a small test asserting that every `*Error` channel a manager 135 exposes is collected somewhere would stop this class of defect coming back. 136 A sweep of every manager in `wallet/src/main/java` found no others: 137 138 ```console 139 $ for f in wallet/src/main/java/net/taler/wallet/*/[A-Z]*Manager.kt; do … 140 ExchangeManager.addError has no readers 141 ExchangeManager.deleteError has no readers 142 ExchangeManager.listError has no readers 143 ExchangeManager.reloadError has no readers 144 ``` 145 146 so this is a local lapse rather than a habit, and fixing the exchange list 147 closes the class.