2026-05-12 security patches (#12493)
- fix: prevent git write to wiki repo from unauthorized user via git HTTP - fix: prevent LFS authorization token from being used for read/write access after user's access is restricted from Forgejo - fix: prevent scoped API access (OAuth tokens, Access tokens) from accessing resources beyond their permitted scope via non-API endpoints (e.g. /user/repo/raw/...) - fix: implementing missing OAuth validation checks, improve protections against race conditions - fix: prevent OAuth redirect URI spoofing via non-ascii case collision - fix: strengthen Actions Artifact V4 signature algorithm against spoofing attacks <!--start release-notes-assistant--> ## Release notes <!--URL:https://codeberg.org/forgejo/forgejo--> - Security bug fixes - [PR](https://codeberg.org/forgejo/forgejo/pulls/12493): <!--number 12493 --><!--line 0 --><!--description MjAyNi0wNS0xMiBzZWN1cml0eSBwYXRjaGVz-->2026-05-12 security patches<!--description--> <!--end release-notes-assistant--> Co-authored-by: Derzsi Dániel <daniel@tohka.us> Co-authored-by: jvoisin <julien.voisin@dustri.org> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12493
This commit is contained in:
committed by
Gusted
co-authored by
Derzsi Dániel
jvoisin
parent
5b6c702f41
commit
32b8d732b8
@@ -4,6 +4,7 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"slices"
|
||||
|
||||
@@ -57,6 +58,23 @@ func RequireRepoWriterOr(unitTypes ...unit.Type) func(ctx *Context) {
|
||||
// RequireRepoReader returns a middleware for requiring repository read to the specify unitType
|
||||
func RequireRepoReader(unitType unit.Type) func(ctx *Context) {
|
||||
return func(ctx *Context) {
|
||||
// Typically checks for authentication scopes won't be relevant for non-API requests where this middleware is
|
||||
// used; but, some paths like `/user/repo/raw/...` can be accessed with API authentication mechanisms. In those
|
||||
// edge cases, check that `read:repository` scope is present if the authentication method indicates a limited
|
||||
// scope.
|
||||
hasScope, scope := ctx.Authentication.Scope().Get()
|
||||
if hasScope {
|
||||
allow, err := scope.HasScope(auth_model.AccessTokenScopeReadRepository)
|
||||
if err != nil {
|
||||
ctx.ServerError("checking scope failed", err)
|
||||
return
|
||||
}
|
||||
if !allow {
|
||||
ctx.Error(http.StatusForbidden, "scopedAccessCheck", fmt.Sprintf("token does not have at least one of required scope(s): %v", auth_model.AccessTokenScopeReadRepository))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if !ctx.Repo.CanRead(unitType) {
|
||||
if log.IsTrace() {
|
||||
if ctx.IsSigned {
|
||||
|
||||
@@ -375,7 +375,15 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Repo.Permission, err = access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
||||
// Typically checks for authorization reducers won't be relevant for non-API requests where this middleware is used;
|
||||
// but, some paths like `/user/repo/raw/...` can be accessed with API authentication mechanisms. In those edge
|
||||
// cases, initialize `ctx.Repo.Permission` based upon the reduced permission set available.
|
||||
authorizationReducer := ctx.Authentication.Reducer()
|
||||
if authorizationReducer == nil {
|
||||
ctx.Repo.Permission, err = access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
||||
} else {
|
||||
ctx.Repo.Permission, err = access_model.GetUserRepoPermissionWithReducer(ctx, repo, ctx.Doer, authorizationReducer)
|
||||
}
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserRepoPermission", err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user