static: harden dot-segment check for backslashes, test non-validating custom fs.FS - #3129
Merged
Merged
Conversation
…ors, fix comments
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.
A custom
fs.FSthat does not follow thefs.FScontract (for example a hand-written adapter over a directory or object store that joins names withfilepath.Join) could resolve a requested name outside its root. Since v5.4.0 (GHSA-3pmx-cf9f-34xr) Echo does not open paths with a.,..or empty segment, so a name with a..element is never passed toOpen.Changes:
.and..parts separated by a backslash (e.g...\secret.txt). Such a name reaches the filesystem with the default configuration via/..%5Csecret.txtor a literal backslash, and via/..%5csecret.txtwhen path unescaping is enabled. A backslash is a literal character infs.FSnames, andos.DirFS,embed.FSand Echo's default filesystem are not affected; but a custom filesystem that wrongly treats a backslash as a separator (such as one built onfilepath.Joinon Windows) would otherwise resolve it outside its root. Names containing a backslash but no./..part (e.g.dir\file.txt) are unaffected.Echo.StaticFS(with and withoutEnablePathUnescapingStaticFiles) and the static middleware (root and group routes, with and withoutEnablePathUnescaping), covering literal..,%2e%2e,..%2f, nested..,..%5c,..%5C,a%5C..%5C..and literal..\; plus unit tests for the helper. The tests fail without the change on Linux, macOS and Windows.middleware/static.gosaid the"/"prefix removes..components (the code uses"./";..paths are not opened and are handled like a missing file) and referenced a non-existentstatic_windows.go; the helper doc now describes the backslash rule.Changelog:
static: do not open paths with a "." or ".." part between backslashes (hardening for custom filesystems that treat a backslash as a separator).