@@ -134,7 +134,7 @@ func webAuth(authMethod auth_service.Method) func(*context.Context) {
134134
135135// verifyAuthWithOptions checks authentication according to options
136136func 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
298301func 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