Skip to content

Commit

Permalink
Add serviceworker.js to KnownPublicEntries
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
silverwind committed Jun 20, 2020
1 parent 6891b90 commit 1889e2b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
11 changes: 4 additions & 7 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"code.gitea.io/gitea/modules/generate"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/public"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
api "code.gitea.io/gitea/modules/structs"
Expand Down Expand Up @@ -879,7 +880,7 @@ func (u *User) IsGhost() bool {
}

var (
reservedUsernames = []string{
reservedUsernames = append([]string{
".",
"..",
".well-known",
Expand All @@ -889,17 +890,13 @@ var (
"attachments",
"avatars",
"commits",
"css",
"debug",
"error",
"explore",
"fomantic",
"ghost",
"help",
"img",
"install",
"issues",
"js",
"less",
"login",
"manifest.json",
Expand All @@ -917,8 +914,8 @@ var (
"stars",
"template",
"user",
"vendor",
}
}, public.KnownPublicEntries...)

reservedUserPatterns = []string{"*.keys", "*.gpg"}
)

Expand Down
7 changes: 4 additions & 3 deletions modules/public/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ type Options struct {
Prefix string
}

// List of known entries inside the `public` directory
var knownEntries = []string{
// KnownPublicEntries list all direct children in the `public` directory
var KnownPublicEntries = []string{
"css",
"fomantic",
"img",
"js",
"serviceworker.js",
"vendor",
}

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

0 comments on commit 1889e2b

Please sign in to comment.