aboutsummaryrefslogtreecommitdiffstats
path: root/lib/app.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-09-13 20:44:48 -0700
committerAdam Soltys <[email protected]>2026-09-13 20:44:48 -0700
commitd8a361bdcfaa8cc5b39d9675e74b0e1d2e42be2c (patch)
tree9709aa57f0e9138a23fef25ae3cb528e4c30068f /lib/app.ts
parent287fdb2b14b48d769e43a223c5c33049ff470880 (diff)
downloadcoinos-server-d8a361bdcfaa8cc5b39d9675e74b0e1d2e42be2c.tar.gz
coinos-server-d8a361bdcfaa8cc5b39d9675e74b0e1d2e42be2c.zip
security: drop the admin endpoint surface and land pending hardening
Removes the admin-gated endpoints and the account flags they set, plus a batch of hardening that had accumulated uncommitted in the tree. These were deployed and verified together, so they land as one change. admin surface: - drop POST /hidepay, POST /unlimit and GET /users, their handlers, and the now-unused admin preValidation export - `unlimited` was only ever written, never read; `hidepay` only appeared in output projections. Both flags go, along with their whitelist, public-fields and type entries. request log: - redactBody now recurses. It only masked top-level keys, so a body that nests credentials one level down wrote them to the log in plaintext, and pin fields were not on the list at all. payments: - sendOnchain/build gate `aid` through requireAccount, so a caller can only spend from an account it owns - sendOnchain signs only a tx we composed, matched against a short-lived per-account build receipt - raise xpay retry_for to 60s; route-finding preferred a drained zero-fee hop and burned the whole budget on it. check()'s reversal window keeps its 2x margin. ecash / invoices / webhooks: - resolve a token's mint through the IP-pinning fetcher instead of plain fetch, closing an unauthenticated SSRF path into the internal network - reject non-positive amounts before the balance write - /sign requires the caller to own the address, rather than signing under any address the hot wallet controls - webhook delivery no longer disables TLS verification; the body carries the merchant's shared secret registration: - refuse a username the v3 registrar holds unless the caller's own nostr key is the holder (lib/names.ts) liquid: - honour the deposit kill switch at invoice generation and at credit elements image: - pin 23.3.4 and verify the release tarball checksum Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0112TGi9GGNWqji1XQ5jZRzc
Diffstat (limited to 'lib/app.ts')
-rw-r--r--lib/app.ts37
1 files changed, 30 insertions, 7 deletions
diff --git a/lib/app.ts b/lib/app.ts
index d2949e61..65607d24 100644
--- a/lib/app.ts
+++ b/lib/app.ts
@@ -22,14 +22,37 @@ const app = fastify({
const reqLogger = pino(pino.destination("req"));
const resLogger = pino(pino.destination("res"));
-// Never log plaintext passwords. Redact password fields from request bodies
-// before they reach the request log.
-const REDACT_FIELDS = ["password", "confirm", "secret", "otpsecret"];
-const redactBody = (body: any) => {
- if (!body || typeof body !== "object") return body;
+// Never log plaintext credentials. This MUST recurse: the previous version
+// only redacted top-level keys, but POST /register posts {user:{password}} —
+// one level down — so every registration wrote its plaintext password to the
+// request log, and `pin`/`newpin` were not on the list at all (POST /pin,
+// POST /user and POST /take all carry one). Anything nested in an array is
+// covered too. Depth is bounded so a pathological body can't spin here.
+const REDACT_FIELDS = new Set([
+ "password",
+ "newpassword",
+ "confirm",
+ "pin",
+ "newpin",
+ "secret",
+ "otpsecret",
+ "nsec",
+ "seed",
+ "privkey",
+ "mnemonic",
+]);
+const redactBody = (body: any, depth = 0): any => {
+ if (!body || typeof body !== "object" || depth > 6) return body;
+ if (Array.isArray(body)) return body.map((v) => redactBody(v, depth + 1));
const copy: any = { ...body };
- for (const field of REDACT_FIELDS)
- if (field in copy) copy[field] = "[redacted]";
+ for (const k of Object.keys(copy)) {
+ if (REDACT_FIELDS.has(k)) {
+ if (copy[k] !== undefined && copy[k] !== null && copy[k] !== "")
+ copy[k] = "[redacted]";
+ } else if (copy[k] && typeof copy[k] === "object") {
+ copy[k] = redactBody(copy[k], depth + 1);
+ }
+ }
return copy;
};