Skip to content

Commit dce75e0

Browse files
committed
feat(serverHandler): increase access restriction
1 parent ea71919 commit dce75e0

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

src/serverHandler/aliasHandler.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ func (h *aliasHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
109109
defer file.Close()
110110
}
111111

112+
if !data.AllowAccess {
113+
if !h.postMiddleware(w, r, data, fsPath) {
114+
h.accessRestricted(w, data.Status)
115+
}
116+
return
117+
}
118+
112119
if data.NeedAuth {
113120
h.notifyAuth(w, r)
114121

@@ -125,13 +132,6 @@ func (h *aliasHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
125132
}
126133
}
127134

128-
if !data.AllowAccess {
129-
if !h.postMiddleware(w, r, data, fsPath) {
130-
h.accessRestricted(w, data.Status)
131-
}
132-
return
133-
}
134-
135135
if data.NeedDirSlashRedirect {
136136
h.redirectWithSlashSuffix(w, r, data.prefixReqPath)
137137
return
@@ -169,7 +169,7 @@ func (h *aliasHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
169169

170170
// final process
171171
item := data.Item
172-
if data.WantJson {
172+
if data.wantJson {
173173
h.json(w, r, data)
174174
} else if shouldServeAsContent(file, item) {
175175
h.content(w, r, data)

src/serverHandler/middleware.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (h *aliasHandler) postMiddleware(w http.ResponseWriter, r *http.Request, da
2424
RestrictAccess: data.RestrictAccess,
2525
AllowAccess: data.AllowAccess,
2626

27-
WantJson: data.WantJson,
27+
WantJson: data.wantJson,
2828

2929
Status: data.Status,
3030

src/serverHandler/mutate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (h *aliasHandler) mutate(w http.ResponseWriter, r *http.Request, data *resp
2828
}
2929
}
3030

31-
if data.WantJson {
31+
if data.wantJson {
3232
header := w.Header()
3333
header.Set("Content-Type", "application/json; charset=utf-8")
3434
header.Set("Cache-Control", "public, max-age=0")

src/serverHandler/responseData.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type responseData struct {
2929
prefixReqPath string
3030
rawReqPath string
3131
handlerReqPath string
32+
wantJson bool
3233

3334
NeedAuth bool
3435
forceAuth bool
@@ -46,7 +47,6 @@ type responseData struct {
4647
IsMkdir bool
4748
IsDelete bool
4849
IsMutate bool
49-
WantJson bool
5050

5151
CanUpload bool
5252
CanMkdir bool
@@ -413,12 +413,12 @@ func (h *aliasHandler) getResponseData(r *http.Request) (data *responseData, fsP
413413

414414
subItemPrefix := getSubItemPrefix(currDirRelPath, rawReqPath, tailSlash)
415415

416-
canUpload := h.getCanUpload(item, rawReqPath, reqFsPath)
417-
canMkdir := h.getCanMkdir(item, rawReqPath, reqFsPath)
418-
canDelete := h.getCanDelete(item, rawReqPath, reqFsPath)
416+
canUpload := authSuccess && h.getCanUpload(item, rawReqPath, reqFsPath)
417+
canMkdir := authSuccess && h.getCanMkdir(item, rawReqPath, reqFsPath)
418+
canDelete := authSuccess && h.getCanDelete(item, rawReqPath, reqFsPath)
419419
hasDeletable := canDelete && len(subItems) > len(aliasSubItems)
420-
canArchive := h.getCanArchive(subItems, rawReqPath, reqFsPath)
421-
canCors := h.getCanCors(rawReqPath, reqFsPath)
420+
canArchive := authSuccess && h.getCanArchive(subItems, rawReqPath, reqFsPath)
421+
canCors := authSuccess && h.getCanCors(rawReqPath, reqFsPath)
422422
loginAvail := len(authUserName) == 0 && h.users.Len() > 0
423423

424424
context := pathContext{
@@ -432,6 +432,7 @@ func (h *aliasHandler) getResponseData(r *http.Request) (data *responseData, fsP
432432
prefixReqPath: prefixReqPath,
433433
rawReqPath: rawReqPath,
434434
handlerReqPath: reqPath,
435+
wantJson: wantJson,
435436

436437
NeedAuth: needAuth,
437438
forceAuth: forceAuth,
@@ -449,7 +450,6 @@ func (h *aliasHandler) getResponseData(r *http.Request) (data *responseData, fsP
449450
IsMkdir: isMkdir,
450451
IsDelete: isDelete,
451452
IsMutate: isMutate,
452-
WantJson: wantJson,
453453

454454
CanUpload: canUpload,
455455
CanMkdir: canMkdir,

0 commit comments

Comments
 (0)