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: mask credential-named provider env vars even when not marked secret (#12490)

[._.]/ Adam Eivyb82d6db7c838
diff --git a/client/src/utils/providerReadiness.js b/client/src/utils/providerReadiness.js
index ad49174fb8..c56179b8c9 100644
--- a/client/src/utils/providerReadiness.js
+++ b/client/src/utils/providerReadiness.js
@@ -15,6 +15,7 @@
* Re-exported by `./providers.js` for existing `utils/providers` imports.
*/
+import { isCredentialEnvVarName, isNonCredentialEnvVarName } from '../../../server/lib/credentialEnvVars.js';
import { isPrivateNetworkEndpoint } from './providerEndpoints.js';
import { gatewayForProvider, isGatewayBackedProvider } from './providerGateways.js';
import { isApiProvider, isCodexSubscriptionProvider, isProcessProvider } from './providerTypes.js';
@@ -144,17 +145,9 @@ export const providerRuntimeKey = (provider) => {
return runnerCommandBaseName(command.trim());
};
-// Environment variables whose names are conventionally credentials. The
-// explicit secretEnvVars list remains the primary source, but it is a masking
-// list rather than a credential schema — providers may mark optional values
-// such as AWS_PROFILE secret too. Filter both sources so only actual credential
-// names participate in readiness. The explicit list can still name a custom
-// credential that does not follow this convention (for example MY_LLM_KEY).
-const CREDENTIAL_ENV_VAR_RE = /(?:^|_)(?:API_KEY|APIKEY|AUTH|ACCESS_KEY|ACCESS_TOKEN|BEARER|CLIENT_SECRET|CREDENTIALS?|KEY|PASSWORD|PRIVATE_KEY|SECRET|TOKEN)(?:_|$)/i;
-
-const NON_CREDENTIAL_ENV_VAR_RE = /(?:^|_)(?:BASE_URL|CONFIG|CONFIG_CONTENT|ENDPOINT|HOST|MODEL|MODE|PATH|PORT|PROFILE|REGION)(?:_|$)/i;
-
-const NON_CREDENTIAL_ENV_VAR_NAMES = new Set(['CLAUDE_CODE_USE_BEDROCK']);
+// The name classifier lives in server/lib (it also drives response masking).
+// The explicit secretEnvVars list can still name a custom credential that does
+// not follow the convention (for example MY_LLM_KEY).
const providerHasStoredKey = (provider) =>
provider?.hasApiKey === true || Boolean(provider?.apiKey);
@@ -166,9 +159,8 @@ const credentialEnvVars = (provider) => {
const explicit = new Set(secretEnvVars.filter((name) => typeof name === 'string' && name !== ''));
const names = [...secretEnvVars, ...Object.keys(envVars)];
return [...new Set(names.filter((name) => typeof name === 'string'
- && !NON_CREDENTIAL_ENV_VAR_NAMES.has(name)
- && !NON_CREDENTIAL_ENV_VAR_RE.test(name)
- && (explicit.has(name) || CREDENTIAL_ENV_VAR_RE.test(name))))];
+ && !isNonCredentialEnvVarName(name)
+ && (explicit.has(name) || isCredentialEnvVarName(name))))];
};
/**
diff --git a/server/lib/README.md b/server/lib/README.md
index a266e08895..8c58a20727 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -32,6 +32,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `peerExecutionAuthority.js` | Non-rewound receiver execution epoch and restore-owner journal; default-deny on stale evidence or pending/conflicting recovery. Invalidates grants on identity changes and refuses stale epochs. |
| `appDeployFlags.js` | Shared allowlist of flags PortOS may forward to a managed app's `deploy.sh`, consumed by socket validation and deployment orchestration without reversing the lib/services dependency. |
| `apiContractSchemas.js` | Canonical Zod request contracts for externally callable APIs plus `zodToOpenApiSchema` (plain JSON Schema — the 3.0.3 conversion happens at the OpenAPI document boundary, not here); runtime routes and OpenAPI use the same schema objects. |
+| `credentialEnvVars.js` | `isCredentialEnvVarName(name)` / `isNonCredentialEnvVarName(name)` / `isMaskedEnvVar(name, secretEnvVars)`: name-convention classifier for credential env vars (API_KEY, TOKEN, SECRET…), shared by provider response masking and the client readiness check. Pure. |
| `codeAnimationAcceptance.js` | Code Animation production acceptance: splits run evidence into technical/visual/temporal/sound (unmeasured stays unverified), decides promotability, freezes source/audio/render hashes and detects stale acceptance. Pure. |
| `codeAnimationContainment.js` | Code Animation production worker containment contract: per-platform enforced mechanism (macOS Seatbelt or Linux bubblewrap, otherwise refusal), deny-by-default profiles and a process-denying Linux seccomp filter, from-scratch worker environment, operator tool-root rules, tool configuration and worker limit schemas. Pure; the runner is `services/codeAnimation/containedWorker.js`. |
| `generatedPreviewSandbox.js` | OS network-isolation plan for generated preview browsers: macOS Seatbelt or Linux bubblewrap, otherwise refusal. The jail denies IP and the host DNS resolver; Chrome flags are defense in depth. Pure; the launcher is `services/htmlComposition/ownedBrowser.js`. |
diff --git a/server/lib/credentialEnvVars.js b/server/lib/credentialEnvVars.js
new file mode 100644
index 0000000000..7344ab3bbc
--- /dev/null
+++ b/server/lib/credentialEnvVars.js
@@ -0,0 +1,22 @@
+// Shared (server + client) classifier for env-var names that conventionally hold
+// credentials. The explicit provider `secretEnvVars` list stays the primary
+// masking source; this catches hand-entered vars whose Secret box was left off.
+
+const CREDENTIAL_ENV_VAR_RE = /(?:^|_)(?:API_KEY|APIKEY|AUTH|ACCESS_KEY|ACCESS_TOKEN|BEARER|CLIENT_SECRET|CREDENTIALS?|KEY|PASSWORD|PRIVATE_KEY|SECRET|TOKEN)(?:_|$)/i;
+
+const NON_CREDENTIAL_ENV_VAR_RE = /(?:^|_)(?:BASE_URL|CONFIG|CONFIG_CONTENT|ENDPOINT|HOST|MODEL|MODE|PATH|PORT|PROFILE|REGION)(?:_|$)/i;
+
+const NON_CREDENTIAL_ENV_VAR_NAMES = new Set(['CLAUDE_CODE_USE_BEDROCK']);
+
+/** True for names known to hold config, not a credential (AWS_PROFILE, *_BASE_URL…). */
+export const isNonCredentialEnvVarName = (name) => typeof name === 'string'
+ && (NON_CREDENTIAL_ENV_VAR_NAMES.has(name) || NON_CREDENTIAL_ENV_VAR_RE.test(name));
+
+/** True when the env-var NAME looks like a credential by convention. */
+export const isCredentialEnvVarName = (name) => typeof name === 'string'
+ && !isNonCredentialEnvVarName(name)
+ && CREDENTIAL_ENV_VAR_RE.test(name);
+
+/** Should this provider env var be redacted: listed secret OR credential-named. */
+export const isMaskedEnvVar = (name, secretEnvVars) =>
+ (Array.isArray(secretEnvVars) && secretEnvVars.includes(name)) || isCredentialEnvVarName(name);
diff --git a/server/lib/index.js b/server/lib/index.js
index 50c337031e..1c355e49b4 100644
--- a/server/lib/index.js
+++ b/server/lib/index.js
@@ -912,3 +912,5 @@ export * from './musicDesignerValidation.js';
export * from './mediaJobPreparation.js';
export * from './eventLoopLagProbe.js';
export * from './persistentMindAttachmentOwnership.js';
+
+export * from './credentialEnvVars.js';
diff --git a/server/routes/providers.credentialEnvMasking.test.js b/server/routes/providers.credentialEnvMasking.test.js
new file mode 100644
index 0000000000..cb655d607d
--- /dev/null
+++ b/server/routes/providers.credentialEnvMasking.test.js
@@ -0,0 +1,54 @@
+import { describe, expect, it, vi } from 'vitest';
+import express, { Router } from 'express';
+import { request } from '../lib/testHelper.js';
+import { errorMiddleware } from '../lib/errorHandler.js';
+import { createPortOSProviderRoutes } from './providers.js';
+
+// Synthetic record: the Secret box was left off for a hand-entered key.
+const stored = () => ({
+ id: 'example-cli',
+ name: 'Example CLI',
+ type: 'cli',
+ command: 'example',
+ models: [],
+ enabled: true,
+ envVars: { OPENAI_API_KEY: 'sk-example-real', EXAMPLE_BASE_URL: 'http://localhost:1234' },
+ secretEnvVars: [],
+});
+
+function appWith(providerService) {
+ const toolkit = { services: { providers: providerService }, routes: { providers: Router() } };
+ const app = express();
+ app.use(express.json());
+ app.use('/api/providers', createPortOSProviderRoutes(toolkit));
+ app.use(errorMiddleware);
+ return app;
+}
+
+describe('credential-named provider env vars', () => {
+ it('masks a credential-named var that is not in secretEnvVars, but not a base URL', async () => {
+ const record = stored();
+ const res = await request(appWith({ getProviderById: vi.fn().mockResolvedValue(record) }))
+ .get('/api/providers/example-cli');
+
+ expect(res.status).toBe(200);
+ expect(res.body.envVars.OPENAI_API_KEY).toBe('***');
+ expect(res.body.envVars.EXAMPLE_BASE_URL).toBe('http://localhost:1234');
+ expect(JSON.stringify(res.body)).not.toContain('sk-example-real');
+ });
+
+ it('keeps the stored key when a save resends ***, and replaces it for a new value', async () => {
+ const updateProvider = vi.fn(async (_id, next) => next);
+ const app = appWith({ getProviderById: vi.fn().mockResolvedValue(stored()), updateProvider });
+
+ const kept = await request(app).put('/api/providers/example-cli')
+ .send({ envVars: { OPENAI_API_KEY: '***', EXAMPLE_BASE_URL: 'http://localhost:1234' } });
+ expect(kept.status).toBe(200);
+ expect(updateProvider.mock.calls[0][1].envVars.OPENAI_API_KEY).toBe('sk-example-real');
+
+ const replaced = await request(app).put('/api/providers/example-cli')
+ .send({ envVars: { OPENAI_API_KEY: 'sk-example-new' } });
+ expect(replaced.status).toBe(200);
+ expect(updateProvider.mock.calls[1][1].envVars.OPENAI_API_KEY).toBe('sk-example-new');
+ });
+});
diff --git a/server/routes/providers.js b/server/routes/providers.js
index 6979ca53b4..1de76c8027 100644
--- a/server/routes/providers.js
+++ b/server/routes/providers.js
@@ -88,6 +88,7 @@ import {
PUBLIC_REVIEW_ACTIONS_POSTURE,
} from '../lib/providerVendors.js';
import { buildTuiShellLaunch } from '../lib/tuiShellLaunch.js';
+import { isMaskedEnvVar } from '../lib/credentialEnvVars.js';
import { presetDerivable, presetKind } from '../lib/providerPresets.js';
import { isDerivedPreset } from '../lib/providerGraphRecords.js';
import {
@@ -135,12 +136,10 @@ const sanitizeProvider = (provider) => {
envVars: envVars ? { ...envVars } : {},
secretEnvVars: secretEnvVars || []
};
- // Redact values of secret env vars
- if (Array.isArray(secretEnvVars)) {
- for (const key of secretEnvVars) {
- if (key in sanitized.envVars) {
- sanitized.envVars[key] = sanitized.envVars[key] === '' ? '' : '***';
- }
+ // Redact secret-listed AND credential-named env vars (Secret box may be off)
+ for (const key of Object.keys(sanitized.envVars)) {
+ if (isMaskedEnvVar(key, secretEnvVars)) {
+ sanitized.envVars[key] = sanitized.envVars[key] === '' ? '' : '***';
}
}
return sanitized;
@@ -1179,10 +1178,10 @@ export function createPortOSProviderRoutes(aiToolkit) {
updates.apiKey = existing.apiKey;
}
- // Preserve existing secret env var values when client sends redacted '***' placeholders
- if (updates.envVars && Array.isArray(existing.secretEnvVars)) {
- for (const key of existing.secretEnvVars) {
- if (updates.envVars[key] === '***' && existing.envVars?.[key]) {
+ // Preserve existing secret/credential-named env var values when client sends redacted '***' placeholders
+ if (updates.envVars) {
+ for (const [key, value] of Object.entries(updates.envVars)) {
+ if (value === '***' && existing.envVars?.[key] && isMaskedEnvVar(key, existing.secretEnvVars)) {
updates.envVars[key] = existing.envVars[key];
}
}