Skip to content

Commit 6c75d1a

Browse files
Gustedearl-warren
authored andcommitted
fix: require code permissions for branch feed
- The RSS and atom feed for branches exposes details about the code, it therefore should be guarded by the requirement that the doer has access to the code of that repository. - Added integration testing. (cherry picked from commit 3e3ef76)
1 parent 36300be commit 6c75d1a

File tree

6 files changed

+150
-2
lines changed

6 files changed

+150
-2
lines changed

routers/web/web.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,8 +1562,10 @@ func registerRoutes(m *web.Route) {
15621562
m.Get("/cherry-pick/{sha:([a-f0-9]{4,64})$}", repo.SetEditorconfigIfExists, repo.CherryPick)
15631563
}, repo.MustBeNotEmpty, context.RepoRef(), reqRepoCodeReader)
15641564

1565-
m.Get("/rss/branch/*", repo.MustBeNotEmpty, context.RepoRefByType(context.RepoRefBranch), feedEnabled, feed.RenderBranchFeed("rss"))
1566-
m.Get("/atom/branch/*", repo.MustBeNotEmpty, context.RepoRefByType(context.RepoRefBranch), feedEnabled, feed.RenderBranchFeed("atom"))
1565+
m.Group("", func() {
1566+
m.Get("/rss/branch/*", feed.RenderBranchFeed("rss"))
1567+
m.Get("/atom/branch/*", feed.RenderBranchFeed("atom"))
1568+
}, repo.MustBeNotEmpty, context.RepoRefByType(context.RepoRefBranch), reqRepoCodeReader, feedEnabled)
15671569

15681570
m.Group("/src", func() {
15691571
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.Home)

tests/integration/api_feed_user_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,24 @@ func TestFeed(t *testing.T) {
109109
})
110110
})
111111
})
112+
113+
t.Run("View permission", func(t *testing.T) {
114+
t.Run("Anomynous", func(t *testing.T) {
115+
defer tests.PrintCurrentTest(t)()
116+
req := NewRequest(t, "GET", "/org3/repo3/rss/branch/master")
117+
MakeRequest(t, req, http.StatusNotFound)
118+
})
119+
t.Run("No code permission", func(t *testing.T) {
120+
defer tests.PrintCurrentTest(t)()
121+
session := loginUser(t, "user8")
122+
req := NewRequest(t, "GET", "/org3/repo3/rss/branch/master")
123+
session.MakeRequest(t, req, http.StatusNotFound)
124+
})
125+
t.Run("With code permission", func(t *testing.T) {
126+
defer tests.PrintCurrentTest(t)()
127+
session := loginUser(t, "user9")
128+
req := NewRequest(t, "GET", "/org3/repo3/rss/branch/master")
129+
session.MakeRequest(t, req, http.StatusOK)
130+
})
131+
})
112132
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-
2+
id: 1001
3+
org_id: 3
4+
lower_name: no_code
5+
name: no_code
6+
authorize: 1 # read
7+
num_repos: 1
8+
num_members: 1
9+
includes_all_repositories: false
10+
can_create_org_repo: false
11+
12+
-
13+
id: 1002
14+
org_id: 3
15+
lower_name: read_code
16+
name: no_code
17+
authorize: 1 # read
18+
num_repos: 1
19+
num_members: 1
20+
includes_all_repositories: false
21+
can_create_org_repo: false
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-
2+
id: 1001
3+
org_id: 3
4+
team_id: 1001
5+
repo_id: 3
6+
7+
-
8+
id: 1002
9+
org_id: 3
10+
team_id: 1002
11+
repo_id: 3
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
-
2+
id: 1001
3+
team_id: 1001
4+
type: 1
5+
access_mode: 0
6+
7+
-
8+
id: 1002
9+
team_id: 1001
10+
type: 2
11+
access_mode: 1
12+
13+
-
14+
id: 1003
15+
team_id: 1001
16+
type: 3
17+
access_mode: 1
18+
19+
-
20+
id: 1004
21+
team_id: 1001
22+
type: 4
23+
access_mode: 1
24+
25+
-
26+
id: 1005
27+
team_id: 1001
28+
type: 5
29+
access_mode: 1
30+
31+
-
32+
id: 1006
33+
team_id: 1001
34+
type: 6
35+
access_mode: 1
36+
37+
-
38+
id: 1007
39+
team_id: 1001
40+
type: 7
41+
access_mode: 1
42+
43+
-
44+
id: 1008
45+
team_id: 1002
46+
type: 1
47+
access_mode: 1
48+
49+
-
50+
id: 1009
51+
team_id: 1002
52+
type: 2
53+
access_mode: 1
54+
55+
-
56+
id: 1010
57+
team_id: 1002
58+
type: 3
59+
access_mode: 1
60+
61+
-
62+
id: 1011
63+
team_id: 1002
64+
type: 4
65+
access_mode: 1
66+
67+
-
68+
id: 1012
69+
team_id: 1002
70+
type: 5
71+
access_mode: 1
72+
73+
-
74+
id: 1013
75+
team_id: 1002
76+
type: 6
77+
access_mode: 1
78+
79+
-
80+
id: 1014
81+
team_id: 1002
82+
type: 7
83+
access_mode: 1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-
2+
id: 1001
3+
org_id: 3
4+
team_id: 1001
5+
uid: 8
6+
7+
-
8+
id: 1002
9+
org_id: 3
10+
team_id: 1002
11+
uid: 9

0 commit comments

Comments
 (0)