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

fix([issue-2140]): local review — never full-disclose short last-4 masks; TZ-safe DATE round-trip

Adam Eivy8bb5ac79a381
diff --git a/server/lib/vaultCrypto.js b/server/lib/vaultCrypto.js
index c58598a63a..3251467caf 100644
--- a/server/lib/vaultCrypto.js
+++ b/server/lib/vaultCrypto.js
@@ -109,11 +109,16 @@ export function decryptValue(ciphertext) {
// ─── Masking ─────────────────────────────────────────────────────────────────
-/** `••••1234` — last 4 of the digits (or raw chars when digits are scarce). */
+/**
+ * `••••1234` — last 4 of the digits (or raw chars when digits are scarce).
+ * A source of 4 or fewer characters is fully masked: showing "the last 4" of a
+ * 4-char value would be full disclosure, not a mask.
+ */
function maskLastFour(value) {
const digits = value.replace(/\D/g, '');
- const tail = (digits.length >= 4 ? digits : value).slice(-4);
- return `••••${tail}`;
+ const source = digits.length >= 4 ? digits : value;
+ if (source.length <= 4) return '••••';
+ return `••••${source.slice(-4)}`;
}
/**
diff --git a/server/lib/vaultCrypto.test.js b/server/lib/vaultCrypto.test.js
index 583373228e..3e3ea7bc44 100644
--- a/server/lib/vaultCrypto.test.js
+++ b/server/lib/vaultCrypto.test.js
@@ -137,6 +137,12 @@ describe('maskValue', () => {
expect(maskValue('financial_account', 'DE89 3704 0044 0532 0130 00')).toBe('••••3000');
});
+ it('fully masks a last-4 value of 4 or fewer characters (never full disclosure)', () => {
+ expect(maskValue('financial_account', '1234')).toBe('••••');
+ expect(maskValue('ssn', '123')).toBe('••••');
+ expect(maskValue('phone', 'x1y2')).toBe('••••');
+ });
+
it('keeps the email domain visible', () => {
expect(maskValue('email', '[email protected]')).toBe('j•••@example.com');
expect(maskValue('email', 'no-at-sign')).toBe('••••');
diff --git a/server/services/privacyVault.db.test.js b/server/services/privacyVault.db.test.js
index cfb6a49bfb..9e3e35767e 100644
--- a/server/services/privacyVault.db.test.js
+++ b/server/services/privacyVault.db.test.js
@@ -121,6 +121,21 @@ describe.skipIf(!dbReady)('privacy vault DB round-trip', () => {
expect(revealed).toEqual({ id: record.id, type: 'phone', value: '+1 503 555 0142' });
});
+ it('round-trips valid_from/valid_to as plain YYYY-MM-DD strings (no TZ shift)', async () => {
+ const record = await vault.createVaultRecord({
+ type: 'address', label: 'Old place', value: '1 Old Rd, Portland, OR', status: 'previous',
+ validFrom: '2019-02-01', validTo: '2026-07-04',
+ });
+ created.push(record.id);
+ expect(record.validFrom).toBe('2019-02-01');
+ expect(record.validTo).toBe('2026-07-04');
+ const fetched = await vault.getVaultRecord(record.id);
+ expect(fetched.validFrom).toBe('2019-02-01');
+ expect(fetched.validTo).toBe('2026-07-04');
+ const cleared = await vault.updateVaultRecord(record.id, { validTo: null });
+ expect(cleared.validTo).toBe(null);
+ });
+
it('updates value (re-encrypt + re-mask) and metadata', async () => {
const record = await vault.createVaultRecord({
type: 'address', label: 'Home', value: '123 Main St, Portland, OR 97201',
diff --git a/server/services/privacyVault.js b/server/services/privacyVault.js
index e265f7d5ca..aba7db8d0a 100644
--- a/server/services/privacyVault.js
+++ b/server/services/privacyVault.js
@@ -25,7 +25,12 @@ import {
import { PRIVACY_SENSITIVE_TYPES, PRIVACY_SCAN_DEFAULT_TYPES } from '../lib/privacyValidation.js';
// Everything EXCEPT value_enc — list/read responses never carry ciphertext.
-const RECORD_COLUMNS = `id, type, label, masked_value, status, valid_from, valid_to,
+// DATE columns come back via to_char as plain 'YYYY-MM-DD' strings: node-postgres
+// otherwise parses DATE into a local-midnight JS Date, and re-serializing that
+// through toISOString() shifts the date back a day in UTC+N timezones.
+const RECORD_COLUMNS = `id, type, label, masked_value, status,
+ to_char(valid_from, 'YYYY-MM-DD') AS valid_from,
+ to_char(valid_to, 'YYYY-MM-DD') AS valid_to,
share_with_twin, use_for_scans, notes, created_at, updated_at`;
function rowToRecord(row) {
@@ -36,8 +41,8 @@ function rowToRecord(row) {
label: row.label,
maskedValue: row.masked_value,
status: row.status,
- validFrom: row.valid_from ? new Date(row.valid_from).toISOString().slice(0, 10) : null,
- validTo: row.valid_to ? new Date(row.valid_to).toISOString().slice(0, 10) : null,
+ validFrom: row.valid_from ?? null,
+ validTo: row.valid_to ?? null,
shareWithTwin: row.share_with_twin,
useForScans: row.use_for_scans,
notes: row.notes,