Skip to content

Commit 82f6640

Browse files
silverwindYohann Delafollye
authored andcommitted
Add serviceworker.js to KnownPublicEntries (go-gitea#11992)
Fixes a wrong 302 redirect to the login page, see go-gitea#11989. Also made it so the reserved username list is extended with those known entries so we avoid code duplication. Should be backported to 1.12.
1 parent f060a20 commit 82f6640

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

models/user.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"code.gitea.io/gitea/modules/generate"
3030
"code.gitea.io/gitea/modules/git"
3131
"code.gitea.io/gitea/modules/log"
32+
"code.gitea.io/gitea/modules/public"
3233
"code.gitea.io/gitea/modules/setting"
3334
"code.gitea.io/gitea/modules/structs"
3435
api "code.gitea.io/gitea/modules/structs"
@@ -885,7 +886,7 @@ func (u *User) IsGhost() bool {
885886
}
886887

887888
var (
888-
reservedUsernames = []string{
889+
reservedUsernames = append([]string{
889890
".",
890891
"..",
891892
".well-known",
@@ -895,17 +896,13 @@ var (
895896
"attachments",
896897
"avatars",
897898
"commits",
898-
"css",
899899
"debug",
900900
"error",
901901
"explore",
902-
"fomantic",
903902
"ghost",
904903
"help",
905-
"img",
906904
"install",
907905
"issues",
908-
"js",
909906
"less",
910907
"login",
911908
"manifest.json",
@@ -923,8 +920,8 @@ var (
923920
"stars",
924921
"template",
925922
"user",
926-
"vendor",
927-
}
923+
}, public.KnownPublicEntries...)
924+
928925
reservedUserPatterns = []string{"*.keys", "*.gpg"}
929926
)
930927

modules/public/public.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ type Options struct {
3030
Prefix string
3131
}
3232

33-
// List of known entries inside the `public` directory
34-
var knownEntries = []string{
33+
// KnownPublicEntries list all direct children in the `public` directory
34+
var KnownPublicEntries = []string{
3535
"css",
3636
"fomantic",
3737
"img",
3838
"js",
39+
"serviceworker.js",
3940
"vendor",
4041
}
4142

@@ -114,7 +115,7 @@ func (opts *Options) handle(ctx *macaron.Context, log *log.Logger, opt *Options)
114115
if len(parts) < 2 {
115116
return false
116117
}
117-
for _, entry := range knownEntries {
118+
for _, entry := range KnownPublicEntries {
118119
if entry == parts[1] {
119120
ctx.Resp.WriteHeader(404)
120121
return true

0 commit comments

Comments
 (0)