diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-25 15:18:10 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-07-26 08:37:50 +0200 |
commit | 97583d00235d5e8f29d9c49ca13096521e394aa4 (patch) | |
tree | 5f29ba8c8e5b2d2653a1173408151bb64f6a80a9 /server/controllers/activitypub/client.ts | |
parent | 9901c8d6908a43ab4594406446eac770ee21176c (diff) | |
download | PeerTube-97583d00235d5e8f29d9c49ca13096521e394aa4.tar.gz PeerTube-97583d00235d5e8f29d9c49ca13096521e394aa4.tar.zst PeerTube-97583d00235d5e8f29d9c49ca13096521e394aa4.zip |
Add more rate limits
Diffstat (limited to 'server/controllers/activitypub/client.ts')
-rw-r--r-- | server/controllers/activitypub/client.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index c47c61f52..be52f1662 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -19,6 +19,7 @@ import { | |||
19 | getLocalVideoSharesActivityPubUrl | 19 | getLocalVideoSharesActivityPubUrl |
20 | } from '../../lib/activitypub/url' | 20 | } from '../../lib/activitypub/url' |
21 | import { | 21 | import { |
22 | activityPubRateLimiter, | ||
22 | asyncMiddleware, | 23 | asyncMiddleware, |
23 | ensureIsLocalChannel, | 24 | ensureIsLocalChannel, |
24 | executeIfActivityPub, | 25 | executeIfActivityPub, |
@@ -47,32 +48,38 @@ activityPubClientRouter.use(cors()) | |||
47 | activityPubClientRouter.get( | 48 | activityPubClientRouter.get( |
48 | [ '/accounts?/:name', '/accounts?/:name/video-channels', '/a/:name', '/a/:name/video-channels' ], | 49 | [ '/accounts?/:name', '/accounts?/:name/video-channels', '/a/:name', '/a/:name/video-channels' ], |
49 | executeIfActivityPub, | 50 | executeIfActivityPub, |
51 | activityPubRateLimiter, | ||
50 | asyncMiddleware(localAccountValidator), | 52 | asyncMiddleware(localAccountValidator), |
51 | asyncMiddleware(accountController) | 53 | asyncMiddleware(accountController) |
52 | ) | 54 | ) |
53 | activityPubClientRouter.get('/accounts?/:name/followers', | 55 | activityPubClientRouter.get('/accounts?/:name/followers', |
54 | executeIfActivityPub, | 56 | executeIfActivityPub, |
57 | activityPubRateLimiter, | ||
55 | asyncMiddleware(localAccountValidator), | 58 | asyncMiddleware(localAccountValidator), |
56 | asyncMiddleware(accountFollowersController) | 59 | asyncMiddleware(accountFollowersController) |
57 | ) | 60 | ) |
58 | activityPubClientRouter.get('/accounts?/:name/following', | 61 | activityPubClientRouter.get('/accounts?/:name/following', |
59 | executeIfActivityPub, | 62 | executeIfActivityPub, |
63 | activityPubRateLimiter, | ||
60 | asyncMiddleware(localAccountValidator), | 64 | asyncMiddleware(localAccountValidator), |
61 | asyncMiddleware(accountFollowingController) | 65 | asyncMiddleware(accountFollowingController) |
62 | ) | 66 | ) |
63 | activityPubClientRouter.get('/accounts?/:name/playlists', | 67 | activityPubClientRouter.get('/accounts?/:name/playlists', |
64 | executeIfActivityPub, | 68 | executeIfActivityPub, |
69 | activityPubRateLimiter, | ||
65 | asyncMiddleware(localAccountValidator), | 70 | asyncMiddleware(localAccountValidator), |
66 | asyncMiddleware(accountPlaylistsController) | 71 | asyncMiddleware(accountPlaylistsController) |
67 | ) | 72 | ) |
68 | activityPubClientRouter.get('/accounts?/:name/likes/:videoId', | 73 | activityPubClientRouter.get('/accounts?/:name/likes/:videoId', |
69 | executeIfActivityPub, | 74 | executeIfActivityPub, |
75 | activityPubRateLimiter, | ||
70 | cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS), | 76 | cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS), |
71 | asyncMiddleware(getAccountVideoRateValidatorFactory('like')), | 77 | asyncMiddleware(getAccountVideoRateValidatorFactory('like')), |
72 | asyncMiddleware(getAccountVideoRateFactory('like')) | 78 | asyncMiddleware(getAccountVideoRateFactory('like')) |
73 | ) | 79 | ) |
74 | activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId', | 80 | activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId', |
75 | executeIfActivityPub, | 81 | executeIfActivityPub, |
82 | activityPubRateLimiter, | ||
76 | cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS), | 83 | cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS), |
77 | asyncMiddleware(getAccountVideoRateValidatorFactory('dislike')), | 84 | asyncMiddleware(getAccountVideoRateValidatorFactory('dislike')), |
78 | asyncMiddleware(getAccountVideoRateFactory('dislike')) | 85 | asyncMiddleware(getAccountVideoRateFactory('dislike')) |
@@ -81,47 +88,56 @@ activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId', | |||
81 | activityPubClientRouter.get( | 88 | activityPubClientRouter.get( |
82 | [ '/videos/watch/:id', '/w/:id' ], | 89 | [ '/videos/watch/:id', '/w/:id' ], |
83 | executeIfActivityPub, | 90 | executeIfActivityPub, |
91 | activityPubRateLimiter, | ||
84 | cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS), | 92 | cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS), |
85 | asyncMiddleware(videosCustomGetValidator('all')), | 93 | asyncMiddleware(videosCustomGetValidator('all')), |
86 | asyncMiddleware(videoController) | 94 | asyncMiddleware(videoController) |
87 | ) | 95 | ) |
88 | activityPubClientRouter.get('/videos/watch/:id/activity', | 96 | activityPubClientRouter.get('/videos/watch/:id/activity', |
89 | executeIfActivityPub, | 97 | executeIfActivityPub, |
98 | activityPubRateLimiter, | ||
90 | asyncMiddleware(videosCustomGetValidator('all')), | 99 | asyncMiddleware(videosCustomGetValidator('all')), |
91 | asyncMiddleware(videoController) | 100 | asyncMiddleware(videoController) |
92 | ) | 101 | ) |
93 | activityPubClientRouter.get('/videos/watch/:id/announces', | 102 | activityPubClientRouter.get('/videos/watch/:id/announces', |
94 | executeIfActivityPub, | 103 | executeIfActivityPub, |
104 | activityPubRateLimiter, | ||
95 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), | 105 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
96 | asyncMiddleware(videoAnnouncesController) | 106 | asyncMiddleware(videoAnnouncesController) |
97 | ) | 107 | ) |
98 | activityPubClientRouter.get('/videos/watch/:id/announces/:actorId', | 108 | activityPubClientRouter.get('/videos/watch/:id/announces/:actorId', |
99 | executeIfActivityPub, | 109 | executeIfActivityPub, |
110 | activityPubRateLimiter, | ||
100 | asyncMiddleware(videosShareValidator), | 111 | asyncMiddleware(videosShareValidator), |
101 | asyncMiddleware(videoAnnounceController) | 112 | asyncMiddleware(videoAnnounceController) |
102 | ) | 113 | ) |
103 | activityPubClientRouter.get('/videos/watch/:id/likes', | 114 | activityPubClientRouter.get('/videos/watch/:id/likes', |
104 | executeIfActivityPub, | 115 | executeIfActivityPub, |
116 | activityPubRateLimiter, | ||
105 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), | 117 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
106 | asyncMiddleware(videoLikesController) | 118 | asyncMiddleware(videoLikesController) |
107 | ) | 119 | ) |
108 | activityPubClientRouter.get('/videos/watch/:id/dislikes', | 120 | activityPubClientRouter.get('/videos/watch/:id/dislikes', |
109 | executeIfActivityPub, | 121 | executeIfActivityPub, |
122 | activityPubRateLimiter, | ||
110 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), | 123 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
111 | asyncMiddleware(videoDislikesController) | 124 | asyncMiddleware(videoDislikesController) |
112 | ) | 125 | ) |
113 | activityPubClientRouter.get('/videos/watch/:id/comments', | 126 | activityPubClientRouter.get('/videos/watch/:id/comments', |
114 | executeIfActivityPub, | 127 | executeIfActivityPub, |
128 | activityPubRateLimiter, | ||
115 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), | 129 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
116 | asyncMiddleware(videoCommentsController) | 130 | asyncMiddleware(videoCommentsController) |
117 | ) | 131 | ) |
118 | activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId', | 132 | activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId', |
119 | executeIfActivityPub, | 133 | executeIfActivityPub, |
134 | activityPubRateLimiter, | ||
120 | asyncMiddleware(videoCommentGetValidator), | 135 | asyncMiddleware(videoCommentGetValidator), |
121 | asyncMiddleware(videoCommentController) | 136 | asyncMiddleware(videoCommentController) |
122 | ) | 137 | ) |
123 | activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId/activity', | 138 | activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId/activity', |
124 | executeIfActivityPub, | 139 | executeIfActivityPub, |
140 | activityPubRateLimiter, | ||
125 | asyncMiddleware(videoCommentGetValidator), | 141 | asyncMiddleware(videoCommentGetValidator), |
126 | asyncMiddleware(videoCommentController) | 142 | asyncMiddleware(videoCommentController) |
127 | ) | 143 | ) |
@@ -129,24 +145,28 @@ activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId/activity | |||
129 | activityPubClientRouter.get( | 145 | activityPubClientRouter.get( |
130 | [ '/video-channels/:nameWithHost', '/video-channels/:nameWithHost/videos', '/c/:nameWithHost', '/c/:nameWithHost/videos' ], | 146 | [ '/video-channels/:nameWithHost', '/video-channels/:nameWithHost/videos', '/c/:nameWithHost', '/c/:nameWithHost/videos' ], |
131 | executeIfActivityPub, | 147 | executeIfActivityPub, |
148 | activityPubRateLimiter, | ||
132 | asyncMiddleware(videoChannelsNameWithHostValidator), | 149 | asyncMiddleware(videoChannelsNameWithHostValidator), |
133 | ensureIsLocalChannel, | 150 | ensureIsLocalChannel, |
134 | asyncMiddleware(videoChannelController) | 151 | asyncMiddleware(videoChannelController) |
135 | ) | 152 | ) |
136 | activityPubClientRouter.get('/video-channels/:nameWithHost/followers', | 153 | activityPubClientRouter.get('/video-channels/:nameWithHost/followers', |
137 | executeIfActivityPub, | 154 | executeIfActivityPub, |
155 | activityPubRateLimiter, | ||
138 | asyncMiddleware(videoChannelsNameWithHostValidator), | 156 | asyncMiddleware(videoChannelsNameWithHostValidator), |
139 | ensureIsLocalChannel, | 157 | ensureIsLocalChannel, |
140 | asyncMiddleware(videoChannelFollowersController) | 158 | asyncMiddleware(videoChannelFollowersController) |
141 | ) | 159 | ) |
142 | activityPubClientRouter.get('/video-channels/:nameWithHost/following', | 160 | activityPubClientRouter.get('/video-channels/:nameWithHost/following', |
143 | executeIfActivityPub, | 161 | executeIfActivityPub, |
162 | activityPubRateLimiter, | ||
144 | asyncMiddleware(videoChannelsNameWithHostValidator), | 163 | asyncMiddleware(videoChannelsNameWithHostValidator), |
145 | ensureIsLocalChannel, | 164 | ensureIsLocalChannel, |
146 | asyncMiddleware(videoChannelFollowingController) | 165 | asyncMiddleware(videoChannelFollowingController) |
147 | ) | 166 | ) |
148 | activityPubClientRouter.get('/video-channels/:nameWithHost/playlists', | 167 | activityPubClientRouter.get('/video-channels/:nameWithHost/playlists', |
149 | executeIfActivityPub, | 168 | executeIfActivityPub, |
169 | activityPubRateLimiter, | ||
150 | asyncMiddleware(videoChannelsNameWithHostValidator), | 170 | asyncMiddleware(videoChannelsNameWithHostValidator), |
151 | ensureIsLocalChannel, | 171 | ensureIsLocalChannel, |
152 | asyncMiddleware(videoChannelPlaylistsController) | 172 | asyncMiddleware(videoChannelPlaylistsController) |
@@ -154,11 +174,13 @@ activityPubClientRouter.get('/video-channels/:nameWithHost/playlists', | |||
154 | 174 | ||
155 | activityPubClientRouter.get('/redundancy/videos/:videoId/:resolution([0-9]+)(-:fps([0-9]+))?', | 175 | activityPubClientRouter.get('/redundancy/videos/:videoId/:resolution([0-9]+)(-:fps([0-9]+))?', |
156 | executeIfActivityPub, | 176 | executeIfActivityPub, |
177 | activityPubRateLimiter, | ||
157 | asyncMiddleware(videoFileRedundancyGetValidator), | 178 | asyncMiddleware(videoFileRedundancyGetValidator), |
158 | asyncMiddleware(videoRedundancyController) | 179 | asyncMiddleware(videoRedundancyController) |
159 | ) | 180 | ) |
160 | activityPubClientRouter.get('/redundancy/streaming-playlists/:streamingPlaylistType/:videoId', | 181 | activityPubClientRouter.get('/redundancy/streaming-playlists/:streamingPlaylistType/:videoId', |
161 | executeIfActivityPub, | 182 | executeIfActivityPub, |
183 | activityPubRateLimiter, | ||
162 | asyncMiddleware(videoPlaylistRedundancyGetValidator), | 184 | asyncMiddleware(videoPlaylistRedundancyGetValidator), |
163 | asyncMiddleware(videoRedundancyController) | 185 | asyncMiddleware(videoRedundancyController) |
164 | ) | 186 | ) |
@@ -166,17 +188,20 @@ activityPubClientRouter.get('/redundancy/streaming-playlists/:streamingPlaylistT | |||
166 | activityPubClientRouter.get( | 188 | activityPubClientRouter.get( |
167 | [ '/video-playlists/:playlistId', '/videos/watch/playlist/:playlistId', '/w/p/:playlistId' ], | 189 | [ '/video-playlists/:playlistId', '/videos/watch/playlist/:playlistId', '/w/p/:playlistId' ], |
168 | executeIfActivityPub, | 190 | executeIfActivityPub, |
191 | activityPubRateLimiter, | ||
169 | asyncMiddleware(videoPlaylistsGetValidator('all')), | 192 | asyncMiddleware(videoPlaylistsGetValidator('all')), |
170 | asyncMiddleware(videoPlaylistController) | 193 | asyncMiddleware(videoPlaylistController) |
171 | ) | 194 | ) |
172 | activityPubClientRouter.get('/video-playlists/:playlistId/videos/:playlistElementId', | 195 | activityPubClientRouter.get('/video-playlists/:playlistId/videos/:playlistElementId', |
173 | executeIfActivityPub, | 196 | executeIfActivityPub, |
197 | activityPubRateLimiter, | ||
174 | asyncMiddleware(videoPlaylistElementAPGetValidator), | 198 | asyncMiddleware(videoPlaylistElementAPGetValidator), |
175 | asyncMiddleware(videoPlaylistElementController) | 199 | asyncMiddleware(videoPlaylistElementController) |
176 | ) | 200 | ) |
177 | 201 | ||
178 | activityPubClientRouter.get('/videos/local-viewer/:localViewerId', | 202 | activityPubClientRouter.get('/videos/local-viewer/:localViewerId', |
179 | executeIfActivityPub, | 203 | executeIfActivityPub, |
204 | activityPubRateLimiter, | ||
180 | asyncMiddleware(getVideoLocalViewerValidator), | 205 | asyncMiddleware(getVideoLocalViewerValidator), |
181 | asyncMiddleware(getVideoLocalViewerController) | 206 | asyncMiddleware(getVideoLocalViewerController) |
182 | ) | 207 | ) |