Skip to content

Commit dca8ef9

Browse files
authored
Prevent clones and pushes to disabled wiki (go-gitea#11131) (go-gitea#11134)
Backport go-gitea#11131 Signed-off-by: Andrew Thornton <[email protected]>
1 parent cebef5c commit dca8ef9

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

routers/private/serv.go

Lines changed: 20 additions & 1 deletion
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.IsUncyclo {
333+
// Ensure the wiki is enabled before we allow access to it
334+
if _, err := repo.GetUnit(models.UnitTypeUncyclo); 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.InitUncyclo(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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,19 @@ func HTTP(ctx *context.Context) {
313313
}
314314
}
315315

316+
if isUncyclo {
317+
// Ensure the wiki is enabled before we allow access to it
318+
if _, err := repo.GetUnit(models.UnitTypeUncyclo); err != nil {
319+
if models.IsErrUnitTypeNotExist(err) {
320+
ctx.HandleText(http.StatusForbidden, "repository wiki is disabled")
321+
return
322+
}
323+
log.Error("Failed to get the wiki unit in %-v Error: %v", repo, err)
324+
ctx.ServerError("GetUnit(UnitTypeUncyclo) for "+repo.FullName(), err)
325+
return
326+
}
327+
}
328+
316329
environ = append(environ, models.ProtectedBranchRepoID+fmt.Sprintf("=%d", repo.ID))
317330

318331
w := ctx.Resp

0 commit comments

Comments
 (0)