Skip to content

Commit 915cdf8

Browse files
authoredJul 26, 2023
Remove "misc" scope check from public API endpoints (#26134)
Fix #26035
1 parent 9ed3700 commit 915cdf8

File tree

4 files changed

+33
-63
lines changed

4 files changed

+33
-63
lines changed
 

‎docs/content/doc/development/oauth2-provider.en-us.md

+30-30
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,36 @@ Gitea supports scoped access tokens, which allow users the ability to restrict t
5151

5252
Gitea token scopes are as follows:
5353

54-
| Name | Description |
55-
| ---- |--------------------------------------------------------------------------------------------------------------------------------------------------|
56-
| **(no scope)** | Not supported. A scope is required even for public repositories. |
57-
| **activitypub** | `activitypub` API routes: ActivityPub related operations. |
58-
|     **read:activitypub** | Grants read access for ActivityPub operations. |
59-
|     **write:activitypub** | Grants read/write/delete access for ActivityPub operations. |
60-
| **admin** | `/admin/*` API routes: Site-wide administrative operations (hidden for non-admin accounts). |
61-
|     **read:admin** | Grants read access for admin operations, such as getting cron jobs or registered user emails. |
62-
|     **write:admin** | Grants read/write/delete access for admin operations, such as running cron jobs or updating user accounts. | |
63-
| **issue** | `issues/*`, `labels/*`, `milestones/*` API routes: Issue-related operations. |
64-
|     **read:issue** | Grants read access for issues operations, such as getting issue comments, issue attachments, and milestones. |
65-
|     **write:issue** | Grants read/write/delete access for issues operations, such as posting or editing an issue comment or attachment, and updating milestones. |
66-
| **misc** | miscellaneous and settings top-level API routes. |
67-
|     **read:misc** | Grants read access to miscellaneous operations, such as getting label and gitignore templates. |
68-
|     **write:misc** | Grants read/write/delete access to miscellaneous operations, such as markup utility operations. |
69-
| **notification** | `notification/*` API routes: user notification operations. |
70-
|     **read:notification** | Grants read access to user notifications, such as which notifications users are subscribed to and read new notifications. |
71-
|     **write:notification** | Grants read/write/delete access to user notifications, such as marking notifications as read. |
72-
| **organization** | `orgs/*` and `teams/*` API routes: Organization and team management operations. |
73-
|     **read:organization** | Grants read access to org and team status, such as listing all orgs a user has visibility to, teams, and team members. |
74-
|     **write:organization** | Grants read/write/delete access to org and team status, such as creating and updating teams and updating org settings. |
75-
| **package** | `/packages/*` API routes: Packages operations |
76-
|     **read:package** | Grants read access to package operations, such as reading and downloading available packages. |
77-
|     **write:package** | Grants read/write/delete access to package operations. Currently the same as `read:package`. |
78-
| **repository** | `/repos/*` API routes except `/repos/issues/*`: Repository file, pull-request, and release operations. |
79-
|     **read:repository** | Grants read access to repository operations, such as getting repository files, releases, collaborators. |
80-
|     **write:repository** | Grants read/write/delete access to repository operations, such as getting updating repository files, creating pull requests, updating collaborators. |
81-
| **user** | `/user/*` and `/users/*` API routes: User-related operations. |
82-
|     **read:user** | Grants read access to user operations, such as getting user repo subscriptions and user settings. |
83-
|     **write:user** | Grants read/write/delete access to user operations, such as updating user repo subscriptions, followed users, and user settings. |
54+
| Name | Description |
55+
| ---- |------------------------------------------------------------------------------------------------------------------------------------------------------|
56+
| **(no scope)** | Not supported. A scope is required even for public repositories. |
57+
| **activitypub** | `activitypub` API routes: ActivityPub related operations. |
58+
|     **read:activitypub** | Grants read access for ActivityPub operations. |
59+
|     **write:activitypub** | Grants read/write/delete access for ActivityPub operations. |
60+
| **admin** | `/admin/*` API routes: Site-wide administrative operations (hidden for non-admin accounts). |
61+
|     **read:admin** | Grants read access for admin operations, such as getting cron jobs or registered user emails. |
62+
|     **write:admin** | Grants read/write/delete access for admin operations, such as running cron jobs or updating user accounts. |
63+
| **issue** | `issues/*`, `labels/*`, `milestones/*` API routes: Issue-related operations. |
64+
|     **read:issue** | Grants read access for issues operations, such as getting issue comments, issue attachments, and milestones. |
65+
|     **write:issue** | Grants read/write/delete access for issues operations, such as posting or editing an issue comment or attachment, and updating milestones. |
66+
| **misc** | Reserved for future usage. |
67+
|     **read:misc** | Reserved for future usage. |
68+
|     **write:misc** | Reserved for future usage. |
69+
| **notification** | `notification/*` API routes: user notification operations. |
70+
|     **read:notification** | Grants read access to user notifications, such as which notifications users are subscribed to and read new notifications. |
71+
|     **write:notification** | Grants read/write/delete access to user notifications, such as marking notifications as read. |
72+
| **organization** | `orgs/*` and `teams/*` API routes: Organization and team management operations. |
73+
|     **read:organization** | Grants read access to org and team status, such as listing all orgs a user has visibility to, teams, and team members. |
74+
|     **write:organization** | Grants read/write/delete access to org and team status, such as creating and updating teams and updating org settings. |
75+
| **package** | `/packages/*` API routes: Packages operations |
76+
|     **read:package** | Grants read access to package operations, such as reading and downloading available packages. |
77+
|     **write:package** | Grants read/write/delete access to package operations. Currently the same as `read:package`. |
78+
| **repository** | `/repos/*` API routes except `/repos/issues/*`: Repository file, pull-request, and release operations. |
79+
|     **read:repository** | Grants read access to repository operations, such as getting repository files, releases, collaborators. |
80+
|     **write:repository** | Grants read/write/delete access to repository operations, such as getting updating repository files, creating pull requests, updating collaborators. |
81+
| **user** | `/user/*` and `/users/*` API routes: User-related operations. |
82+
|     **read:user** | Grants read access to user operations, such as getting user repo subscriptions and user settings. |
83+
|     **write:user** | Grants read/write/delete access to user operations, such as updating user repo subscriptions, followed users, and user settings. |
8484

8585
## Client types
8686

‎models/auth/token_scope.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type AccessTokenScopeCategory int
1616
const (
1717
AccessTokenScopeCategoryActivityPub = iota
1818
AccessTokenScopeCategoryAdmin
19-
AccessTokenScopeCategoryMisc
19+
AccessTokenScopeCategoryMisc // WARN: this is now just a placeholder, don't remove it which will change the following values
2020
AccessTokenScopeCategoryNotification
2121
AccessTokenScopeCategoryOrganization
2222
AccessTokenScopeCategoryPackage

‎routers/api/v1/api.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ func Routes() *web.Route {
751751
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryActivityPub))
752752
}
753753

