From 05ffcc85616f86109d7e0e0f432626b9bbebc6b9 Mon Sep 17 00:00:00 2001 From: Eric Bell Date: Tue, 24 Nov 2026 07:26:27 -0500 Subject: [PATCH] Add sanitize.js: secret-free copy under a new passphrase (Refs #19) Co-Authored-By: Claude Sonnet 5.5 --- OVERVIEW.md | 1 + build.js | 2 +- docs/MAINTENANCE.md | 4 ++ package.json | 1 + sanitize.js | 92 +++++++++++++++++++++++++++++++++++++++++++ test/sanitize.test.js | 62 +++++++++++++++++++++++++++++ 6 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 sanitize.js create mode 100644 test/sanitize.test.js diff --git a/OVERVIEW.md b/OVERVIEW.md index 692309f..e81cd42 100644 --- a/OVERVIEW.md +++ b/OVERVIEW.md @@ -23,6 +23,7 @@ There are no npm dependencies and no CDN or network calls at runtime. ``` build.js builds dist/final-wishes.html (optionally encrypting a JSON file into it) +sanitize.js `node sanitize.js --in real.html --out copy.html`: re-seals a copy with secrets erased under a new passphrase bump-version.js `npm run bump`, and the pre-commit hook's engine: advances src/version.js to today's date + next letter .githooks/pre-commit runs `bump-version.js --staged`; enable once per clone with `npm run hooks` package.json scripts: build, seal, test diff --git a/build.js b/build.js index 6ff4804..622e867 100644 --- a/build.js +++ b/build.js @@ -32,7 +32,7 @@ function parseArgs(argv) { return a; } -function promptHidden(question) { +export function promptHidden(question) { return new Promise((res, rej) => { if (!process.stdin.isTTY) return rej(new Error('No terminal to prompt on: set FW_PASSPHRASE instead.')); process.stdout.write(question); diff --git a/docs/MAINTENANCE.md b/docs/MAINTENANCE.md index 352e008..6466a82 100644 --- a/docs/MAINTENANCE.md +++ b/docs/MAINTENANCE.md @@ -224,6 +224,10 @@ To work on the layout somewhere less safe (a shared or online machine), open the Nothing is written until you Save, and saving over the file removes the secrets for good. Use **Backup copy** first, or save under a new name, if you need them again. Choosing "Keep them" dismisses the banner and changes nothing. +### Making a copy without secrets (the sanitize script) + +`node sanitize.js --in /path/real.html --out /path/copy.html` reads your real file (it is never changed), asks for its passphrase and a **new** passphrase for the copy, erases every value marked secret, and writes the copy with the newest app code. It prints what is still in the copy, section by section, so you can judge whether it is safe where you plan to put it. It refuses to write over the input, and refuses to reuse the real passphrase. Set `FW_PASSPHRASE` and `FW_NEW_PASSPHRASE` to skip the prompts. Only values flagged secret are erased: review anything sensitive that is not flagged. + ## Keep it current Nothing in the app reminds you to review. Set a yearly reminder. Things that go stale: card expiry dates, account balances and metal values, advisors' diff --git a/package.json b/package.json index 9f72501..1db907f 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "build": "node build.js", "test": "node --test", "seal": "node build.js --data data/seed.json", + "sanitize": "node sanitize.js", "bump": "node bump-version.js", "hooks": "git config core.hooksPath .githooks" }, diff --git a/sanitize.js b/sanitize.js new file mode 100644 index 0000000..ba8f4a6 --- /dev/null +++ b/sanitize.js @@ -0,0 +1,92 @@ +// Makes a copy of a Final Wishes file with every secret value erased, sealed under a NEW passphrase, +// so it can be kept somewhere less safe (a shared SSD, an online session) for working on the layout. +// The input file is only read. The copy carries the newest app code from src/. +// +// node sanitize.js --in real.html --out /path/copy.html +// +// Passphrases: FW_PASSPHRASE (current) and FW_NEW_PASSPHRASE (for the copy), else prompted for hidden. +// They are never accepted as arguments. Only values flagged `secret` are erased; the summary printed +// at the end lists what is still in the copy so you can judge whether it is safe to put where you plan to. +import { readFileSync, writeFileSync, mkdirSync, existsSync, realpathSync } from 'node:fs'; +import { fileURLToPath } from 'node:url'; +import { dirname, join, resolve } from 'node:path'; +import { assemble } from './src/template.js'; +import { encrypt, decrypt, passphraseProblem } from './src/crypto.js'; +import { assertValid, isSequence } from './src/model.js'; +import { clearSecrets } from './src/ops.js'; +import { bundleJs, promptHidden } from './build.js'; + +const root = dirname(fileURLToPath(import.meta.url)); + +export function extractPayload(html) { + const m = html.match(/