Security & Performance Refactor: Command Injection, Traversal, and Regressions#4
Open
BrandonS7 wants to merge 4 commits intoeidos-agi:mainfrom
Open
Security & Performance Refactor: Command Injection, Traversal, and Regressions#4BrandonS7 wants to merge 4 commits intoeidos-agi:mainfrom
BrandonS7 wants to merge 4 commits intoeidos-agi:mainfrom
Conversation
- Replaced AppleScript injection vulnerability with send2trash - Added symlink checks to prevent path traversal - Optimized space hogs scanner (single pass os.walk instead of multiple rglob) - Added proper exception handling for record_removal - Sanitized docker project names to prevent injection
- Removed shell=True from stats.run_cleanup and used shlex - Strictly sanitized AppleScript inputs in memory.py - Fixed TOCTOU and state-after-mutation in safe_delete.py - Replaced recursive rglob with symlink-safe os.walk in utils.py - Tightened Docker label sanitization to alphanumeric allowlist - Added onerror handler and fixed pruning regression in os.walk - Replaced silent except blocks with proper logging - Synced package versions and declared missing dependencies
- Rewrote cleanup dispatch to use safe_cleanup instead of stats.run_cleanup - Removed shell=True everywhere - Improved TOCTOU checks using lstat - Fixed os.walk traversal (added onerror and pruned correctly) - Replaced re.sub stripping with strict regex validation in memory.py and docker.py - Replaced silent except blocks with logging warnings - Added psutil dependency and test extras
- Fixed functional regression in chained commands ('&&') by sequentially processing sub-commands
- Added root symlink traversal check to trash_contents()
- Enforced safe base-path validation for move_to_trash() to prevent arbitrary path deletions outside Home, Applications, or Library/Caches
- Relaxed AppleScript sanitization to safely accept legitimate application names containing apostrophes and ampersands
- Updated tests with 100% coverage for the new behaviors
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.
Description
This PR applies a comprehensive 4-phase remediation of critical security vulnerabilities and performance bottlenecks, guided by multiple rigorous AI audits.
Security Fixes
shell=True: Completely removed theshell=Trueparameter from the primary cleanup dispatch (stats.py). All cleanup operations are now parsed safely withshlex.splitand routed through a hardenedsafe_cleanuppipeline.memory.pyusing a strict regex allowlist to prevent AppleScript injection when terminating processes, while safely supporting legitimate names with apostrophes and ampersands.rglob('*')with symlink-safeos.walk(followlinks=False)to prevent traversal beyond intended directories.trash_contents.move_to_trashcannot delete anything outside~,/Applications, or/Library/Caches.lstat()to tighten the TOCTOU window.Performance & Reliability Improvements
find_space_hogs()from 17 recursiverglobtraversals to a single O(N) pass viaos.walk.onerrorcallbacks to allos.walktraversals to preventPermissionErrorcrashes from silently aborting the entire scan.except Exception: passinto explicit logging warnings so failures are observable.safe_cleanupto successfully process sub-commands separated by&&(e.g.npm cache clean --force && rm -rf ...) so core functionality isn't degraded by the security patch.Dependency Fixes
0.5.0.psutil) inpyproject.toml.[project.optional-dependencies] test = ["pytest"].