754-
// Misc (requires 'misc' scope)
754+
// Misc (public accessible)
755755
m.Group("", func() {
756756
m.Get("/version", misc.Version)
757757
m.Get("/signing-key.gpg", misc.SigningKey)
@@ -771,7 +771,7 @@ func Routes() *web.Route {
771771
m.Get("/attachment", settings.GetGeneralAttachmentSettings)
772772
m.Get("/repository", settings.GetGeneralRepoSettings)
773773
})
774-
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryMisc))
774+
})
775775

776776
// Notifications (requires 'notifications' scope)
777777
m.Group("/notifications", func() {

‎tests/integration/api_token_test.go

-30
Original file line numberDiff line numberDiff line change
@@ -141,26 +141,6 @@ func TestAPIDeniesPermissionBasedOnTokenScope(t *testing.T) {
141141
},
142142
},
143143
},
144-
{
145-
"/api/v1/markdown",
146-
"POST",
147-
[]permission{
148-
{
149-
auth_model.AccessTokenScopeCategoryMisc,
150-
auth_model.Write,
151-
},
152-
},
153-
},
154-
{
155-
"/api/v1/markdown/raw",
156-
"POST",
157-
[]permission{
158-
{
159-
auth_model.AccessTokenScopeCategoryMisc,
160-
auth_model.Write,
161-
},
162-
},
163-
},
164144
{
165145
"/api/v1/notifications",
166146
"GET",
@@ -347,16 +327,6 @@ func TestAPIDeniesPermissionBasedOnTokenScope(t *testing.T) {
347327
},
348328
},
349329
},
350-
{
351-
"/api/v1/settings/api",
352-
"GET",
353-
[]permission{
354-
{
355-
auth_model.AccessTokenScopeCategoryMisc,
356-
auth_model.Read,
357-
},
358-
},
359-
},
360330
{
361331
"/api/v1/user",
362332
"GET",

0 commit comments

Comments
 (0)
Please sign in to comment.