🔬 Deep Dive: /dev/null Parsing, bool("false") Trap & CWE-22 Containment #75
quantamixsol
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Three Subtle Bugs — One PR
1.
/dev/nullDiff ParsingGit unified diffs use
--- /dev/nullfor new files. Ourapply_diff()returnedsuccess=Falsefor missing files — but never checked if the diff was a new-file creation. The MCP response looked identical to success (valid patches,dry_run=false). Silent data loss.Fix: Detect
/dev/nullin diff header lines only (not body), create file atomically viatempfile.NamedTemporaryFile+os.replace().2.
bool("false") == True— The MCP TrapPython's
bool()treats any non-empty string asTrue. MCP frameworks pass boolean params as strings. Sodry_run="false"silently becamedry_run=True— files were never written.Rule: Never use
bool(string)in MCP argument handling.3. CWE-22 Path Traversal
New file creation from
/dev/nulldiffs could create files outside the project root via../../paths. Fixed withPath.resolve()+relative_to()containment check.All three patterns validated across 188 tests ✅
👉 Full diff: PR #72
Beta Was this translation helpful? Give feedback.
All reactions