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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): redact tokens from PUT /api/settings response too (#1821)
[._.]/ Adam Eivy374b6e470394
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 4d79b2a284..5ca9cda125 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -1,6 +1,6 @@## Security-- **`GET /api/settings` no longer leaks third-party API tokens** — the handler redacted only the top-level `secrets` key, so `imageGen.hfToken` (HuggingFace) and `civitai.apiKey` were returned in full. Both are now stripped from the response (their sibling config is preserved), matching how the Settings UI already reads only token *presence* from the dedicated `/image-gen/setup/hf-token-status` and `/loras/auth/civitai` status routes. On-disk values are untouched. (#1821)+- **Settings API no longer leaks third-party API tokens** — `GET` and `PUT /api/settings` redacted only the top-level `secrets` key, so `imageGen.hfToken` (HuggingFace) and `civitai.apiKey` were returned in full on both initial load and after any save. Both responses now run through a single sanitizer that strips those tokens (sibling config preserved), matching how the Settings UI already reads only token *presence* from the dedicated `/image-gen/setup/hf-token-status` and `/loras/auth/civitai` status routes. On-disk values are untouched. (#1821)- **Vision-test endpoint no longer reads arbitrary files** — `POST /api/providers/:id/test-vision` took `imagePath` straight from the request body, so a `../` traversal or absolute path could have any readable file base64-encoded and forwarded to the configured external vision provider. The image loader now allowlists `imagePath` to a real image basename under `data/screenshots` (via the canonical `resolveScreenshot` path resolver), rejecting traversal and absolute-path escapes before any file is read or forwarded. (#1820)## Addeddiff --git a/server/routes/settings.js b/server/routes/settings.jsindex 284b540cdf..058a62fc3c 100644--- a/server/routes/settings.js+++ b/server/routes/settings.js@@ -58,11 +58,19 @@ const redactExternalTokens = (settings) => {return next;};+// Single sanitizer every settings response (GET load + PUT save) runs through,+// so a leak can't reappear on one path after being closed on the other: strip+// the top-level `secrets` hierarchy, redact external tokens (#1821), then+// decorate server-authoritative bounds.+const sanitizeSettingsForResponse = (settings) => {+ const { secrets, ...safe } = settings;+ return decorateBounds(redactExternalTokens(safe));+};+// GET /api/settingsrouter.get('/', asyncHandler(async (req, res) => {const settings = await getSettings();- const { secrets, ...safe } = settings;- res.json(decorateBounds(redactExternalTokens(safe)));+ res.json(sanitizeSettingsForResponse(settings));}));// GET /api/settings/ai-assignments@@ -153,8 +161,7 @@ router.put('/', asyncHandler(async (req, res) => {// merged value so a save takes effect without a restart and without// re-reading the file.setCodexParallelLimit(merged.imageGen?.codex?.parallelLimit ?? CODEX_PARALLEL_DEFAULT);- const { secrets, ...safe } = merged;- res.json(decorateBounds(safe));+ res.json(sanitizeSettingsForResponse(merged));}));export default router;diff --git a/server/routes/settings.secretsStrip.test.js b/server/routes/settings.secretsStrip.test.jsindex 614add4381..86603c2fb4 100644--- a/server/routes/settings.secretsStrip.test.js+++ b/server/routes/settings.secretsStrip.test.js@@ -129,4 +129,23 @@ describe('GET /api/settings — external token redaction', () => {expect(Array.isArray(res.body.civitai)).toBe(true);expect(res.body.civitai[0]).toBe('legacy-junk');});++ it('also redacts the tokens from the PUT /api/settings save response', async () => {+ // Tokens already persisted; an unrelated save must not echo them back —+ // otherwise the leak just moves from initial load to the save round-trip.+ seedSettings({+ imageGen: { hfToken: 'hf_secret123', defaultModel: 'flux' },+ civitai: { apiKey: 'civ_secret456' },+ });+ const app = await buildApp();+ const res = await request(app).put('/api/settings').send({ timezone: 'UTC' });+ expect(res.status).toBe(200);+ expect(res.body.imageGen?.hfToken).toBeUndefined();+ expect(res.body.civitai?.apiKey).toBeUndefined();+ expect(res.body.imageGen?.defaultModel).toBe('flux');+ // On-disk values survive the redaction.+ const persisted = readSettingsFile();+ expect(persisted.imageGen?.hfToken).toBe('hf_secret123');+ expect(persisted.civitai?.apiKey).toBe('civ_secret456');+ });});