Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/ssl-bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,20 @@ export async function initSslDb(workDir: string): Promise<string> {
}

// Create index.txt (empty file for certificate index)
if (!fs.existsSync(indexPath)) {
fs.writeFileSync(indexPath, '', { mode: 0o600 });
// Use 'wx' flag (O_WRONLY | O_CREAT | O_EXCL) for atomic create-if-not-exists,
// avoiding TOCTOU race between existsSync and writeFileSync
try {
fs.writeFileSync(indexPath, '', { flag: 'wx', mode: 0o600 });
} catch (e: unknown) {
if ((e as NodeJS.ErrnoException).code !== 'EEXIST') throw e;
}
Comment on lines +149 to 153
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description references issues #174 and #175 as being fixed by this change, but those issues are just smoke test results that passed. There doesn't appear to be an actual issue or discussion about TOCTOU vulnerabilities in the codebase. This appears to be a proactive security improvement rather than fixing a reported bug. Consider updating the PR description to clarify that this is a security hardening improvement rather than a bug fix, or reference the correct issues if they exist.

Copilot uses AI. Check for mistakes.

// Create size file (tracks current DB size, starts at 0)
if (!fs.existsSync(sizePath)) {
fs.writeFileSync(sizePath, '0\n', { mode: 0o600 });
// Same atomic pattern to avoid TOCTOU race condition
try {
fs.writeFileSync(sizePath, '0\n', { flag: 'wx', mode: 0o600 });
} catch (e: unknown) {
if ((e as NodeJS.ErrnoException).code !== 'EEXIST') throw e;
}

logger.debug(`SSL certificate database initialized at: ${sslDbPath}`);
Expand Down
Loading