Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
fix(cli): create the rc tmp copy with the preserved file mode
The tmp copy was written with the default 0644 mode and only chmod'd to the target's mode afterwards, so a 0600 private rc's contents sat world-readable in <target>.composio-tmp for the duration of the window. Create the tmp file with the preserved mode from the start; open(2) masks that mode with the umask (only ever clearing bits), so the follow-up chmod stays to pin the exact mode before the rename.
jkomyno committed
Aug 3, 2026 at 20:25 UTC
021125b7a8cd38e3766e150cd3c29ef36aeceb5f
2 files changed
+28
-8
ts/packages/cli/src/commands/install.cmd.ts
+27
-8
@@ -232,6 +232,32 @@ const resolveWriteTarget = (
232
Effect.catchAll(() => Effect.succeed(filePath))
233
);
234
235
+/**
236
+ * Atomically replace `writeTarget` via a same-directory tmp file. The tmp copy
237
+ * is created with the target's mode from the start so a private rc's contents
238
+ * never sit in a default-mode, world-readable tmp file. open(2) masks the
239
+ * requested mode with the process umask (only ever clearing bits), so a chmod
240
+ * still follows to pin the exact mode.
241
+ */
242
+const replaceFilePreservingMode = (
243
+ writeTarget: string,
244
+ contents: string,
245
+ fs: FileSystem.FileSystem
246
+): Effect.Effect<void, PlatformError> =>
247
+ Effect.gen(function* () {
248
+ const existingTargetInfo = yield* fs.stat(writeTarget).pipe(Effect.option);
249
+ const preservedMode = Option.map(existingTargetInfo, info => info.mode & 0o7777);
250
+ const tmpPath = `${writeTarget}.composio-tmp`;
251
+ yield* Option.match(preservedMode, {
252
+ onNone: () => fs.writeFileString(tmpPath, contents),
253
+ onSome: mode => fs.writeFileString(tmpPath, contents, { mode }),
254
+ });
255
+ if (Option.isSome(preservedMode)) {
256
+ yield* fs.chmod(tmpPath, preservedMode.value);
257
+ }
258
+ yield* fs.rename(tmpPath, writeTarget);
259
+ });
260
+
261
// ---------------------------------------------------------------------------
262
// Exported logic (reusable from install.sh post-install delegation)
263
// ---------------------------------------------------------------------------
@@ -438,7 +464,6 @@ export const installShellIntegration = (params: {
464
// not discard a previous iteration's append.
465
const existingContents = yield* readMaybeMissingFile(filePath, fs);
466
const writeTarget = yield* resolveWriteTarget(filePath, fs);
441
- const existingTargetInfo = yield* fs.stat(writeTarget).pipe(Effect.option);
467
468
yield* fs
469
.makeDirectory(path.dirname(writeTarget), { recursive: true })
@@ -449,13 +474,7 @@ export const installShellIntegration = (params: {
474
);
475
476
const appendContent = '\n' + blocks.join('\n\n') + '\n';
452
- const tmpPath = `${writeTarget}.composio-tmp`;
453
-
454
- yield* fs.writeFileString(tmpPath, existingContents + appendContent);
455
- if (Option.isSome(existingTargetInfo)) {
456
- yield* fs.chmod(tmpPath, existingTargetInfo.value.mode & 0o7777);
457
- }
458
- yield* fs.rename(tmpPath, writeTarget);
477
+ yield* replaceFilePreservingMode(writeTarget, existingContents + appendContent, fs);
478
479
yield* success(`Updated ${tildify(filePath, os.homedir)}`);
480
}
ts/packages/cli/test/src/commands/install.cmd.test.ts
+1
@@ -208,6 +208,7 @@ describe('CLI: composio install', () => {
208
209
const info = yield* fs.stat(bashProfilePath);
210
expect(info.mode & 0o777).toBe(0o600);
211
+ expect(yield* fs.exists(`${bashProfilePath}.composio-tmp`)).toBe(false);
212
})
213
);
214
});