commit a8efc6021208e48a4366c4e91e12515c1b5b1a3e
parent 1fc5430520c72ec14e47c464ec9fe948f06a9f6a
Author: Florian Dold <dold@taler.net>
Date: Thu, 24 Sep 2026 22:27:31 +0200
wallet diagnostics: keep credentials out of HTTP and CLI logs
Diffstat:
5 files changed, 55 insertions(+), 9 deletions(-)
diff --git a/packages/taler-util/src/http-common.test.ts b/packages/taler-util/src/http-common.test.ts
@@ -30,6 +30,7 @@ import {
import { TalerErrorCode } from "./taler-error-codes.js";
import { CancellationToken } from "./CancellationToken.js";
import { qtartRedirectMode } from "./http-impl.qtart-common.js";
+import { Logger } from "./logging.js";
function jsonResponse(body: string, status = 400): HttpResponse {
const headers = new HeadersImpl();
@@ -104,6 +105,47 @@ function makeRecordingHttpLib(): {
return { http, requests };
}
+test("sensitive HTTP requests omit bodies from trace logs without changing transport", async (t) => {
+ const logs: string[] = [];
+ t.mock.method(Logger.prototype, "shouldLogTrace", () => true);
+ t.mock.method(Logger.prototype, "trace", (message: string) =>
+ logs.push(message),
+ );
+ const secret = "fountain-credential-for-test";
+ const body = { fountain_secret: secret };
+ const http = new HttpLib(
+ {
+ async fetch(_url, opt) {
+ assert.strictEqual(opt.sensitive, true);
+ assert.strictEqual(
+ new TextDecoder().decode(opt.body),
+ JSON.stringify(body),
+ );
+ return {
+ status: 200,
+ headers: new HeadersImpl(),
+ async bytes() {
+ return new TextEncoder().encode(JSON.stringify(body));
+ },
+ };
+ },
+ },
+ { enableThrottling: false },
+ );
+ const response = await http.fetch(
+ "https://merchant.example/fountain/withdraw",
+ {
+ method: "POST",
+ body,
+ sensitive: true,
+ },
+ );
+ assert.deepStrictEqual(await response.json(), body);
+ assert.strictEqual(await response.text(), JSON.stringify(body));
+ assert.ok(logs.some((line) => line.includes("POST")));
+ assert.ok(logs.every((line) => !line.includes(secret)));
+});
+
test("DELETE encodes a supplied JSON body", async () => {
const { http, requests } = makeRecordingHttpLib();
diff --git a/packages/taler-util/src/http-common.ts b/packages/taler-util/src/http-common.ts
@@ -151,6 +151,9 @@ export interface HttpRequestOptions {
body?: string | Uint8Array | object;
+ /** Omit request/response bodies and credential-bearing curl diagnostics. */
+ sensitive?: boolean;
+
/**
* How to handle redirects.
* Same semantics as WHATWG fetch.
@@ -262,9 +265,7 @@ export async function readTalerErrorResponse(
const talerErrorCode = errJson?.code;
if (typeof talerErrorCode !== "number") {
logger.warn(
- `malformed error response (status ${httpResponse.status}): ${j2s(
- errJson,
- )}`,
+ `error response for HTTP ${httpResponse.status} lacks a numeric Taler error code`,
);
throw TalerError.fromDetail(
TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
@@ -543,6 +544,7 @@ export interface HttpRawResponse {
export interface HttpRawRequestOptions {
method: "POST" | "PATCH" | "PUT" | "GET" | "DELETE";
headers: Record<string, string>;
+ sensitive?: boolean;
/**
* Already encoded and, if requested, already compressed. Undefined for
@@ -698,7 +700,7 @@ export class HttpLib implements HttpRequestLibrary {
if (logger.shouldLogTrace()) {
const timeoutInfo =
timeoutMs === undefined ? "no timeout" : `timeout ${timeoutMs}ms`;
- if (opt?.body != null) {
+ if (opt?.body != null && !opt.sensitive) {
logger.trace(
`request ${rid} ${requestMethod} ${requestUrl} (${timeoutInfo}): ${j2s(
opt.body,
@@ -720,6 +722,7 @@ export class HttpLib implements HttpRequestLibrary {
timeoutMs,
cancellationToken: opt?.cancellationToken,
redirect: opt?.redirect,
+ sensitive: opt?.sensitive,
});
} catch (cause) {
throw this.mapRequestError(
@@ -768,7 +771,7 @@ export class HttpLib implements HttpRequestLibrary {
const readText = async (): Promise<string> => {
const text = await decodeText();
- if (logger.shouldLogTrace()) {
+ if (!opt?.sensitive && logger.shouldLogTrace()) {
logger.trace(`request ${rid} TEXT: ${text}`);
}
return text;
@@ -794,7 +797,7 @@ export class HttpLib implements HttpRequestLibrary {
: "Invalid JSON from HTTP response",
);
}
- if (logger.shouldLogTrace()) {
+ if (!opt?.sensitive && logger.shouldLogTrace()) {
logger.trace(`request ${rid} JSON: ${j2s(json)}`);
}
return json;
diff --git a/packages/taler-util/src/http-impl.node.ts b/packages/taler-util/src/http-impl.node.ts
@@ -151,7 +151,7 @@ export const rawLib: HttpRawLib = {
const chunks: Uint8Array[] = [];
- if (SHOW_CURL_HTTP_REQUEST) {
+ if (SHOW_CURL_HTTP_REQUEST && !opt.sensitive) {
printAsCurl(parsedUrl.href, { ...opt, headers });
}
diff --git a/packages/taler-util/src/http-impl.qtart.ts b/packages/taler-util/src/http-impl.qtart.ts
@@ -80,7 +80,7 @@ export const rawLib: HttpRawLib = {
if (logger.shouldLogTrace()) {
logger.trace(`got qtart http response, status ${res.status}`);
- logger.trace(`response headers: ${j2s(res.headers)}`);
+ if (!opt.sensitive) logger.trace(`response headers: ${j2s(res.headers)}`);
}
const headers: HeadersImpl = new HeadersImpl();
diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts
@@ -3829,10 +3829,11 @@ advancedCli
logger.info("disconnected");
},
onMessage(msg) {
- logger.info(`message: ${j2s(msg)}`);
const op = (msg as any).operation;
const id = (msg as any).id;
const payload = (msg as any).args;
+ // Request payloads can contain fountain bearer credentials.
+ logger.info(`request: ${j2s({ operation: op, id })}`);
w.handleCoreApiRequest(op, id, payload)
.then((resp) => {
logger.info("sending response");