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(security): sanitize provider API responses to strip secrets

Adam Eivyb510e0956af0
diff --git a/.changelog/v0.16.x.md b/.changelog/v0.16.x.md
index e386806751..1341e63783 100644
--- a/.changelog/v0.16.x.md
+++ b/.changelog/v0.16.x.md
@@ -14,6 +14,12 @@ Agent persistence, reliability, and decision transparency improvements.
- **Validation helper** (`validateSocketData`) returns parsed data on success or emits `${event}:error` with structured issue details on failure, matching the pattern used by HTTP route validation
- Schemas enforce type safety on path traversal inputs (`path`, `repoPath`), shell session IDs, terminal dimensions (`cols`/`rows` as positive integers), and process names
+### Provider API responses no longer expose secrets to clients
+- **Previously**, all GET endpoints (`/providers`, `/providers/:id`, `/providers/active`, `/providers/samples`) returned full provider objects including `apiKey` values and `secretEnvVars` values in plaintext -- anyone with network access to the API could read all API keys
+- **Now sanitizes all provider GET responses** -- `apiKey` is stripped and replaced with `hasApiKey: boolean`, secret env var values are redacted to `***`
+- **PUT endpoint preserves existing secrets** -- when the client omits `apiKey` or sends `***` for secret env vars, the server merges with existing values instead of overwriting
+- **Client form updated** -- API key field starts empty on edit with a placeholder indicating whether a key is already set; only sends a new key value when the user explicitly types one
+
### PTY shell sessions no longer leak environment secrets
- **Previously**, `pty.spawn()` spread the entire `process.env` into shell sessions, exposing API keys, tokens, and other secrets to anyone running `env` in the terminal
- **Now uses an explicit allowlist** of safe environment variable prefixes (`PATH`, `HOME`, `SHELL`, toolchain vars like `NVM_`, `GOPATH`, etc.) so only standard/non-sensitive variables are passed through
diff --git a/client/src/pages/AIProviders.jsx b/client/src/pages/AIProviders.jsx
index 89e33961a3..7e8bec5dce 100644
--- a/client/src/pages/AIProviders.jsx
+++ b/client/src/pages/AIProviders.jsx
@@ -549,7 +549,7 @@ function ProviderForm({ provider, onClose, onSave, allProviders = [] }) {
command: provider?.command || '',
args: provider?.args?.join(' ') || '',
endpoint: provider?.endpoint || '',
- apiKey: provider?.apiKey || '',
+ apiKey: '',
models: provider?.models || [],
defaultModel: provider?.defaultModel || '',
lightModel: provider?.lightModel || '',
@@ -580,6 +580,11 @@ function ProviderForm({ provider, onClose, onSave, allProviders = [] }) {
timeout: parseInt(formData.timeout)
};
+ // Only send apiKey if user entered a new value (avoid overwriting existing key with empty string)
+ if (!data.apiKey && provider) {
+ delete data.apiKey;
+ }
+
if (provider) {
await api.updateProvider(provider.id, data);
} else {
@@ -667,7 +672,7 @@ function ProviderForm({ provider, onClose, onSave, allProviders = [] }) {
type="password"
value={formData.apiKey}
onChange={(e) => setFormData(prev => ({ ...prev, apiKey: e.target.value }))}
- placeholder="Optional"
+ placeholder={provider?.hasApiKey ? 'Key set — leave blank to keep' : 'Optional'}
className="w-full px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white focus:border-port-accent focus:outline-none"
/>
</div>
diff --git a/server/routes/providers.js b/server/routes/providers.js
index d70d7d51cb..3f9e344d9e 100644
--- a/server/routes/providers.js
+++ b/server/routes/providers.js
@@ -3,12 +3,56 @@ import { asyncHandler, ServerError } from '../lib/errorHandler.js';
import { testVision, runVisionTestSuite, checkVisionHealth } from '../services/visionTest.js';
import { getAllProviderStatuses, getProviderStatus, markProviderAvailable, getTimeUntilRecovery } from '../services/providerStatus.js';
+/**
+ * Sanitize a provider object for client responses.
+ * Strips apiKey (replaces with hasApiKey boolean) and redacts secretEnvVars values.
+ */
+const sanitizeProvider = (provider) => {
+ if (!provider) return provider;
+ const { apiKey, envVars, secretEnvVars, ...rest } = provider;
+ const sanitized = {
+ ...rest,
+ hasApiKey: Boolean(apiKey),
+ 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] = '***';
+ }
+ }
+ }
+ return sanitized;
+};
+
/**
* Create PortOS-specific provider routes
* Extends AI Toolkit routes with vision testing endpoints
*/
export function createPortOSProviderRoutes(aiToolkit) {
const router = Router();
+ const providerService = aiToolkit.services.providers;
+
+ // Sanitized GET routes — intercept toolkit GET endpoints to strip secrets
+ router.get('/', asyncHandler(async (req, res) => {
+ const data = await providerService.getAllProviders();
+ res.json({
+ activeProvider: data.activeProvider,
+ providers: data.providers.map(sanitizeProvider)
+ });
+ }));
+
+ router.get('/active', asyncHandler(async (req, res) => {
+ const provider = await providerService.getActiveProvider();
+ res.json(sanitizeProvider(provider));
+ }));
+
+ router.get('/samples', asyncHandler(async (req, res) => {
+ const providers = await providerService.getSampleProviders();
+ res.json({ providers: providers.map(sanitizeProvider) });
+ }));
// Provider status routes MUST be defined before toolkit routes,
// because the toolkit has a GET /:id route that would catch /status
@@ -68,7 +112,39 @@ export function createPortOSProviderRoutes(aiToolkit) {
res.json(result);
}));
- // Mount base toolkit routes last (its /:id route would shadow our /status route)
+ // Sanitized GET /:id — must be after specific /:id/* routes above
+ router.get('/:id', asyncHandler(async (req, res) => {
+ const provider = await providerService.getProviderById(req.params.id);
+ if (!provider) return res.status(404).json({ error: 'Provider not found' });
+ res.json(sanitizeProvider(provider));
+ }));
+
+ // PUT /:id — intercept to preserve redacted secrets before passing to toolkit
+ router.put('/:id', asyncHandler(async (req, res) => {
+ const existing = await providerService.getProviderById(req.params.id);
+ if (!existing) return res.status(404).json({ error: 'Provider not found' });
+
+ const updates = { ...req.body };
+
+ // Preserve existing apiKey if client didn't send a new one
+ if (!('apiKey' in updates)) {
+ 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]) {
+ updates.envVars[key] = existing.envVars[key];
+ }
+ }
+ }
+
+ const provider = await providerService.updateProvider(req.params.id, updates);
+ res.json(sanitizeProvider(provider));
+ }));
+
+ // Mount base toolkit routes last (GET/PUT /:id are now shadowed by sanitized versions above)
router.use('/', aiToolkit.routes.providers);
return router;