Skip to content

Commit e9f5067

Browse files
authored
Add missing reqToken() to notifications endpoints (#26914)
They currently throw a Internal Server Error when you use them without a token. Now they correctly return a `token is required` error. This is no security issue. If you use this endpoints with a token that don't have the correct permission, you get the correct error. This is not affected by this PR.
1 parent f79f6a2 commit e9f5067

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

routers/api/v1/api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,11 +776,11 @@ func Routes() *web.Route {
776776
// Notifications (requires 'notifications' scope)
777777
m.Group("/notifications", func() {
778778
m.Combo("").
779-
Get(notify.ListNotifications).
779+
Get(reqToken(), notify.ListNotifications).
780780
Put(reqToken(), notify.ReadNotifications)
781-
m.Get("/new", notify.NewAvailable)
781+
m.Get("/new", reqToken(), notify.NewAvailable)
782782
m.Combo("/threads/{id}").
783-
Get(notify.GetThread).
783+
Get(reqToken(), notify.GetThread).
784784
Patch(reqToken(), notify.ReadThread)
785785
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryNotification))
786786

tests/integration/api_notification_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func TestAPINotification(t *testing.T) {
3030
session := loginUser(t, user2.Name)
3131
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteNotification, auth_model.AccessTokenScopeWriteRepository)
3232

33+
MakeRequest(t, NewRequest(t, "GET", "/api/v1/notifications"), http.StatusUnauthorized)
34+
3335
// -- GET /notifications --
3436
// test filter
3537
since := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801
@@ -80,6 +82,8 @@ func TestAPINotification(t *testing.T) {
8082
assert.False(t, apiNL[1].Unread)
8183
assert.True(t, apiNL[1].Pinned)
8284

85+
MakeRequest(t, NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/threads/%d", 1)), http.StatusUnauthorized)
86+
8387
// -- GET /notifications/threads/{id} --
8488
// get forbidden
8589
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/threads/%d?token=%s", 1, token))
@@ -99,6 +103,8 @@ func TestAPINotification(t *testing.T) {
99103
assert.EqualValues(t, thread5.Issue.APIURL(), apiN.Subject.URL)
100104
assert.EqualValues(t, thread5.Repository.HTMLURL(), apiN.Repository.HTMLURL)
101105

106+
MakeRequest(t, NewRequest(t, "GET", "/api/v1/notifications/new"), http.StatusUnauthorized)
107+
102108
new := struct {
103109
New int64 `json:"new"`
104110
}{}

0 commit comments

Comments
 (0)