aboutsummaryrefslogtreecommitdiff
path: root/pkg/tool/path_test.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2018-12-18 01:31:04 -0500
committerUnknwon <u@gogs.io>2018-12-18 01:31:04 -0500
commit86ada875296eb81ffd902f976eedee9ea0f19859 (patch)
treefb7e03f4bd27768cd5509fdc5a735813d49c4842 /pkg/tool/path_test.go
parentd74437af578718784c30819f160dc98e6f401a12 (diff)
models/repo_editor: sanitize user-defined file name to prevent RCE (#5558)
Reported by PentesterLab (https://pentesterlab.com).
Diffstat (limited to 'pkg/tool/path_test.go')
-rw-r--r--pkg/tool/path_test.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/pkg/tool/path_test.go b/pkg/tool/path_test.go
index 530238ce..c9e18294 100644
--- a/pkg/tool/path_test.go
+++ b/pkg/tool/path_test.go
@@ -30,3 +30,19 @@ func Test_IsSameSiteURLPath(t *testing.T) {
}
})
}
+
+func Test_SanitizePath(t *testing.T) {
+ Convey("Sanitize malicious user-defined path", t, func() {
+ testCases := []struct {
+ path string
+ expect string
+ }{
+ {"../../../../../../../../../data/gogs/data/sessions/a/9/a9f0ab6c3ef63dd8", "data/gogs/data/sessions/a/9/a9f0ab6c3ef63dd8"},
+
+ {"data/sessions/a/9/a9f0ab6c3ef63dd8", "data/sessions/a/9/a9f0ab6c3ef63dd8"},
+ }
+ for _, tc := range testCases {
+ So(SanitizePath(tc.path), ShouldEqual, tc.expect)
+ }
+ })
+}