-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: allow access to '..' in mapfs #7575
Conversation
Signed-off-by: nikpivkin <nikita.pivkin@smartforce.io>
pkg/mapfs/fs.go
Outdated
@@ -245,3 +245,7 @@ func cleanPath(path string) string { | |||
path = strings.TrimLeft(path, "/") // Remove the leading slash | |||
return path | |||
} | |||
|
|||
func (m *FS) isPathAboveRoot(name string) bool { | |||
return strings.HasPrefix(name, "..") && m.underlyingRoot != "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return strings.HasPrefix(name, "..") && m.underlyingRoot != "" | |
return (name == ".." || strings.HasPrefix(name, "../")) && m.underlyingRoot != "" |
A regular file can have ..
prefix.
$ touch ..foo
$ ls -al
total 0
drwxr-xr-x 3 teppei 96 9 25 11:06 ./
drwxrwxrwt 37 root 1184 9 25 11:06 ../
-rw-r--r-- 1 teppei 0 9 25 11:06 ..foo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed a002320
Signed-off-by: nikpivkin <nikita.pivkin@smartforce.io>
@@ -478,3 +478,26 @@ func TestFS_RemoveAll(t *testing.T) { | |||
require.ErrorIs(t, err, fs.ErrNotExist) | |||
}) | |||
} | |||
|
|||
func TestFS_WithUnderlyingRoot(t *testing.T) { | |||
root := "testdata/subdir" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason why testdata
is used? Can we use filepath.Join(t.TempDir(), "subdir"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The testdata/subdir
contains some files to which access is tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks.
@@ -478,3 +478,26 @@ func TestFS_RemoveAll(t *testing.T) { | |||
require.ErrorIs(t, err, fs.ErrNotExist) | |||
}) | |||
} | |||
|
|||
func TestFS_WithUnderlyingRoot(t *testing.T) { | |||
root := "testdata/subdir" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks.
Description
The path “../” becomes “..” after cleaning, causing the MapFS check that the path lies outside FS to fail.
Before
After
Related issues
Checklist