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: redact imageGen.hfToken and civitai.apiKey from GET /api/settings (#1821)

[._.]/ Adam Eivyf36e3a3a2a61
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 429ae009d1..4d79b2a284 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -1,5 +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)
- **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)
## Added
diff --git a/server/routes/settings.js b/server/routes/settings.js
index 4764bdc47c..284b540cdf 100644
--- a/server/routes/settings.js
+++ b/server/routes/settings.js
@@ -9,6 +9,7 @@ import {
CODEX_PARALLEL_DEFAULT,
} from '../services/mediaJobQueue/index.js';
import { asyncHandler } from '../lib/errorHandler.js';
+import { isPlainObject } from '../lib/objects.js';
import { backupConfigSchema, sharingSettingsPatchSchema, featureProviderConfigSchema, codeReviewSettingsSchema, locationSettingsSchema, settingsEmbeddingsSchema, citySnapshotConfigSchema, apiAccessSettingsSchema, loraTrainingConfigSchema, pipelineEditorialChecksSettingsSchema, validateRequest } from '../lib/validation.js';
const router = Router();
@@ -37,11 +38,31 @@ const decorateBounds = (settings) => ({
},
});
+// Third-party API tokens that live OUTSIDE the `secrets.*` hierarchy but must
+// never be echoed to the client (#1821). The Settings UI reads only their
+// *presence* from dedicated status routes (`GET /api/image-gen/setup/hf-token-
+// status`, `GET /api/loras/auth/civitai` → `hasKey`), never the raw value here,
+// so stripping them is non-breaking. Sibling fields under each parent are
+// preserved; arrays are left untouched (a legacy/malformed `civitai: ['x']`
+// must not be spread into `{ '0': 'x' }`).
+const redactExternalTokens = (settings) => {
+ const next = { ...settings };
+ if (isPlainObject(next.imageGen)) {
+ const { hfToken, ...rest } = next.imageGen;
+ next.imageGen = rest;
+ }
+ if (isPlainObject(next.civitai)) {
+ const { apiKey, ...rest } = next.civitai;
+ next.civitai = rest;
+ }
+ return next;
+};
+
// GET /api/settings
router.get('/', asyncHandler(async (req, res) => {
const settings = await getSettings();
const { secrets, ...safe } = settings;
- res.json(decorateBounds(safe));
+ res.json(decorateBounds(redactExternalTokens(safe)));
}));
// GET /api/settings/ai-assignments
diff --git a/server/routes/settings.secretsStrip.test.js b/server/routes/settings.secretsStrip.test.js
index 5ee44a1be0..614add4381 100644
--- a/server/routes/settings.secretsStrip.test.js
+++ b/server/routes/settings.secretsStrip.test.js
@@ -85,3 +85,48 @@ describe('PUT /api/settings — secrets-strip', () => {
expect(readSettingsFile().timezone).toBe('Europe/Berlin');
});
});
+
+// Regression for #1821: third-party API tokens stored OUTSIDE the `secrets.*`
+// hierarchy (`imageGen.hfToken`, `civitai.apiKey`) must never be echoed by
+// GET /api/settings. The Settings UI reads only their presence from dedicated
+// status routes, so stripping the raw values is non-breaking.
+describe('GET /api/settings — external token redaction', () => {
+ it('omits imageGen.hfToken and civitai.apiKey while preserving siblings', async () => {
+ seedSettings({
+ timezone: 'UTC',
+ imageGen: { hfToken: 'hf_secret123', defaultModel: 'flux' },
+ civitai: { apiKey: 'civ_secret456', autoDownload: true },
+ });
+ const app = await buildApp();
+ const res = await request(app).get('/api/settings');
+ expect(res.status).toBe(200);
+ // Tokens are stripped from the response...
+ expect(res.body.imageGen?.hfToken).toBeUndefined();
+ expect(res.body.civitai?.apiKey).toBeUndefined();
+ // ...but their sibling config is preserved.
+ expect(res.body.imageGen?.defaultModel).toBe('flux');
+ expect(res.body.civitai?.autoDownload).toBe(true);
+ // ...and the on-disk values are untouched (redaction is response-only).
+ const persisted = readSettingsFile();
+ expect(persisted.imageGen?.hfToken).toBe('hf_secret123');
+ expect(persisted.civitai?.apiKey).toBe('civ_secret456');
+ });
+
+ it('leaves settings without those keys unchanged', async () => {
+ seedSettings({ timezone: 'UTC', imageGen: { defaultModel: 'flux' } });
+ const app = await buildApp();
+ const res = await request(app).get('/api/settings');
+ expect(res.status).toBe(200);
+ expect(res.body.imageGen?.defaultModel).toBe('flux');
+ expect(res.body.civitai).toBeUndefined();
+ });
+
+ it('does not spread a malformed array-valued civitai into index keys', async () => {
+ seedSettings({ civitai: ['legacy-junk'] });
+ const app = await buildApp();
+ const res = await request(app).get('/api/settings');
+ expect(res.status).toBe(200);
+ expect(Array.isArray(res.body.civitai)).toBe(true);
+ expect(res.body.civitai[0]).toBe('legacy-junk');
+ });
+});