Skip to content

Commit 00de9bf

Browse files
authored
fix!: sign with the raw path instead of filename (OpenListTeam#2258)
1 parent 1743110 commit 00de9bf

File tree

6 files changed

+15
-16
lines changed

6 files changed

+15
-16
lines changed

server/common/sign.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package common
33
import (
44
"github.com/alist-org/alist/v3/internal/model"
55
"github.com/alist-org/alist/v3/internal/sign"
6+
stdpath "path"
67
)
78

8-
func Sign(obj model.Obj, encrypt bool) string {
9+
func Sign(obj model.Obj, parent string, encrypt bool) string {
910
if obj.IsDir() || !encrypt {
1011
return ""
1112
}
12-
return sign.Sign(obj.GetName())
13+
return sign.Sign(stdpath.Join(parent, obj.GetName()))
1314
}

server/handles/down.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func Proxy(c *gin.Context) {
5858
URL := fmt.Sprintf("%s%s?sign=%s",
5959
strings.Split(downProxyUrl, "\n")[0],
6060
utils.EncodePath(rawPath, true),
61-
sign.Sign(filename))
61+
sign.Sign(rawPath))
6262
c.Redirect(302, URL)
6363
return
6464
}

server/handles/fsmanage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ func Link(c *gin.Context) {
203203
common.SuccessResp(c, model.Link{
204204
URL: fmt.Sprintf("%s/p%s?d&sign=%s",
205205
common.GetApiUrl(c.Request),
206-
utils.EncodePath(req.Path, true),
207-
sign.Sign(stdpath.Base(rawPath))),
206+
utils.EncodePath(rawPath, true),
207+
sign.Sign(rawPath)),
208208
})
209209
return
210210
}

server/handles/fsread.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func FsList(c *gin.Context) {
8686
provider = storage.GetStorage().Driver
8787
}
8888
common.SuccessResp(c, FsListResp{
89-
Content: toObjResp(objs, isEncrypt(meta, req.Path)),
89+
Content: toObjResp(objs, req.Path, isEncrypt(meta, req.Path)),
9090
Total: int64(total),
9191
Readme: getReadme(meta, req.Path),
9292
Write: user.CanWrite() || canWrite(meta, req.Path),
@@ -196,7 +196,7 @@ func pagination(objs []model.Obj, req *common.PageReq) (int, []model.Obj) {
196196
return total, objs[start:end]
197197
}
198198

199-
func toObjResp(objs []model.Obj, encrypt bool) []ObjResp {
199+
func toObjResp(objs []model.Obj, parent string, encrypt bool) []ObjResp {
200200
var resp []ObjResp
201201
for _, obj := range objs {
202202
thumb := ""
@@ -212,7 +212,7 @@ func toObjResp(objs []model.Obj, encrypt bool) []ObjResp {
212212
Size: obj.GetSize(),
213213
IsDir: obj.IsDir(),
214214
Modified: obj.ModTime(),
215-
Sign: common.Sign(obj, encrypt),
215+
Sign: common.Sign(obj, parent, encrypt),
216216
Thumb: thumb,
217217
Type: tp,
218218
})
@@ -275,12 +275,12 @@ func FsGet(c *gin.Context) {
275275
rawURL = fmt.Sprintf("%s%s?sign=%s",
276276
strings.Split(storage.GetStorage().DownProxyUrl, "\n")[0],
277277
utils.EncodePath(req.Path, true),
278-
sign.Sign(obj.GetName()))
278+
sign.Sign(req.Path))
279279
} else {
280280
rawURL = fmt.Sprintf("%s/p%s?sign=%s",
281281
common.GetApiUrl(c.Request),
282282
utils.EncodePath(req.Path, true),
283-
sign.Sign(obj.GetName()))
283+
sign.Sign(req.Path))
284284
}
285285
} else {
286286
// file have raw url
@@ -310,13 +310,13 @@ func FsGet(c *gin.Context) {
310310
Size: obj.GetSize(),
311311
IsDir: obj.IsDir(),
312312
Modified: obj.ModTime(),
313-
Sign: common.Sign(obj, isEncrypt(meta, req.Path)),
313+
Sign: common.Sign(obj, parentPath, isEncrypt(meta, req.Path)),
314314
Type: utils.GetFileType(obj.GetName()),
315315
},
316316
RawURL: rawURL,
317317
Readme: getReadme(meta, req.Path),
318318
Provider: provider,
319-
Related: toObjResp(related, isEncrypt(parentMeta, parentPath)),
319+
Related: toObjResp(related, parentPath, isEncrypt(parentMeta, parentPath)),
320320
})
321321
}
322322

server/middlewares/down.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package middlewares
22

33
import (
4-
stdpath "path"
54
"strings"
65

76
"github.com/alist-org/alist/v3/internal/db"
@@ -17,7 +16,6 @@ import (
1716
func Down(c *gin.Context) {
1817
rawPath := parsePath(c.Param("path"))
1918
c.Set("path", rawPath)
20-
filename := stdpath.Base(rawPath)
2119
meta, err := db.GetNearestMeta(rawPath)
2220
if err != nil {
2321
if !errors.Is(errors.Cause(err), errs.MetaNotFound) {
@@ -29,7 +27,7 @@ func Down(c *gin.Context) {
2927
// verify sign
3028
if needSign(meta, rawPath) {
3129
s := c.Query("sign")
32-
err = sign.Verify(filename, strings.TrimSuffix(s, "/"))
30+
err = sign.Verify(rawPath, strings.TrimSuffix(s, "/"))
3331
if err != nil {
3432
common.ErrorResp(c, err, 401)
3533
c.Abort()

server/webdav/webdav.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func (h *Handler) handleGetHeadPost(w http.ResponseWriter, r *http.Request) (sta
231231
u := fmt.Sprintf("%s/p%s?sign=%s",
232232
common.GetApiUrl(r),
233233
utils.EncodePath(reqPath, true),
234-
sign.Sign(path.Base(reqPath)))
234+
sign.Sign(reqPath))
235235
w.Header().Set("Cache-Control", "max-age=0, no-cache, no-store, must-revalidate")
236236
http.Redirect(w, r, u, 302)
237237
} else {

0 commit comments

Comments
 (0)