Skip to content

Commit f497201

Browse files
dvilelafclaude
andcommitted
fix: mkdir backups/ with mode=0o700 to close TOCTOU window
Passes mode directly to mkdir() so the directory is created with restricted permissions atomically, rather than relying solely on the subsequent os.chmod() call. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b8eadab commit f497201

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/iwa/core/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ def _rotate_backup(path: Path, keep: int = 30) -> None:
8080
if not path.exists():
8181
return
8282
backup_dir = path.parent / "backups"
83-
backup_dir.mkdir(exist_ok=True)
83+
# mode=0o700 on creation closes the TOCTOU window between mkdir and chmod.
84+
# The explicit chmod below still runs to fix dirs created by older versions.
85+
backup_dir.mkdir(mode=0o700, exist_ok=True)
8486
# Ensure the backups/ directory is not world-traversable (both code paths
8587
# — config saves and wallet saves — must agree on 0o700 so whichever path
8688
# creates the dir first doesn't leave it world-readable).

0 commit comments

Comments
 (0)