Skip to content

Commit f26a044

Browse files
committed
fine tune
1 parent 897ff51 commit f26a044

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

routers/web/githttp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ func addOwnerRepoGitHTTPRouters(m *web.Router) {
2222
m.Methods("GET,OPTIONS", "/objects/{head:[0-9a-f]{2}}/{hash:[0-9a-f]{38,62}}", repo.GetLooseObject)
2323
m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40,64}}.pack", repo.GetPackFile)
2424
m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40,64}}.idx", repo.GetIdxFile)
25-
}, optSignInAnyOrigin, repo.HTTPGitEnabledHandler, repo.CorsHandler(), context.UserAssignmentWeb())
25+
}, repo.HTTPGitEnabledHandler, repo.CorsHandler(), optSignInFromAnyOrigin, context.UserAssignmentWeb())
2626
}

routers/web/web.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func webAuth(authMethod auth_service.Method) func(*context.Context) {
134134

135135
// verifyAuthWithOptions checks authentication according to options
136136
func verifyAuthWithOptions(options *common.VerifyOptions) func(ctx *context.Context) {
137-
crossOrginProtection := http.NewCrossOriginProtection()
137+
crossOriginProtection := http.NewCrossOriginProtection()
138138

139139
return func(ctx *context.Context) {
140140
// Check prohibit login users.
@@ -179,7 +179,7 @@ func verifyAuthWithOptions(options *common.VerifyOptions) func(ctx *context.Cont
179179
}
180180

181181
if !options.SignOutRequired && !options.DisableCrossOriginProtection {
182-
if err := crossOrginProtection.Check(ctx.Req); err != nil {
182+
if err := crossOriginProtection.Check(ctx.Req); err != nil {
183183
http.Error(ctx.Resp, err.Error(), http.StatusForbidden)
184184
return
185185
}
@@ -292,7 +292,10 @@ func Routes() *web.Router {
292292
return routes
293293
}
294294

295-
var optSignInAnyOrigin = verifyAuthWithOptions(&common.VerifyOptions{DisableCrossOriginProtection: true})
295+
// optSignInFromAnyOrigin means that the user can (but isn't required to) be signed in from any origin (no cross-origin protection)
296+
// * With CORS middleware: CORS middleware does the preflight request handling, the requests has Sec-Fetch-Site header.
297+
// * For client requests: git clone via http, no Sec-Fetch-Site header
298+
var optSignInFromAnyOrigin = verifyAuthWithOptions(&common.VerifyOptions{DisableCrossOriginProtection: true})
296299

297300
// registerWebRoutes register routes
298301
func registerWebRoutes(m *web.Router) {
@@ -489,7 +492,7 @@ func registerWebRoutes(m *web.Router) {
489492
m.Post("/-/markup", reqSignIn, web.Bind(structs.MarkupOption{}), misc.Markup)
490493

491494
m.Get("/-/web-theme/list", misc.WebThemeList)
492-
m.Post("/-/web-theme/apply", optSignInAnyOrigin, misc.WebThemeApply)
495+
m.Post("/-/web-theme/apply", optSignIn, misc.WebThemeApply)
493496

494497
m.Group("/explore", func() {
495498
m.Get("", func(ctx *context.Context) {
@@ -572,7 +575,7 @@ func registerWebRoutes(m *web.Router) {
572575
m.Methods("POST, OPTIONS", "/access_token", web.Bind(forms.AccessTokenForm{}), auth.AccessTokenOAuth)
573576
m.Methods("GET, OPTIONS", "/keys", auth.OIDCKeys)
574577
m.Methods("POST, OPTIONS", "/introspect", web.Bind(forms.IntrospectTokenForm{}), auth.IntrospectOAuth)
575-
}, optionsCorsHandler(), optSignInAnyOrigin)
578+
}, optionsCorsHandler(), optSignInFromAnyOrigin)
576579
}, oauth2Enabled)
577580

578581
m.Group("/user/settings", func() {
@@ -1655,7 +1658,7 @@ func registerWebRoutes(m *web.Router) {
16551658
m.Post("/action/{action:accept_transfer|reject_transfer}", reqSignIn, repo.ActionTransfer)
16561659
}, optSignIn, context.RepoAssignment)
16571660

1658-
common.AddOwnerRepoGitLFSRoutes(m, optSignInAnyOrigin, lfsServerEnabled) // "/{username}/{reponame}/{lfs-paths}": git-lfs support
1661+
common.AddOwnerRepoGitLFSRoutes(m, lfsServerEnabled, optionsCorsHandler(), optSignInFromAnyOrigin) // "/{username}/{reponame}/{lfs-paths}": git-lfs support
16591662

16601663
addOwnerRepoGitHTTPRouters(m) // "/{username}/{reponame}/{git-paths}": git http support
16611664

0 commit comments

Comments
 (0)