0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-12-22 06:24:24 +01:00

Add serviceworker.js to KnownPublicEntries (#11992)

Fixes a wrong 302 redirect to the login page, see https://github.com/go-gitea/gitea/issues/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.
This commit is contained in:
silverwind 2020-06-20 15:20:25 +02:00 committed by GitHub
parent 6891b90303
commit e24ee48776
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 10 deletions

View file

@ -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"
@ -879,7 +880,7 @@ func (u *User) IsGhost() bool {
}
var (
reservedUsernames = []string{
reservedUsernames = append([]string{
".",
"..",
".well-known",
@ -889,17 +890,13 @@ var (
"attachments",
"avatars",
"commits",
"css",
"debug",
"error",
"explore",
"fomantic",
"ghost",
"help",
"img",
"install",
"issues",
"js",
"less",
"login",
"manifest.json",
@ -917,8 +914,8 @@ var (
"stars",
"template",
"user",
"vendor",
}
}, public.KnownPublicEntries...)
reservedUserPatterns = []string{"*.keys", "*.gpg"}
)

View file

@ -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",
}
@ -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