Repository navigation
fix(SC2114): recognize non-canonical paths to system directories - #3614
Open
santhiprakash wants to merge 2 commits into
Open
santhiprakash wants to merge 2 commits into
santhiprakash wants to merge 2 commits into
Conversation
- Problem: `rm -rf /./etc` and `rm -rf /etc/../etc` delete a system
directory but drew no SC2114, because fixPath compared the literal
argument text against importantPaths.
- Fix: extend fixPath to lexically resolve "." and ".." components.
Resolution stops at the first segment containing a glob character
("/etc/*/../x" is not necessarily "/x"), never pops a leading ".."
of a relative path, and performs no symlink resolution. The same
canonicalization applies to the potential paths checked for SC2115.
- Verification: new prop_checkCatastrophicRm14-23 fail on the pre-fix
fixPath and pass after; `cabal test` passes all properties; e2e,
`rm -rf /./etc` and `rm -rf /etc/../etc` now warn SC2114 while
`rm -rf /usr/local/../etc`, `rm -rf ../etc` and `rm -rf /etc/*/../foo`
stay silent.
Contributor
Author
|
Related: #3616 (open) also modifies |
e-kwsm
reviewed
Nov 12, 2026
- Problem: reviewer e-kwsm reported rm -rf /*/../etc/ still not warned; the canonicalizer bailed at the first glob segment and kept the remainder verbatim (*../etc), which never matches a system directory although the shell resolves the path to /etc. - Fix: let a .. pop the nearest previous segment, glob or concrete: /* expands to top-level entries /name, so /name/../etc is exactly /etc. Mid-path globs keep correct semantics (/etc/*/../etc resolves to /etc/etc, not warned). - Verification: docker haskell:9.6 cabal test; new props checkCatastrophicRm24/25/26 (Rm24 Falsified pre-fix), full test suite green post-fix (1 of 1 test suites passed).
e-kwsm
approved these changes
Nov 15, 2026
This branch has not been deployed
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.
Fixes #3584
Problem
rm -rf /etctriggers SC2114 ("Warning: deletes a system directory"), but the same deletion spelled non-canonically does not:Both delete exactly
/etc, yet ShellCheck reports nothing for them.Triage / Root cause
checkCatastrophicRmcompares the argument text — afterfixPathcollapses repeated/and*and strips a trailing/— againstimportantPaths.fixPathnever resolves.or..components, so non-canonical spellings never reach the comparison.Fix
Extend
fixPathto lexically resolve.and..components before theimportantPathslookup:.segments are dropped;..pops the preceding segment...never pops a leading..of a relative path (rm -rf ../etcstays../etc), matching normpath-style semantics.*,?,[):rm -rf /etc/*/../foodoes not necessarily delete/foo(the glob may match non-directories), so it correctly stays silent.Since
fixPathalso feeds the SC2115 path (the${var:?}suggestion for paths that could expand catastrophically), the same canonicalization applies there:rm -rf "$x/../etc"now warns SC2115 because an emptyxreally does expand to/etc. Flagging explicitly since it changes SC2115 behavior too — it can only produce warnings where an empty expansion lexically resolves to a system directory.Verification
New
prop_checkCatastrophicRm14–23fail on the pre-fixfixPath(checked viacabal repl: Rm14/15/17/18/20/23 = False before the change) and all pass with it; the fourverifyNotprops document the conservative limits above.cabal test(ghc 9.6.7, aarch64,haskell:9.6image): all tests pass.e2e via
cabal run shellcheck -- -s sh:Notes / Risks
importantPaths; no existing warning is removed or reworded (check ids and messages unchanged).rm -rf /..andrm -rf /x/../..now warn — they resolve to/, which is inimportantPaths./proc/self/../etcresolves to/proc/etc(no warning): correct under lexical-only rules —/proc/selfis a symlink and we deliberately do not resolve symlinks.Assistance
AI-assisted. AI tools helped draft this change and this description. The verification steps were actually run.