Keep a bank's raw error text from failing the answer it rides on #5

Open
opened 2026-11-22 13:22:11 +00:00 by jorijnvdgraaf · 0 comments

When the bank, or something in front of it, answers an error with a body that is no JSON, nostro keeps the first 300 bytes of that body as the error's text. Those bytes need not be UTF-8, and D-Bus carries nothing else. The text then rides on an answer as a note, and the answer fails on it: a call that was carried out is answered InvalidArgument, which every client reads as "refused, nothing was sent".

Found by the pre-push review of 1.0.0 (the bug-prover lens). It is older than that release: the path is the same at 0.0.0.

Where

Links are to the tree at 8dd31e2 (1.0.0).

  • ErrorMessage falls back to std::string(body.substr(0, 300)) for a body it cannot read as bunq's JSON. A cut at 300 bytes can split a character of a body that is UTF-8, and an error page in Latin-1 is not UTF-8 to begin with. The text ends up in the BunqError.
  • Notes are made of such errors' what(): a connector that is unavailable when the connectors are read (Nostro-Connector.cpp:141, and again in the worker at :300), a logout that failed (:577), and a request for money that was made and could not be read back (Nostro-Bunq-Payments.cpp:272).
  • The worker's Answer runs the call's work and then appends the notes, taking them out of the list first. Wire<std::string>::Append throws std::invalid_argument("text that is not UTF-8 cannot be sent to nostrod") when sd-bus refuses a string, and ErrorFor answers that as InvalidArgument. The notes are gone with it.

Concrete cases

  1. A request for money. BunqAccount::Request posts the request, which bunq makes, and reads it back. The read gets a proxy's 502 page. The catch notes "request N was made, but reading it back failed: …" with the page's first 300 bytes and returns the request all the same, as it is meant to. The answer then fails on the note. The caller is told InvalidArgument; the app shows "That cannot be done … Nothing was sent." Asking again asks twice.
  2. A payment. One of two connectors is unavailable when the worker first reads them, with such an error text. That note waits for the next answer, which is the payment's, made from the other connector. The payment is carried out, and its answer fails on the note in the same way.
  3. The error itself. ErrorReply hands the message to sd_bus_message_new_method_errorf. Its comment says that making an error answer fails only when memory runs out; with a message that is not UTF-8 it presumably fails as well, and the caller then waits for its own timeout, ten minutes by default.

What it would take

  • Make the text valid where it is taken from the bank: cut the raw body on a character's boundary and replace what is not UTF-8, as the request bodies already do with dump's replace handler.
  • Or make an answer unable to fail on its notes: clean each note, and an error's message, where the worker appends them.
  • A test in ShouldMoveMoney or ShouldServeEveryUser: a Fault on the read-back of a request whose body is <html> with a byte that is no UTF-8, and the request's answer still arrives, with its note.

What was run, and what was read

Run, against libsystemd 262.1: sd_bus_message_append_basic with type s returns -EINVAL for a Latin-1 byte, for a three-byte character cut after its second byte, and for an over-long sequence. The rest is from reading the code at the commit above. Case 3 was not run, and no test fails on any of this today.

