Repository navigation
Harden generated-file writes against path escapes and data loss - #20
Merged
Merged
Conversation
- Reject agent-supplied paths that resolve outside output_dir before anything is written. - Back up every file a build overwrites, including hand-written files the hash map never tracked, so rollback restores them instead of deleting them. - Keep the first backup of a path so a cascade where two nodes write the same file still restores the pre-build original. - Roll back on KeyboardInterrupt and other BaseExceptions, and refuse to build while a leftover .specdiff/.backup/ from a killed build exists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FAykpfqqWA2GFjcC1p6FRy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three ways a build could damage files outside its own output:
Path(output_dir) / rel_pathaccepted LLM-supplied paths like/etc/xor../../x. Newresolve_output_path()rejects any path that resolves outsideoutput_dir. A node with a bad path fails before any of its files are written, and the cascade rolls back.backup()keeps the first copy of a path, so the backup still holds the pre-build original when two nodes in a cascade write the same file.KeyboardInterruptskipped rollback, which left half-written files and stale backups that the next build'sbackup()would treat as originals. The cascade now rolls back on anyBaseExceptionand re-raises.buildalso refuses to start while.specdiff/.backup/exists from a killed run, so those originals aren't overwritten.The per-node loop moved into
_build_nodes()so that every failure path goes through onerollback().Testing
pytest tests/: 262 passed (9 new tests inTestResolveOutputPathandTestWriteSafety)ruff check/ruff format --check: cleanGenerated by Claude Code