Skip to content

fix(security): eliminate TOCTOU race conditions in ssl-bump.ts#1159

Merged
Mossaka merged 1 commit intomainfrom
fix/037-toctou-ssl-bump
Mar 5, 2026
Merged

fix(security): eliminate TOCTOU race conditions in ssl-bump.ts#1159
Mossaka merged 1 commit intomainfrom
fix/037-toctou-ssl-bump

Conversation

@Mossaka
Copy link
Collaborator

@Mossaka Mossaka commented Mar 5, 2026

Summary

  • Replace existsSync + writeFileSync with atomic wx flag writes (O_WRONLY|O_CREAT|O_EXCL) in initSslDb()
  • Replace existsSync + mkdirSync with mkdirSync({ recursive: true }) (no-op if exists) in both generateSessionCa() and initSslDb()
  • Handle EEXIST errors gracefully for file creation

Fixes #838

Test plan

  • All 831 existing tests pass
  • Lint passes (0 errors)
  • initSslDb tests verify idempotent behavior (existing content preserved)
  • Build succeeds

🤖 Generated with Claude Code

Replace check-then-act patterns (existsSync + writeFileSync/mkdirSync) with
atomic operations:

- Use mkdirSync with recursive:true (no-op if dir exists) instead of
  existsSync + mkdirSync
- Use writeFileSync with 'wx' flag (O_WRONLY|O_CREAT|O_EXCL) instead of
  existsSync + writeFileSync, handling EEXIST gracefully

This eliminates time-of-check-time-of-use race conditions in both
generateSessionCa() and initSslDb().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 5, 2026 19:43
@Mossaka Mossaka merged commit b859644 into main Mar 5, 2026
28 of 34 checks passed
@Mossaka Mossaka deleted the fix/037-toctou-ssl-bump branch March 5, 2026 19:43
@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

⚠️ Coverage Regression Detected

This PR decreases test coverage. Please add tests to maintain coverage levels.

Overall Coverage

Metric Base PR Delta
Lines 82.28% 82.41% 📈 +0.13%
Statements 82.25% 82.30% 📈 +0.05%
Functions 82.60% 82.60% ➡️ +0.00%
Branches 74.43% 74.21% 📉 -0.22%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/ssl-bump.ts 90.6% → 90.5% (-0.09%) 90.6% → 88.8% (-1.78%)
src/docker-manager.ts 83.0% → 83.6% (+0.55%) 82.4% → 82.9% (+0.53%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: eliminate TOCTOU race conditions in ssl-bump.ts

1 participant