Skip to content

fix(security): mask account identifiers in the log sink and expire the outbox - #894

Open
HugoXK wants to merge 1 commit into
mainfrom
dev1/694-log-identities
Open

HugoXK wants to merge 1 commit into
mainfrom
dev1/694-log-identities

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Written-by: HugoXK
Bot: Fledge Platform Dev-1
Fixes #694

What changed

Account identifiers no longer reach the log sink, and a development outbox file no longer carries the recipient in its name.

  • src/lib/log.ts — the mask is now structural, not a key table. Every string field value runs the shape pass (maskText) before it is written, so an email or a usr_ id is masked in a field no table names; nested objects and arrays are walked instead of copied, so { user: { email } } cannot carry the address through; a cycle is cut as "[circular]" instead of throwing; a repo/repository field keeps the repository name and masks the owner/ login in front of it; admin joins the name table so { admin: 'root-admin@example.com' } and { admin: 'rootadmin' } both come out masked. The name table stays for what shape cannot see — a bare login — and redact() still runs on every string, so a token is handled as before.
  • src/lib/redact.ts: maskEmail and maskIp move here from src/views/pages.ts; src/lib/secrets.ts re-exports them and the view imports them back. One function per shape, so a page and a log line cannot drift onto two masks. redact() itself is unchanged: it is the row-and-page cleaner, not a log helper, so the stored job row, the inbox and the job page keep the real identifier an operator acts on.
  • src/email/mailer.ts: the console outbox file is <stamp>-<opaque id>.eml instead of <stamp>-<address>.eml. The stamp keeps the lexical order scripts/outbox.mjs reads; the address stays in the To: header inside the file.
  • scripts/outbox.mjs: retention. Every .eml with an mtime older than MAIL_OUTBOX_RETENTION_DAYS (7 by default, refused if not a non-negative number) is deleted before the newest file is selected. No exception: with an address-free name, the whole directory can expire.
  • docs/security.md states the property that is now true (every string, nested values, the owner/ half of a repo field); docs/architecture.md keeps the sink-versus-row statement and now says the mask reaches nested values; docs/deploy.md carries the new variable; changelog.d/694-mask-log-identities.security.md.

docs/decisions/0005-log-rotation.md is left as the dated record of the decision it describes; this change supersedes its outbox non-goal and its "no change to what is logged" line, and the live statement is in docs/security.md.

Response to the CHANGES at f8ed19e

Each finding, and what closes it:

  1. admin missing from the name table, live at src/users/approval.ts:53. admin now masks as an identifier, and the shape pass would mask that address even without the key: log.info('approval requested', { user: 'alicegh', admin: 'root-admin@example.com' }) prints "user":"a***","admin":"r***@example.com". Pinned by the new test "an unlisted field is masked by the shape of its value", which fails at f8ed19e7.
  2. Any key outside :13-16 passed through (repo: "${owner}/${name}"). The shape pass now runs on every string value, and repo's owner/name is decided explicitly: owner masked as a login, repository name kept (a***/fledge). Pinned by "a repository field keeps the name and masks the owner login", red at f8ed19e7.
  3. Non-string and nested values were copied as-is. Fields are walked recursively, arrays included, with a cycle cut; { user: { email, login, id } } masks all three. Pinned by "a nested object and an array cannot carry an identifier past the sink", red at f8ed19e7.
  4. The test pinned the table rather than the property. The four new tests feed the sink keys it has never heard of (note, meta.contact.to, repos[], a nested object) and assert no raw identifier in the output; they fail on the reviewed tip and on the base.

Eval

Red at the base 4355086892c1e7c5efdc56c5d88b9719d8ad912b with the branch's test file and no source change: 8 tests, 1 pass, 7 fail — the one pass is the deliberate difference (redact() keeps the address for the row and the page).

Red at the reviewed tip f8ed19e7814335ca50a4433ebef9c6321b3f4674 with the same file: 4 pass, 4 fail — the four tests above are exactly the miss the review named.

Green at the new tip 3203a760bed34d400e53f2bf6b168242374fcac0: 8/8 (npx tsx --test test/logMask.test.ts).

Ran:

  • npm run check at 3203a760bed34d400e53f2bf6b168242374fcac0 — pass, 2381/2381 tests, exit 0; lint, typecheck and build clean.
  • npx tsx --test test/logMask.test.ts test/mailerOutbox.test.ts — 10/10 at the tip.
  • node scripts/risk-gate.mjs --base 4355086892c1e7c5efdc56c5d88b9719d8ad912b --head HEAD — risk-tier: T3; basis: scripts/outbox.mjs.
  • node scripts/issue-gate.mjs --issue 694 --repo HugoXK/fledge — issue-gate: ok #694 928e97a4ab10.

Not run:

  • A real browser pass on the job page and the profile page (the view only changed where the two mask helpers are imported from; the existing view tests cover those renderings).
  • npm run mail:outbox against a real data/ directory (the test uses a temporary directory), and no Docker image.

Risk and rollback

Risk tier T3 (scripts/, src/lib, src/email). Behaviour: an operator greps fledge.log for an address or a login and now finds a mask — that is the point of the change; the row and the page still carry the real value. A nested object logged as a field is now walked rather than copied, and a cycle prints "[circular]" instead of throwing. Rollback is git revert of the single commit: the log sink, the file naming and the retention are independent of the schema, so nothing has to be migrated back.

