Skip to content

Commit 2041336

Browse files
authored
Merge pull request #8256 from uinstinct/config-0600-perm
fix: use 0600 permissions on config.yaml
2 parents a5257e2 + 2a6a0e9 commit 2041336

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

core/util/paths.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ import Types from "../config/types";
1414

1515
dotenv.config();
1616

17+
export function setConfigFilePermissions(filePath: string): void {
18+
try {
19+
if (os.platform() !== "win32") {
20+
fs.chmodSync(filePath, 0o600);
21+
}
22+
} catch (error) {
23+
console.warn(`Failed to set permissions on ${filePath}:`, error);
24+
}
25+
}
26+
1727
const CONTINUE_GLOBAL_DIR = (() => {
1828
const configPath = process.env.CONTINUE_GLOBAL_DIR;
1929
if (configPath) {
@@ -117,6 +127,7 @@ export function getConfigYamlPath(ideType?: IdeType): string {
117127
} else {
118128
fs.writeFileSync(p, YAML.stringify(defaultConfig));
119129
}
130+
setConfigFilePermissions(p);
120131
}
121132
return p;
122133
}
@@ -255,12 +266,14 @@ function editConfigJson(
255266
}
256267

257268
function editConfigYaml(callback: (config: ConfigYaml) => ConfigYaml): void {
258-
const config = fs.readFileSync(getConfigYamlPath(), "utf8");
269+
const configPath = getConfigYamlPath();
270+
const config = fs.readFileSync(configPath, "utf8");
259271
let configYaml = YAML.parse(config);
260272
// Check if it's an object
261273
if (typeof configYaml === "object" && configYaml !== null) {
262274
configYaml = callback(configYaml as any) as any;
263-
fs.writeFileSync(getConfigYamlPath(), YAML.stringify(configYaml));
275+
fs.writeFileSync(configPath, YAML.stringify(configYaml));
276+
setConfigFilePermissions(configPath);
264277
} else {
265278
console.warn("config.yaml is not a valid object");
266279
}

extensions/cli/src/freeTrialTransition.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fs from "fs";
33
import * as path from "path";
44

55
import chalk from "chalk";
6+
import { setConfigFilePermissions } from "core/util/paths.js";
67
import open from "open";
78

89
import { env } from "./env.js";
@@ -32,6 +33,7 @@ async function createOrUpdateConfig(apiKey: string): Promise<void> {
3233

3334
const updatedContent = updateAnthropicModelInYaml(existingContent, apiKey);
3435
fs.writeFileSync(CONFIG_PATH, updatedContent);
36+
setConfigFilePermissions(CONFIG_PATH);
3537
}
3638

3739
/**

extensions/cli/src/onboarding.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as fs from "fs";
22
import * as path from "path";
33

44
import chalk from "chalk";
5+
import { setConfigFilePermissions } from "core/util/paths.js";
56

67
import { AuthConfig, login } from "./auth/workos.js";
78
import { getApiClient } from "./config.js";
@@ -44,6 +45,7 @@ export async function createOrUpdateConfig(apiKey: string): Promise<void> {
4445

4546
const updatedContent = updateAnthropicModelInYaml(existingContent, apiKey);
4647
fs.writeFileSync(CONFIG_PATH, updatedContent);
48+
setConfigFilePermissions(CONFIG_PATH);
4749
}
4850

4951
export async function runOnboardingFlow(

extensions/vscode/src/commands.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ import { EXTENSION_NAME } from "core/control-plane/env";
88
import { Core } from "core/core";
99
import { walkDirAsync } from "core/indexing/walkDir";
1010
import { isModelInstaller } from "core/llm";
11+
import { NextEditLoggingService } from "core/nextEdit/NextEditLoggingService";
1112
import { startLocalLemonade } from "core/util/lemonadeHelper";
1213
import { startLocalOllama } from "core/util/ollamaHelper";
13-
import { getConfigJsonPath, getConfigYamlPath } from "core/util/paths";
14+
import {
15+
getConfigJsonPath,
16+
getConfigYamlPath,
17+
setConfigFilePermissions,
18+
} from "core/util/paths";
1419
import { Telemetry } from "core/util/posthog";
1520
import * as vscode from "vscode";
1621
import * as YAML from "yaml";
1722

1823
import { convertJsonToYamlConfig } from "../../../packages/config-yaml/dist";
1924

20-
import { NextEditLoggingService } from "core/nextEdit/NextEditLoggingService";
2125
import {
2226
getAutocompleteStatusBarDescription,
2327
getAutocompleteStatusBarTitle,
@@ -716,6 +720,7 @@ const getCommandsMap: (
716720

717721
const configYamlPath = getConfigYamlPath();
718722
fs.writeFileSync(configYamlPath, YAML.stringify(configYaml));
723+
setConfigFilePermissions(configYamlPath);
719724

720725
// Open config.yaml
721726
await openEditorAndRevealRange(

0 commit comments

Comments
 (0)