-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 Security Vulnerability - Directory Traversal #1718
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1718 +/- ##
=======================================
Coverage 85.19% 85.19%
=======================================
Files 29 29
Lines 1986 1986
=======================================
Hits 1692 1692
Misses 186 186
Partials 108 108
Continue to review full report at Codecov.
|
Wow this is superb. Quite a vulnerability. Could you write a test that explicitly confirms that this prevents directory traversal? |
Sure, i am working on it |
You could use this as base func TestDirectoryTraversal(t *testing.T) {
var testCases = []struct {
name string
givenURL string
whenStaticRoot string
expectContent string
expectError string
}{
{
name: "ok, serve index",
givenURL: `/index.html`,
whenStaticRoot: "../_fixture",
expectContent: "Echo",
},
{
name: "nok, do not allow directory traversal",
givenURL: `/..\\middleware/basic_auth.go`,
whenStaticRoot: "../_fixture",
expectContent: "package middleware",
expectError: "code=404, message=Not Found",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
e := echo.New()
staticHandler := StaticWithConfig(StaticConfig{Root: tc.whenStaticRoot})(echo.NotFoundHandler)
req := httptest.NewRequest(http.MethodGet, tc.givenURL, nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
err := staticHandler(c)
if tc.expectError != "" {
assert.Error(t, err)
assert.EqualError(t, err, tc.expectError)
assert.NotContains(t, rec.Body.String(), tc.expectContent)
} else {
assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), tc.expectContent)
}
})
}
} |
This seems to be windows specific problem (different separator). shorter fix would be to change Line 170 in 2b36b3d
to name := filepath.Join(config.Root, filepath.Clean("/"+p)) seems to fix problem on Windows |
Great! And concise! |
@little-cui can you test out @aldas suggestion to know if it actually fixes the issue? |
seems that path.Clean() works only for slashes
but filePath.Clean() is dealing with OS specific separator
|
Great find! @little-cui . Could you adjust your code to the fix @aldas proposed with an added test please so our CI can make sure it is fixed. |
It seems that I missed all the fun 😢 |
maybe it is faster if mainters will edit this PR with this (fixes static route and static middleware) |
Please review again |
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.
Looking good!
Thanks @little-cui and @aldas
Yes, a release is being prepared and expected within the next few days. The most important changes are already merged. |
Hello, Looks like the latest release is v4.1.17 tagged on 28 Aug 2020. |
Hi, We are Apache ServiceComb team. labstack/echo is the good project, we use it in our frontend project.
Recently, we have found a security vulnerability.
At echo.go(Line 483)
the static directory is bound by calling e.static ("/", staticPath).
The original intention is to read the root directory.
In Windows platform, POC can be constructed for path traversal.
Attack vector(s) :