mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-24 05:39:46 +02:00
refactor: carry the API token on the doer (#39690)
The token a request authenticated with now lives on the doer, so permission and visibility checks apply its scope from the doer alone. Replaces https://github.com/go-gitea/gitea/pull/39167, following https://github.com/go-gitea/gitea/pull/39167#issuecomment-6063839619. 1. Public-only tokens get 404 instead of 403 for hidden users, orgs and repos, like GitHub. 2. Org ownership, site admin, repo and org creation, generation and transfer endpoints reject public-only tokens. 3. API pull request responses set `head.repo` to `null` and `head.repo_id` to `-1` when the caller cannot see the head repository. 4. Public-only tokens see org memberships like anonymous callers, so concealed members stay hidden. 5. Site admin access in activity feeds, follower lists, org members, Actions run lists and packages needs a session or an `all`-scoped token. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
1 parent
7e62dda791
commit
5264304a34
96 files changed
+583
-686
No files matched your search
@@ -108,7 +108,7 @@ func CreateAccessToken(ctx *context.Context, owner *user_model.User) {
|
||||
// a token-authenticated request must not mint a token with a broader scope than its own, nor
|
||||
// drop the public-only restriction. Web routes accept basic-auth PATs/OAuth tokens too, so this
|
||||
// must mirror the REST API guard in routers/api/v1/user/app.go.
|
||||
apiTokenScope, hasApiTokenScope := ctx.Data["ApiTokenScope"].(auth_model.AccessTokenScope)
|
||||
apiTokenScope, hasApiTokenScope := user_model.GetDoerTokenScope(ctx.Doer)
|
||||
if hasApiTokenScope {
|
||||
hasScope, err := apiTokenScope.CanCreateChildScope(t.Scope)
|
||||
if err != nil {
|
||||
|
||||
@@ -276,7 +276,7 @@ func Repos(ctx *context.Context) {
|
||||
}
|
||||
|
||||
userRepos, _, err := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{
|
||||
Actor: ctxUser,
|
||||
OwnerID: ctxUser.ID,
|
||||
Private: true,
|
||||
ListOptions: db.ListOptions{
|
||||
Page: 1,
|
||||
@@ -300,7 +300,7 @@ func Repos(ctx *context.Context) {
|
||||
ctx.Data["Dirs"] = repoNames
|
||||
ctx.Data["ReposMap"] = repos
|
||||
} else {
|
||||
repos, reposCount, err := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{Actor: ctxUser, Private: true, ListOptions: opts})
|
||||
repos, reposCount, err := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{OwnerID: ctxUser.ID, Private: true, ListOptions: opts})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserRepositories", err)
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user