From 530e74c70bdcd8d6a2369abfcab065f5bc6fa26b Mon Sep 17 00:00:00 2001 From: Wuxuan <101337393+wangwuxuan2011@users.noreply.github.com> Date: Tue, 17 Jan 2023 21:54:25 +0800 Subject: [PATCH] fix: avoid regular expression match current directory (#3078) * fix: avoid regular expression match current directory * fix: optimize and regexp exclude slash Co-authored-by: wuxuan --- server/common/check.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/common/check.go b/server/common/check.go index 63cd72a4..1c8fda43 100644 --- a/server/common/check.go +++ b/server/common/check.go @@ -17,10 +17,10 @@ func CanWrite(meta *model.Meta, path string) bool { func CanAccess(user *model.User, meta *model.Meta, reqPath string, password string) bool { // if the reqPath is in hide (only can check the nearest meta) and user can't see hides, can't access - if meta != nil && !user.CanSeeHides() && meta.Hide != "" { + if meta != nil && !user.CanSeeHides() && meta.Hide != "" && !utils.PathEqual(meta.Path, reqPath) { for _, hide := range strings.Split(meta.Hide, "\n") { re := regexp.MustCompile(hide) - if re.MatchString(reqPath[len(meta.Path):]) { + if re.MatchString(reqPath[len(meta.Path)+1:]) { return false } }