-
Notifications
You must be signed in to change notification settings - Fork 52.3k
fix(desktop): scrub credentials from updater and bootstrap children #70373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import assert from 'node:assert/strict' | ||
|
|
||
| import { test } from 'vitest' | ||
|
|
||
| import { isCredentialEnvVar, scrubDesktopChildEnv } from './scrub-child-env' | ||
|
|
||
| test('isCredentialEnvVar matches suffix and known names', () => { | ||
| assert.equal(isCredentialEnvVar('OPENROUTER_API_KEY'), true) | ||
| assert.equal(isCredentialEnvVar('HERMES_DESKTOP_REMOTE_TOKEN'), true) | ||
| assert.equal(isCredentialEnvVar('AWS_SECRET_ACCESS_KEY'), true) | ||
| assert.equal(isCredentialEnvVar('FAL_KEY'), true) | ||
| assert.equal(isCredentialEnvVar('PATH'), false) | ||
| assert.equal(isCredentialEnvVar('HERMES_HOME'), false) | ||
| assert.equal(isCredentialEnvVar('HERMES_DESKTOP'), false) | ||
| }) | ||
|
|
||
| test('scrubDesktopChildEnv drops secrets and keeps operational keys', () => { | ||
| const scrubbed = scrubDesktopChildEnv( | ||
| { | ||
| PATH: '/usr/bin', | ||
| HERMES_HOME: '/home/u/.hermes', | ||
| OPENROUTER_API_KEY: 'sk-live', | ||
| TELEGRAM_BOT_TOKEN: '123:abc', | ||
| FAL_KEY: 'fal-secret', | ||
| HERMES_DESKTOP_REMOTE_TOKEN: 'remote-secret', | ||
| EMPTY: '' | ||
| }, | ||
| { | ||
| HERMES_DESKTOP: '1', | ||
| HERMES_DASHBOARD_SESSION_TOKEN: 'minted-session' | ||
| } | ||
| ) | ||
|
|
||
| assert.equal(scrubbed.PATH, '/usr/bin') | ||
| assert.equal(scrubbed.HERMES_HOME, '/home/u/.hermes') | ||
| assert.equal(scrubbed.HERMES_DESKTOP, '1') | ||
| assert.equal(scrubbed.HERMES_DASHBOARD_SESSION_TOKEN, 'minted-session') | ||
| assert.equal(scrubbed.OPENROUTER_API_KEY, undefined) | ||
| assert.equal(scrubbed.TELEGRAM_BOT_TOKEN, undefined) | ||
| assert.equal(scrubbed.FAL_KEY, undefined) | ||
| assert.equal(scrubbed.HERMES_DESKTOP_REMOTE_TOKEN, undefined) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /** | ||
| * Shared credential scrub for Desktop Electron child processes. | ||
| * | ||
| * Desktop often spreads `{ ...process.env }` into PTY / serve / updater children. | ||
| * Provider and messaging secrets belong in HERMES_HOME/.env for the backend, not | ||
| * in the parent Electron environment forwarded wholesale to every child. | ||
| */ | ||
|
|
||
| const CREDENTIAL_SUFFIXES = Object.freeze([ | ||
| '_API_KEY', | ||
| '_TOKEN', | ||
| '_SECRET', | ||
| '_PASSWORD', | ||
| '_CREDENTIALS', | ||
| '_ACCESS_KEY', | ||
| '_PRIVATE_KEY', | ||
| '_OAUTH_TOKEN' | ||
| ]) | ||
|
|
||
| const CREDENTIAL_NAMES = new Set([ | ||
| 'ANTHROPIC_BASE_URL', | ||
| 'ANTHROPIC_TOKEN', | ||
| 'AWS_ACCESS_KEY_ID', | ||
| 'AWS_SECRET_ACCESS_KEY', | ||
| 'AWS_SESSION_TOKEN', | ||
| 'CUSTOM_API_KEY', | ||
| 'FAL_KEY', | ||
| 'GEMINI_BASE_URL', | ||
| 'OPENAI_BASE_URL', | ||
| 'OPENROUTER_BASE_URL', | ||
| 'OLLAMA_BASE_URL', | ||
| 'GROQ_BASE_URL', | ||
| 'XAI_BASE_URL' | ||
| ]) | ||
|
|
||
| export function isCredentialEnvVar(name: string): boolean { | ||
| if (!name) { | ||
| return false | ||
| } | ||
|
|
||
| if (CREDENTIAL_NAMES.has(name)) { | ||
| return true | ||
| } | ||
|
|
||
| return CREDENTIAL_SUFFIXES.some(suffix => name.endsWith(suffix)) | ||
| } | ||
|
|
||
| export type EnvMap = Record<string, string | undefined> | ||
|
|
||
| /** | ||
| * Copy `source` while dropping credential-shaped keys. Optionally re-apply | ||
| * explicit overrides afterwards (e.g. a minted dashboard session token). | ||
| */ | ||
| export function scrubDesktopChildEnv(source: EnvMap = {}, overrides: EnvMap = {}): Record<string, string> { | ||
| const out: Record<string, string> = {} | ||
|
|
||
| for (const [key, value] of Object.entries(source || {})) { | ||
| if (value == null || value === '') { | ||
| continue | ||
| } | ||
|
|
||
| if (isCredentialEnvVar(key)) { | ||
| continue | ||
| } | ||
|
|
||
| out[key] = String(value) | ||
| } | ||
|
|
||
| for (const [key, value] of Object.entries(overrides || {})) { | ||
| if (value == null || value === '') { | ||
| delete out[key] | ||
| continue | ||
| } | ||
|
|
||
| out[key] = String(value) | ||
| } | ||
|
|
||
| return out | ||
| } | ||
|
|
||
| export { CREDENTIAL_NAMES, CREDENTIAL_SUFFIXES } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FAL_KEYis a documented FAL API credential (hermes_cli/config_defaults.py:3572) but is absent here and does not match any suffix below, so this scrubber forwards it. Please add it to the explicit credential names and assert its removal in this helper's test.