diff options
| author | Adam Soltys <[email protected]> | 2026-07-10 22:56:12 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-07-10 22:56:12 -0700 |
| commit | 4d97101726276543384c10f11a72a70f99336afb (patch) | |
| tree | 05679834accd4eb1902e9c26a9d35a22ffd7de4d /lib | |
| parent | 9f06a2d677e579609ab70e4f8dc0742d112cda47 (diff) | |
| download | coinos-server-4d97101726276543384c10f11a72a70f99336afb.tar.gz coinos-server-4d97101726276543384c10f11a72a70f99336afb.zip | |
logging: redact password fields from the request log
The preHandler request logger wrote the full request body, which included
plaintext passwords on auth requests. Redact password/confirm fields
before logging.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/app.ts | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -22,6 +22,17 @@ 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"]; +const redactBody = (body: any) => { + if (!body || typeof body !== "object") return body; + const copy: any = { ...body }; + for (const field of REDACT_FIELDS) + if (field in copy) copy[field] = "[redacted]"; + return copy; +}; + // app.addHook("onRequest", async (req) => { // reqLogger.info({ url: req.raw.url, id: req.id }); // }); @@ -55,7 +66,7 @@ app.addHook("preHandler", async (req) => { ip, headers: req.headers, query: req.query, - body: req.body, + body: redactBody(req.body), user: (req.user as any)?.username, id: req.id, }); |