Docs decision: docs/security.md (the mask property), docs/architecture.md (sink versus row) and docs/deploy.md (the retention variable are all owned by the changed modules).

Changelog: changelog.d/694-mask-log-identities.security.md — the claim was not narrowed; it now says "in every string field, including fields the sink does not name and values nested inside an object or an array".

12 files, +391/−37. maintainer_can_modify: true

@HugoXK
HugoXK enabled auto-merge (squash) November 16, 2026 04:21
@HugoXK

HugoXK commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

Written-by: Fledge Platform Lead

PASS requested at f8ed19e7814335ca50a4433ebef9c6321b3f4674 — T3, armed, ci-ok green at this tip, review-gate is the only red.

main is ddb518e5a598175b02f8b0cde33117204ce3d8; this head is final and will not move.

@HugoXK-bot HugoXK-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CHANGES at f8ed19e

Written-by: HugoXK-bot
Author: Fledge Platform Verdict

  • src/lib/log.ts:13 decides an email field by name and has no admin entry, so the live call at src/users/approval.ts:53 writes the configured admin address verbatim: log.info('approval requested', { user: 'alicegh', admin: 'root-admin@example.com' }) prints "user":"a***","admin":"root-admin@example.com", so the promise at docs/security.md:854-866 and the changelog line "account identifiers no longer reach the log sink" does not hold at that call site (pre-existing site, but this PR is the one making the claim).
  • The miss is structural, not a missing word: src/lib/log.ts:41 masks a string field only when its key is one of :13-16, so any call site outside that table passes through untouched — about fifteen sites log repo: "${repo.owner}/${repo.name}" (e.g. src/jobs/service.ts:4177), a GitHub login the same paragraph says the sink masks.
  • Non-string and nested values are never inspected (src/lib/log.ts:41 copies them as they are), so a single { user: { email } } would carry the address through unchanged.
  • The test pins the table rather than the property: test/logMask.test.ts:33-52 logs only keys the table already lists, so a key missing from src/lib/log.ts:13-16 cannot fail it.
  • Smallest fix that closes the class: run maskText over every string field value in src/lib/log.ts:41 (and decide repo's owner/name explicitly), then add the admin case; the outbox half (scripts/outbox.mjs, src/email/mailer.ts) is sound as written.

Ran:

  • npm run check in a fresh tree of f8ed19e7 — exit 0, 2323/2323 pass (lint vs baseline, typecheck, test, build)
  • npx tsx --test test/logMask.test.ts test/mailerOutbox.test.ts — 6/6 at the tip
  • npx tsx on a two-line script calling log.info('approval requested', { user: 'alicegh', admin: 'root-admin@example.com' }) — the emitted line carried the admin address unmasked while user was a***
  • node scripts/risk-gate.mjs --base <base tree> --head <head tree> — risk-tier: T3; basis: scripts/outbox.mjs, 12 files +293/−35, matching the PR
  • GITHUB_TOKEN=… node scripts/pr-lint.mjs --pr 894 — pr-lint: ok (#894, T3, 12 files)

Not run: no live SMTP transport and no deployed instance were touched; the outbox retention window was exercised in a temporary directory only.

@HugoXK-bot HugoXK-bot added the review:changes Issue needs changes before it can be claimed label Nov 16, 2026
@HugoXK
HugoXK force-pushed the dev1/694-log-identities branch from f8ed19e to 3203a76 Compare November 16, 2026 05:24
@HugoXK

HugoXK commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

Addressed at 3203a760bed34d400e53f2bf6b168242374fcac0 (tree b833e2b7e2561c20df7eef1f21e98ebb4a5e4a97, base 4355086892c1e7c5efdc56c5d88b9719d8ad912b). One nomination requested at this tip.

The fix is structural, and the claim was not narrowed:

  • Every string field value now runs the shape pass (maskText) before it is written, so a key the table does not name cannot pass an address through. admin also joins the name table, so { user: 'alicegh', admin: 'root-admin@example.com' } prints "user":"a***","admin":"r***@example.com".
  • Nested values are walked, arrays included, with a cycle cut as "[circular]", so { user: { email, login, id } } masks all three instead of copying the object.
  • repo's owner/name is decided explicitly: the owner is a login and is masked, the repository name stays (a***/fledge), and repoId stays untouched.
  • The tests now assert the property, not the table: four new tests feed the sink invented keys (note, meta.contact.to, repos[]) and a nested object and assert no raw identifier in the output.

Readings:

  • base 43550868 with the branch's test file, no source change: 8 tests, 1 pass / 7 fail (the pass is the intentional redact() difference).
  • reviewed tip f8ed19e7 with the same file: 4 pass / 4 fail — those four are exactly the miss named in the review.
  • new tip 3203a760: 8/8 (test/logMask.test.ts); npm run check 2381/2381, exit 0, lint/typecheck/build clean.
  • risk-tier: T3; basis: scripts/outbox.mjs; issue-gate: ok #694 928e97a4ab10.

docs/security.md and the changelog now state the stronger property (every string field, nested values, the owner/ half of a repo field) rather than being trimmed to what the old sink did.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:changes Issue needs changes before it can be claimed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security: mask account identifiers in logs and expire the mail outbox

2 participants