fix: UNSAFE_TOOL_OUTPUT_PATH false positive on prefix boundaries#8
Merged
Conversation
The UNSAFE_TOOL_OUTPUT_PATH rule used startsWith() to check if a tool's output path falls under a system directory (/etc, /proc, /sys, /boot, /root, /dev). This caused false positives for paths like /etcfoo, /procrastinate, /device, /rootfs — none of which are actually system directories. Fix: check for exact match (path === dir) or proper subdirectory (path.startsWith(dir + '/')). Added 5 new test cases covering: - /etcfoo (should NOT fire) - /procrastinate (should NOT fire) - /device (should NOT fire) - /rootfs (should NOT fire) - /etc exact match (should fire)
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
The
UNSAFE_TOOL_OUTPUT_PATHrule usedString.startsWith()to check whether a tool's output path falls under a system directory (/etc,/proc,/sys,/boot,/root,/dev). This caused false positives for legitimate paths that merely start with the same characters as a system directory:/etcfoo/bar/procrastinate/file/device/some-path/rootfs/data/etc/passwd/proc/1/mem/etc(exact)Fix
Replace bare
startsWith(dir)with a proper path-boundary check:This ensures only exact matches or proper subdirectories trigger the rule.
Tests Added
5 new test cases in
src/__tests__/scanner.test.ts:/etcfoo— prefix boundary guard (should NOT fire)/procrastinate— prefix boundary guard (should NOT fire)/device— prefix boundary guard (should NOT fire)/rootfs— prefix boundary guard (should NOT fire)/etcexact match (should fire)Verification
npx tsc --noEmit— type checking passesnpm test— 75/75 tests pass (was 70)npm run lint— 0 warnings