Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (claude+codex): redact JSON mirror, tighten secret regex, fix health metric keys

[._.]/ Adam Eivy4a81f5ca6639
diff --git a/server/services/legacyExport.js b/server/services/legacyExport.js
index f83c68030a..717753b094 100644
--- a/server/services/legacyExport.js
+++ b/server/services/legacyExport.js
@@ -40,12 +40,16 @@ const BRAIN_LEGACY_TYPES = ['people', 'projects', 'ideas', 'journals', 'links'];
// Health metrics surfaced in the summary, with the human label used in Markdown.
// Each value carries its own freshness date (last sync) as the source caveat.
+// Keys are the canonical stored metric names — `heart_rate_variability_sdnn`
+// (the alias in appleHealthQuery resolves it to `heart_rate_variability` too).
+// Only metrics whose points expose a numeric `qty`/`Avg`/`value` are listed:
+// `getLatestMetricValues` can't extract sleep (stored as `totalSleep`), so sleep
+// is left to the dedicated health follow-up rather than perpetually reported absent.
const HEALTH_METRICS = [
['resting_heart_rate', 'Resting heart rate', 'bpm'],
- ['heart_rate_variability', 'Heart rate variability', 'ms'],
+ ['heart_rate_variability_sdnn', 'Heart rate variability', 'ms'],
['weight_body_mass', 'Body mass', ''],
['step_count', 'Daily steps', ''],
- ['sleep_analysis', 'Sleep', ''],
['vo2_max', 'VO₂ max', ''],
];
@@ -74,8 +78,14 @@ export function redactSecrets(text) {
.replace(/\bxox[baprs]-[A-Za-z0-9-]{10,}\b/g, '[REDACTED]')
// Bearer tokens in headers
.replace(/\bBearer\s+[A-Za-z0-9._-]{20,}\b/g, 'Bearer [REDACTED]')
- // "password": "...", password=..., api_key: ...
- .replace(/("?(?:password|passwd|secret|api[_-]?key|token)"?\s*[:=]\s*"?)([^"\s,}]{6,})/gi, '$1[REDACTED]');
+ // PEM private-key blocks
+ .replace(/-----BEGIN (?:RSA |EC |OPENSSH |DSA |PGP )?PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC |OPENSSH |DSA |PGP )?PRIVATE KEY-----/g, '[REDACTED PRIVATE KEY]')
+ // Quoted config/JSON secret assignments — `"password": "..."`, `api_key='...'`.
+ // Require the value to be QUOTE-DELIMITED so free-text prose like
+ // `my secret: I never learned to swim` is not mangled (a real false-positive
+ // risk in autobiography/journal content). Token-shaped secrets pasted into
+ // prose are already caught by the specific patterns above, quoted or not.
+ .replace(/(["']?(?:password|passwd|secret|api[_-]?key|token)["']?\s*[:=]\s*)(["'])[^"'\n]{6,}\2/gi, '$1$2[REDACTED]$2');
}
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : null);
@@ -259,7 +269,7 @@ function buildIdentityProfileMd(d) {
}
if (d.genome?.uploaded) {
out.push('## Genome\n');
- const g = [`- **SNPs analyzed**: ${num(d.genome.snpCount)?.toLocaleString() || 'unknown'}`];
+ const g = [`- **SNPs analyzed**: ${num(d.genome.snpCount) != null ? d.genome.snpCount.toLocaleString() : 'unknown'}`];
if (d.genome.markerCount) g.push(`- **Markers tracked**: ${d.genome.markerCount}`);
out.push(g.join('\n'));
}
@@ -375,8 +385,12 @@ function titleize(s) {
.replace(/^./, c => c.toUpperCase());
}
+// Serialize to JSON with the SAME secret redaction the Markdown renderers
+// apply — the `data/*.json` mirror is the half of the bundle most likely to be
+// machine-scraped, so a token pasted into a note must not ride along in it
+// either. The replacer touches every string value.
function jsonFile(obj) {
- return JSON.stringify(obj, null, 2);
+ return JSON.stringify(obj, (_key, value) => (typeof value === 'string' ? redactSecrets(value) : value), 2);
}
// === Bundle assembly ===
diff --git a/server/services/legacyExport.test.js b/server/services/legacyExport.test.js
index adcdfcc29d..f40b5aa413 100644
--- a/server/services/legacyExport.test.js
+++ b/server/services/legacyExport.test.js
@@ -62,9 +62,25 @@ describe('redactSecrets', () => {
it('masks a GitHub PAT', () => {
expect(redactSecrets('ghp_0123456789abcdefghijklmnopqrstuvwx')).toBe('[REDACTED]');
});
- it('masks a password assignment', () => {
+ it('masks a quoted password/secret assignment', () => {
expect(redactSecrets('"password": "hunter2hunter2"')).toContain('[REDACTED]');
expect(redactSecrets('"password": "hunter2hunter2"')).not.toContain('hunter2');
+ expect(redactSecrets("api_key='abcdef123456'")).not.toContain('abcdef123456');
+ });
+ it('masks a PEM private-key block', () => {
+ const pem = '-----BEGIN PRIVATE KEY-----\nMIIEv...base64...\n-----END PRIVATE KEY-----';
+ expect(redactSecrets(pem)).toBe('[REDACTED PRIVATE KEY]');
+ });
+ it('does NOT mangle free-text prose that mentions secret/password words', () => {
+ // Regression for the tightened quoted-value rule — these are autobiography/journal
+ // sentences, not config, and must survive verbatim.
+ for (const prose of [
+ 'My biggest secret: I never learned to swim properly.',
+ 'The secret: always be kind to strangers.',
+ 'password = freedom, in my philosophy of life.',
+ ]) {
+ expect(redactSecrets(prose)).toBe(prose);
+ }
});
it('leaves ordinary prose untouched', () => {
const prose = 'I grew up near the ocean and loved skateboarding.';
@@ -113,13 +129,26 @@ describe('buildBundleFiles', () => {
expect(files.some(f => f.name.startsWith('autobiography/'))).toBe(false);
});
- it('redacts secrets pasted into brain content', () => {
+ it('redacts secrets pasted into brain content — in BOTH the Markdown and the JSON mirror', () => {
const d = sampleData();
d.brain.journals[0].content = 'token ghp_0123456789abcdefghijklmnopqrstuvwx end';
const { files } = buildBundleFiles(d);
const journal = files.find(f => f.name === 'brain/journals.md');
expect(journal.data.toString()).toContain('[REDACTED]');
expect(journal.data.toString()).not.toContain('ghp_0123');
+ // The machine-readable mirror must not leak it either (review finding).
+ const brainJson = files.find(f => f.name === 'data/brain.json');
+ expect(brainJson.data.toString()).toContain('[REDACTED]');
+ expect(brainJson.data.toString()).not.toContain('ghp_0123');
+ });
+
+ it('surfaces HRV stored under the canonical sdnn key', () => {
+ const d = sampleData();
+ d.health.heart_rate_variability_sdnn = { value: 45, date: '2026-06-11' };
+ const { files, sections } = buildBundleFiles(d);
+ expect(sections.health.metrics).toBeGreaterThanOrEqual(2);
+ const health = files.find(f => f.name === 'health/health-summary.md');
+ expect(health.data.toString()).toMatch(/Heart rate variability.*45/);
});
it('includes a health source caveat', () => {