@@ -33,6 +33,13 @@ func bindHttpCloneController(ctx *RouterContext) {
3333 http .HandleFunc ("GET /repo/{repoName}/info/{p...}" , UseMiddleware (
3434 []Middleware { Logged }, ctx ,
3535 func (ctx * routes.RouterContext , w http.ResponseWriter , r * http.Request ) {
36+ allowV2 := ctx .Config .GitConfig .HTTPCloneProtocol .V2
37+ allowV1Dumb := ctx .Config .GitConfig .HTTPCloneProtocol .V1Dumb
38+ if ! allowV1Dumb && ! allowV2 {
39+ w .WriteHeader (403 )
40+ fmt .Fprint (w , "HTTP clone not supported on this instance" )
41+ return
42+ }
3643 if ctx .Config .GlobalVisibility != aegis .GLOBAL_VISIBILITY_PUBLIC {
3744 ctx .ReportForbidden ("" , w , r )
3845 return
@@ -60,11 +67,11 @@ func bindHttpCloneController(ctx *RouterContext) {
6067 isRepoArchived := repo .Status == model .REPO_ARCHIVED
6168 if ! isNamespacePublic || ! (isRepoPublic || isRepoArchived ) {
6269 w .WriteHeader (404 )
63- w . Write ([] byte ( "404 Not Found" ) )
70+ fmt . Fprint ( w , "404 Not Found" )
6471 return
6572 }
6673 // see docs/http-clone.org.
67- if (r .URL .Query ().Has ("service" )) {
74+ if (r .URL .Query ().Has ("service" ) && allowV2 ) {
6875 switch r .URL .Query ().Get ("service" ) {
6976 case "git-upload-pack" :
7077 cmd := exec .Command ("git" , "upload-pack" , repo .LocalPath , "--http-backend-info-refs" )
@@ -93,6 +100,11 @@ func bindHttpCloneController(ctx *RouterContext) {
93100 return
94101 }
95102 // v1-dumb
103+ if ! allowV1Dumb {
104+ w .WriteHeader (403 )
105+ fmt .Fprint (w , "v1-dumb protocl not supported on this instance." )
106+ return
107+ }
96108 rr := repo .Repository .(* gitlib.LocalGitRepository )
97109 p := path .Join (rr .GitDirectoryPath , "info" , r .PathValue ("p" ))
98110 s , err := os .ReadFile (p )
@@ -105,6 +117,11 @@ func bindHttpCloneController(ctx *RouterContext) {
105117 http .HandleFunc ("POST /repo/{repoName}/git-upload-pack" , UseMiddleware (
106118 []Middleware { Logged }, ctx ,
107119 func (ctx * RouterContext , w http.ResponseWriter , r * http.Request ) {
120+ if ! ctx .Config .GitConfig .HTTPCloneProtocol .V2 {
121+ w .WriteHeader (403 )
122+ fmt .Fprint (w , "v2 protocl not supported on this instance." )
123+ return
124+ }
108125 if ctx .Config .GlobalVisibility != aegis .GLOBAL_VISIBILITY_PUBLIC {
109126 w .WriteHeader (403 )
110127 w .Write ([]byte ("Service not available right now." ))
0 commit comments