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:
2026-11-23 20:26:39 -05:00
parent 5cb80245ff
commit 60501b9508
4 changed files with 70 additions and 0 deletions

View File

@@ -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)]

View File

@@ -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;