From 97c0b423d1f9199775685b05df5bbe662ead2200 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 23 Nov 2026 23:41:50 +0100 Subject: [PATCH] taler-api: keep the value of a refused path segment out of the log When a path segment does not deserialize, the error's hint is axum's message, which quotes the segment ("Cannot parse `id` with value `abc` to a `u32`"). The conversion from PathRejection set no log text, so the request logger wrote that hint at WARN, and a segment can be a secret, such as a nonce, or personal data, such as an account name. The log now names the segment and the kind of error ("id: expected u32"), as for refused bodies and queries; the client still gets axum's whole message as the hint, and the debug log has it too. Assisted by LLM --- common/taler-api/src/error.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/common/taler-api/src/error.rs b/common/taler-api/src/error.rs index 3e318fc..f38684f 100644 --- a/common/taler-api/src/error.rs +++ b/common/taler-api/src/error.rs @@ -243,12 +243,41 @@ impl From for ApiError { } } +/// Describe a path segment that did not deserialize for logging without +/// quoting it: axum's message does ("Cannot parse `id` with value `abc` to a +/// `u64`"), and a segment can be a secret, such as a nonce, or personal data, +/// such as an account name. +fn path_error_kind(kind: &ErrorKind) -> String { + match kind { + ErrorKind::ParseErrorAtKey { + key, expected_type, .. + } => format!("{key}: expected {expected_type}"), + ErrorKind::ParseErrorAtIndex { + index, + expected_type, + .. + } => format!("{index}: expected {expected_type}"), + ErrorKind::ParseError { expected_type, .. } => format!("expected {expected_type}"), + ErrorKind::InvalidUtf8InPathParam { key } => format!("{key}: invalid UTF-8"), + ErrorKind::DeserializeError { key, message, .. } => { + format!("{key}: {}", serde_error_kind(message)) + } + ErrorKind::Message(message) => serde_error_kind(message).to_owned(), + // Mistakes of the route, which quote no value. + ErrorKind::WrongNumberOfParameters { .. } | ErrorKind::UnsupportedType { .. } => { + kind.to_string() + } + _ => "invalid path segment".to_owned(), + } +} + impl From for ApiError { fn from(value: PathRejection) -> Self { match value { PathRejection::FailedToDeserializePathParams(err) => { let kind = err.into_kind(); - let err = failure(ErrorCode::GENERIC_PATH_SEGMENT_MALFORMED, &kind); + let err = failure(ErrorCode::GENERIC_PATH_SEGMENT_MALFORMED, &kind) + .with_log(path_error_kind(&kind)); match kind { ErrorKind::ParseErrorAtKey { key, .. } | ErrorKind::InvalidUtf8InPathParam { key } -- 2.47.3