When the bank, or something in front of it, answers an error with a body that is no JSON, nostro keeps the first 300 bytes of that body as the error's text. Those bytes need not be UTF-8, and D-Bus carries nothing else. The text then rides on an answer as a note, and the answer fails on it: a call that was carried out is answered `InvalidArgument`, which every client reads as "refused, nothing was sent". Found by the pre-push review of 1.0.0 (the bug-prover lens). It is older than that release: the path is the same at 0.0.0. ## Where Links are to the tree at 8dd31e2 (1.0.0). - [`ErrorMessage`](https://forgejo.catcrafts.net/Catcrafts/Nostro/src/commit/8dd31e2bb9eb3ac3f7c73ea5f35ad1986b61877b/implementations/Nostro-Bunq.cpp#L71-L94) falls back to `std::string(body.substr(0, 300))` for a body it cannot read as bunq's JSON. A cut at 300 bytes can split a character of a body that is UTF-8, and an error page in Latin-1 is not UTF-8 to begin with. The text ends up in the `BunqError`. - Notes are made of such errors' `what()`: a connector that is unavailable when the connectors are read ([`Nostro-Connector.cpp:141`](https://forgejo.catcrafts.net/Catcrafts/Nostro/src/commit/8dd31e2bb9eb3ac3f7c73ea5f35ad1986b61877b/implementations/Nostro-Connector.cpp#L141), and again in the worker at [`:300`](https://forgejo.catcrafts.net/Catcrafts/Nostro/src/commit/8dd31e2bb9eb3ac3f7c73ea5f35ad1986b61877b/implementations/Nostro-Daemon-Worker.cpp#L300)), a logout that failed (`:577`), and a request for money that was made and could not be read back ([`Nostro-Bunq-Payments.cpp:272`](https://forgejo.catcrafts.net/Catcrafts/Nostro/src/commit/8dd31e2bb9eb3ac3f7c73ea5f35ad1986b61877b/implementations/Nostro-Bunq-Payments.cpp#L258-L282)). - The worker's [`Answer`](https://forgejo.catcrafts.net/Catcrafts/Nostro/src/commit/8dd31e2bb9eb3ac3f7c73ea5f35ad1986b61877b/implementations/Nostro-Daemon-Worker.cpp#L346-L354) runs the call's work and then appends the notes, taking them out of the list first. [`Wire<std::string>::Append`](https://forgejo.catcrafts.net/Catcrafts/Nostro/src/commit/8dd31e2bb9eb3ac3f7c73ea5f35ad1986b61877b/implementations/Nostro-Bus.cpp#L123-L130) throws `std::invalid_argument("text that is not UTF-8 cannot be sent to nostrod")` when sd-bus refuses a string, and [`ErrorFor`](https://forgejo.catcrafts.net/Catcrafts/Nostro/src/commit/8dd31e2bb9eb3ac3f7c73ea5f35ad1986b61877b/implementations/Nostro-Daemon-Worker.cpp#L102-L124) answers that as `InvalidArgument`. The notes are gone with it. ## Concrete cases 1. A request for money. `BunqAccount::Request` posts the request, which bunq makes, and reads it back. The read gets a proxy's 502 page. The catch notes "request N was made, but reading it back failed: …" with the page's first 300 bytes and returns the request all the same, as it is meant to. The answer then fails on the note. The caller is told `InvalidArgument`; the app shows "That cannot be done … Nothing was sent." Asking again asks twice. 2. A payment. One of two connectors is unavailable when the worker first reads them, with such an error text. That note waits for the next answer, which is the payment's, made from the other connector. The payment is carried out, and its answer fails on the note in the same way. 3. The error itself. `ErrorReply` hands the message to `sd_bus_message_new_method_errorf`. Its comment says that making an error answer fails only when memory runs out; with a message that is not UTF-8 it presumably fails as well, and the caller then waits for its own timeout, ten minutes by default. ## What it would take - Make the text valid where it is taken from the bank: cut the raw body on a character's boundary and replace what is not UTF-8, as the request bodies already do with `dump`'s replace handler. - Or make an answer unable to fail on its notes: clean each note, and an error's message, where the worker appends them. - A test in `ShouldMoveMoney` or `ShouldServeEveryUser`: a `Fault` on the read-back of a request whose body is `<html>` with a byte that is no UTF-8, and the request's answer still arrives, with its note. ## What was run, and what was read Run, against libsystemd 262.1: `sd_bus_message_append_basic` with type `s` returns `-EINVAL` for a Latin-1 byte, for a three-byte character cut after its second byte, and for an over-long sequence. The rest is from reading the code at the commit above. Case 3 was not run, and no test fails on any of this today.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Catcrafts/Nostro#5
No description provided.