Skip to content

Commit dcbbf37

Browse files
authored
Add serviceworker.js to KnownPublicEntries (go-gitea#11992) (go-gitea#11994)
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.
1 parent 3e8618a commit dcbbf37

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"
@@ -878,7 +879,7 @@ func (u *User) IsGhost() bool {
878879
}
879880

880881
var (
881-
reservedUsernames = []string{
882+
reservedUsernames = append([]string{
882883
".",
883884
"..",
884885
".well-known",
@@ -888,17 +889,13 @@ var (
888889
"attachments",
889890
"avatars",
890891
"commits",
891-
"css",
892892
"debug",
893893
"error",
894894
"explore",
895-
"fomantic",
896895
"ghost",
897896
"help",
898-
"img",
899897
"install",
900898
"issues",
901-
"js",
902899
"less",
903900
"login",
904901
"manifest.json",
@@ -916,8 +913,8 @@ var (
916913
"stars",
917914
"template",
918915
"user",
919-
"vendor",
920-
}
916+
}, public.KnownPublicEntries...)
917+
921918
reservedUserPatterns = []string{"*.keys", "*.gpg"}
922919
)
923920

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)