Skip to content

Commit 50070e9

Browse files
zeripathYohann Delafollye
authored and
Yohann Delafollye
committed
Prevent clones and pushes to disabled wiki (go-gitea#11131)
Signed-off-by: Andrew Thornton <[email protected]>
1 parent cb8900a commit 50070e9

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

routers/private/serv.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,27 @@ func ServCommand(ctx *macaron.Context) {
329329
results.RepoID = repo.ID
330330
}
331331

332-
// Finally if we're trying to touch the wiki we should init it
333332
if results.IsWiki {
333+
// Ensure the wiki is enabled before we allow access to it
334+
if _, err := repo.GetUnit(models.UnitTypeWiki); err != nil {
335+
if models.IsErrUnitTypeNotExist(err) {
336+
ctx.JSON(http.StatusForbidden, map[string]interface{}{
337+
"results": results,
338+
"type": "ErrForbidden",
339+
"err": "repository wiki is disabled",
340+
})
341+
return
342+
}
343+
log.Error("Failed to get the wiki unit in %-v Error: %v", repo, err)
344+
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
345+
"results": results,
346+
"type": "InternalServerError",
347+
"err": fmt.Sprintf("Failed to get the wiki unit in %s/%s Error: %v", ownerName, repoName, err),
348+
})
349+
return
350+
}
351+
352+
// Finally if we're trying to touch the wiki we should init it
334353
if err = wiki_service.InitWiki(repo); err != nil {
335354
log.Error("Failed to initialize the wiki in %-v Error: %v", repo, err)
336355
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{

routers/repo/http.go

+13
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,19 @@ func HTTP(ctx *context.Context) {
298298
}
299299
}
300300

301+
if isWiki {
302+
// Ensure the wiki is enabled before we allow access to it
303+
if _, err := repo.GetUnit(models.UnitTypeWiki); err != nil {
304+
if models.IsErrUnitTypeNotExist(err) {
305+
ctx.HandleText(http.StatusForbidden, "repository wiki is disabled")
306+
return
307+
}
308+
log.Error("Failed to get the wiki unit in %-v Error: %v", repo, err)
309+
ctx.ServerError("GetUnit(UnitTypeWiki) for "+repo.FullName(), err)
310+
return
311+
}
312+
}
313+
301314
environ = append(environ, models.ProtectedBranchRepoID+fmt.Sprintf("=%d", repo.ID))
302315

303316
w := ctx.Resp

0 commit comments

Comments
 (0)