-
Notifications
You must be signed in to change notification settings - Fork 0
fix: claude-lane/task_1780281408931_wl61hi99e-20260602145932 #31
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,9 @@ | |
| * OpenCode configuration helpers | ||
| */ | ||
|
|
||
| import { writeFileSync, mkdtempSync, chmodSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import { tmpdir } from "node:os"; | ||
|
Comment on lines
+5
to
+7
|
||
| import type { OpencodeConfig, OpencodeProvider } from "./types"; | ||
| import { PROVIDER_CONFIGS } from "./types"; | ||
|
|
||
|
|
@@ -49,14 +52,31 @@ export function buildOpencodeConfig( | |
| } | ||
|
|
||
| /** | ||
| * Convert OpencodeConfig to environment variables for OpenCode CLI | ||
| * Convert OpencodeConfig to environment variables for OpenCode CLI. | ||
| * | ||
| * SECURITY: The API key is NEVER placed directly in the environment. | ||
| * Environment variables are readable via `/proc/<pid>/environ` on Linux | ||
| * by any local user, which would expose the key to local privilege | ||
| * escalation. Instead, the key is written to a temp file with mode | ||
| * 0600 (readable/writable only by the owner) and the file path is | ||
| * passed as the env var value. The child process is expected to read | ||
| * the key from the file. | ||
|
Comment on lines
+55
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Api key still in env Despite the new claim that the API key is never placed in environment variables, OpencodeServer.start() still sets OPENCODE_CONFIG_CONTENT to JSON.stringify(config), which includes config.apiKey and therefore exposes the key in the child process environment. Agent Prompt
Comment on lines
+55
to
+63
|
||
| */ | ||
| export function configToEnv(config: OpencodeConfig): Record<string, string> { | ||
| const env: Record<string, string> = {}; | ||
| const providerConfig = PROVIDER_CONFIGS[config.provider]; | ||
|
|
||
| if (config.apiKey && providerConfig.apiKeyEnvVar) { | ||
| env[providerConfig.apiKeyEnvVar] = config.apiKey; | ||
| // Write the API key to a unique temp file with restrictive permissions. | ||
| // Using mkdtempSync guarantees an unguessable, exclusive directory name, | ||
| // avoiding symlink attacks in the shared /tmp directory. | ||
| const dir = mkdtempSync(join(tmpdir(), "codeflow-opencode-")); | ||
| const keyFile = join(dir, "api_key"); | ||
|
Comment on lines
+70
to
+74
|
||
| writeFileSync(keyFile, config.apiKey, { mode: 0o600 }); | ||
| // Belt-and-suspenders: explicitly chmod in case the umask interfered | ||
| // with the mode option (writeFileSync's mode is masked by process.umask). | ||
| chmodSync(keyFile, 0o600); | ||
| env[providerConfig.apiKeyEnvVar] = keyFile; | ||
|
Comment on lines
+73
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two important security/robustness improvements here:
|
||
| } | ||
|
|
||
| if (config.baseUrl) { | ||
|
|
||
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.
To prevent leaking temporary directories and sensitive API key files on disk indefinitely, we should track the created temporary directories and clean them up when the process exits.
We can import
rmSyncand register a synchronousprocess.on('exit')handler to delete these directories.