fix: redact query strings in access logs [T-2463]
I'm sending a short status update. The change is written, but I can't run anything here because this session has no shell.
What was wrong: The access-log middleware used morgan's short format, which prints the full request URL with its query string. Emailed password-reset, invite and verify-email links carry secrets and the user's email address in the query. Opening one wrote the secret to stdout. Access logs are on by default, so anyone who can read the logs could use those links first.
What changed:
api/src/middlewares/morgan-middleware.ts:- New exported
redactUrl(url). It keeps the path and every query key and replaces each query value withREDACTED. A URL with no query comes back unchanged, and non-string input returns''instead of throwing. - New morgan token
safe-url, which returns `redactUrl(req.originalUrl || req.url)`. - New exported
SAFE_SHORT_FORMAT, which is theshortfields with:safe-urlin place of:url.
- New exported
api/src/app.module.ts:MorganMiddleware.configure(SAFE_SHORT_FORMAT)replaces'short'.api/src/middlewares/morgan-middleware.spec.ts(new) covers:- the reset-password example from the brief;
/projectsstaying unchanged;- a value that contains
=or?, a key with no value, and malformed input; - a
compilecheck that the oldshortline containsabcand the new format's line doesn't; - the fallback to
req.urlwhenoriginalUrlis missing.
Verification: I only checked by reading the code. I did not run yarn --cwd api lint, yarn --cwd api test or yarn --cwd api build. The fake req and res in the spec are built from morgan's token implementations, so a failure there is possible. Please let CI confirm, or run the three commands yourself.
For reviewers: A query key with no = is kept as written, because I treat it as a key rather than a value. That's fine for the current links, but a secret in that position would still be logged.
Task T-2463 · opened by an agent run; the description above is the run's own summary. Review before merging — merge policy is governed by the Work's merge-policy settings.
Summary by cubic
Redacts query string values in access logs so secrets from emailed reset, invite, and verify links no longer appear in stdout.
- Replaces morgan's
shortformat withSAFE_SHORT_FORMAT, which keeps the path and query keys but replaces every value withREDACTED. - URLs without a query string are unchanged; malformed or non-string input falls back safely.
- A query key with no
=is kept as written, so a secret in that position would still be logged.