Add ?reset=1 route that erases secret-flagged values (Refs #19)
After unlock, a banner offers to clear every secret field and secret sequence step. Nothing is written until Save. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -217,6 +217,12 @@ of the document, so it is saved with the rest and is encrypted too. Open
|
||||
- Keep the left and middle text short. If the line gets crowded, the left
|
||||
field wraps first; the right and middle fields never wrap.
|
||||
|
||||
## Reset: erase secrets before working online (issue #19)
|
||||
|
||||
To work on the layout somewhere less safe (a shared or online machine), open the file with `?reset=1` on the end of its address, for example `final-wishes.html?reset=1` (`#reset=1` works too). After you unlock it, a banner offers to erase every value marked secret: secret fields, secret images and secret steps. Labels, structure and everything else stay.
|
||||
|
||||
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.
|
||||
|
||||
## 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'
|
||||
|
||||
23
src/app.js
23
src/app.js
@@ -20,6 +20,28 @@
|
||||
error: '',
|
||||
};
|
||||
|
||||
// ?reset=1 (or #reset=1): after unlock, offer to erase every secret value.
|
||||
const resetRequested = /[?#&]reset=1(?![0-9])/.test(location.search + location.hash);
|
||||
const resetBanner = () => {
|
||||
const n = countSecrets(state.doc);
|
||||
const done = () => { state.resetOffered = true; render(); };
|
||||
return h('div', { class: 'card', role: 'alert' },
|
||||
h('h2', {}, 'Reset: erase secret values'),
|
||||
h('p', {}, n ? 'This will erase ' + n + ' secret value' + (n === 1 ? '' : 's') + ' (passwords, PINs, secret images and steps) from this document in memory. Labels and everything else stay.'
|
||||
: 'This document has no secret values to erase.'),
|
||||
h('p', {}, 'Nothing is written until you Save. Make a Backup copy first if you may need the secrets again, because saving over this file removes them for good.'),
|
||||
h('div', { class: 'row' },
|
||||
n ? btn('Erase ' + n + ' secret value' + (n === 1 ? '' : 's'), () => {
|
||||
const erased = clearSecrets(state.doc);
|
||||
state.revealed = new WeakSet();
|
||||
state.resetOffered = true;
|
||||
markDirty();
|
||||
state.status = 'Erased ' + erased + ' secret value' + (erased === 1 ? '' : 's') + '. Save to keep this.';
|
||||
render();
|
||||
}, 'primary') : null,
|
||||
btn(n ? 'Keep them' : 'Dismiss', done)));
|
||||
};
|
||||
|
||||
function h(tag, attrs, ...kids) {
|
||||
const el = document.createElement(tag);
|
||||
for (const [k, v] of Object.entries(attrs || {})) {
|
||||
@@ -770,6 +792,7 @@
|
||||
btn('Change passphrase', changePassphrase),
|
||||
btn('Print…', openPrintDialog),
|
||||
btn(state.editing ? 'Done editing' : 'Edit', () => { state.editing = !state.editing; render(); }, state.editing ? 'primary' : ''))),
|
||||
resetRequested && !state.resetOffered ? resetBanner() : null,
|
||||
h('div', { class: 'layout' }, renderNav(),
|
||||
h('main', {}, onHeader ? [h('h2', {}, 'Print header'), headerPanel()]
|
||||
: sec ? [h('h2', {}, sec.title), state.editing ? editSection(sec) : viewSection(sec)]
|
||||
|
||||
16
src/ops.js
16
src/ops.js
@@ -180,6 +180,22 @@ export function allSequences(doc) {
|
||||
return out;
|
||||
}
|
||||
|
||||
// Erase the content of every secret field and secret frame (labels, structure
|
||||
// and the secret flags stay). Returns how many values were erased.
|
||||
export function clearSecrets(doc) {
|
||||
let n = 0;
|
||||
const frames = (q) => { for (const f of q.frames) if (f.secret && (f.image || String(f.text || '').trim())) { f.image = ''; f.text = ''; n++; } };
|
||||
for (const s of doc.sections) {
|
||||
for (const r of s.records || []) {
|
||||
if (isSequence(r)) frames(r);
|
||||
else for (const f of r.fields) if (f.secret && f.value) { f.value = ''; n++; }
|
||||
}
|
||||
for (const it of s.items || []) if (isSequence(it)) frames(it);
|
||||
for (const q of s.sequences || []) frames(q);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
// The ordered list a new sequence goes into for this kind of section.
|
||||
export function sequenceList(section) {
|
||||
if (section.kind === 'records') return section.records;
|
||||
|
||||
@@ -320,3 +320,28 @@ test('sub-tab ids are unique across the document', () => {
|
||||
const ids = new Set([t.id, ...s.records.map((r) => r.id), s.id]);
|
||||
assert.equal(ids.size, 5);
|
||||
});
|
||||
|
||||
test('clearSecrets erases secret fields and frames, keeps the rest, returns the count', async () => {
|
||||
const { clearSecrets, addSequence, addFrame } = await import('../src/ops.js');
|
||||
const { countSecrets } = await import('../src/print.js');
|
||||
const doc = emptyDocument('x');
|
||||
const s = addSection(doc, 'records', 'Accounts');
|
||||
const r = addRecord(doc, s);
|
||||
addField(r); addField(r);
|
||||
r.fields[0].label = 'User'; r.fields[0].value = 'bob';
|
||||
r.fields[1].label = 'PIN'; r.fields[1].value = '1234'; r.fields[1].secret = true;
|
||||
const q = addSequence(doc, s);
|
||||
const fr = addFrame(q);
|
||||
fr.text = 'tap here'; fr.secret = true;
|
||||
const before = countSecrets(doc);
|
||||
assert.equal(before, 2);
|
||||
assert.equal(clearSecrets(doc), 2);
|
||||
assert.equal(countSecrets(doc), 0);
|
||||
assert.equal(r.fields[0].value, 'bob');
|
||||
assert.equal(r.fields[1].value, '');
|
||||
assert.equal(r.fields[1].secret, true);
|
||||
assert.equal(r.fields[1].label, 'PIN');
|
||||
assert.equal(fr.text, '');
|
||||
assert.deepEqual(validate(doc), []);
|
||||
assert.equal(clearSecrets(doc), 0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user