diff options
author | Chocobozzz <me@florianbigard.com> | 2023-06-20 14:17:34 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-06-20 14:17:34 +0200 |
commit | e915cde30ec47258a2beeec5ca748c928b59858c (patch) | |
tree | f5692ab20c534a61487f3bd471bb6105ed58d88a /server/controllers/api/runners | |
parent | 923e41fa4f342019298b46e407ea1f0207f74205 (diff) | |
download | PeerTube-e915cde30ec47258a2beeec5ca748c928b59858c.tar.gz PeerTube-e915cde30ec47258a2beeec5ca748c928b59858c.tar.zst PeerTube-e915cde30ec47258a2beeec5ca748c928b59858c.zip |
Fix runner api rate limit bypass
Diffstat (limited to 'server/controllers/api/runners')
-rw-r--r-- | server/controllers/api/runners/index.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/runners/jobs-files.ts | 5 | ||||
-rw-r--r-- | server/controllers/api/runners/jobs.ts | 6 | ||||
-rw-r--r-- | server/controllers/api/runners/manage-runners.ts | 5 | ||||
-rw-r--r-- | server/controllers/api/runners/registration-tokens.ts | 6 |
5 files changed, 22 insertions, 2 deletions
diff --git a/server/controllers/api/runners/index.ts b/server/controllers/api/runners/index.ts index c98ded354..9998fe4cc 100644 --- a/server/controllers/api/runners/index.ts +++ b/server/controllers/api/runners/index.ts | |||
@@ -6,6 +6,8 @@ import { runnerRegistrationTokensRouter } from './registration-tokens' | |||
6 | 6 | ||
7 | const runnersRouter = express.Router() | 7 | const runnersRouter = express.Router() |
8 | 8 | ||
9 | // No api route limiter here, they are defined in child routers | ||
10 | |||
9 | runnersRouter.use('/', manageRunnersRouter) | 11 | runnersRouter.use('/', manageRunnersRouter) |
10 | runnersRouter.use('/', runnerJobsRouter) | 12 | runnersRouter.use('/', runnerJobsRouter) |
11 | runnersRouter.use('/', runnerJobFilesRouter) | 13 | runnersRouter.use('/', runnerJobFilesRouter) |
diff --git a/server/controllers/api/runners/jobs-files.ts b/server/controllers/api/runners/jobs-files.ts index 260d824a8..4e69fb902 100644 --- a/server/controllers/api/runners/jobs-files.ts +++ b/server/controllers/api/runners/jobs-files.ts | |||
@@ -3,7 +3,7 @@ import { logger, loggerTagsFactory } from '@server/helpers/logger' | |||
3 | import { proxifyHLS, proxifyWebTorrentFile } from '@server/lib/object-storage' | 3 | import { proxifyHLS, proxifyWebTorrentFile } from '@server/lib/object-storage' |
4 | import { VideoPathManager } from '@server/lib/video-path-manager' | 4 | import { VideoPathManager } from '@server/lib/video-path-manager' |
5 | import { getStudioTaskFilePath } from '@server/lib/video-studio' | 5 | import { getStudioTaskFilePath } from '@server/lib/video-studio' |
6 | import { asyncMiddleware } from '@server/middlewares' | 6 | import { apiRateLimiter, asyncMiddleware } from '@server/middlewares' |
7 | import { jobOfRunnerGetValidator } from '@server/middlewares/validators/runners' | 7 | import { jobOfRunnerGetValidator } from '@server/middlewares/validators/runners' |
8 | import { | 8 | import { |
9 | runnerJobGetVideoStudioTaskFileValidator, | 9 | runnerJobGetVideoStudioTaskFileValidator, |
@@ -16,18 +16,21 @@ const lTags = loggerTagsFactory('api', 'runner') | |||
16 | const runnerJobFilesRouter = express.Router() | 16 | const runnerJobFilesRouter = express.Router() |
17 | 17 | ||
18 | runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/max-quality', | 18 | runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/max-quality', |
19 | apiRateLimiter, | ||
19 | asyncMiddleware(jobOfRunnerGetValidator), | 20 | asyncMiddleware(jobOfRunnerGetValidator), |
20 | asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), | 21 | asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), |
21 | asyncMiddleware(getMaxQualityVideoFile) | 22 | asyncMiddleware(getMaxQualityVideoFile) |
22 | ) | 23 | ) |
23 | 24 | ||
24 | runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/previews/max-quality', | 25 | runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/previews/max-quality', |
26 | apiRateLimiter, | ||
25 | asyncMiddleware(jobOfRunnerGetValidator), | 27 | asyncMiddleware(jobOfRunnerGetValidator), |
26 | asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), | 28 | asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), |
27 | getMaxQualityVideoPreview | 29 | getMaxQualityVideoPreview |
28 | ) | 30 | ) |
29 | 31 | ||
30 | runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/studio/task-files/:filename', | 32 | runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/studio/task-files/:filename', |
33 | apiRateLimiter, | ||
31 | asyncMiddleware(jobOfRunnerGetValidator), | 34 | asyncMiddleware(jobOfRunnerGetValidator), |
32 | asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), | 35 | asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), |
33 | runnerJobGetVideoStudioTaskFileValidator, | 36 | runnerJobGetVideoStudioTaskFileValidator, |
diff --git a/server/controllers/api/runners/jobs.ts b/server/controllers/api/runners/jobs.ts index 140f062be..5d687e689 100644 --- a/server/controllers/api/runners/jobs.ts +++ b/server/controllers/api/runners/jobs.ts | |||
@@ -7,6 +7,7 @@ import { MIMETYPES } from '@server/initializers/constants' | |||
7 | import { sequelizeTypescript } from '@server/initializers/database' | 7 | import { sequelizeTypescript } from '@server/initializers/database' |
8 | import { getRunnerJobHandlerClass, updateLastRunnerContact } from '@server/lib/runners' | 8 | import { getRunnerJobHandlerClass, updateLastRunnerContact } from '@server/lib/runners' |
9 | import { | 9 | import { |
10 | apiRateLimiter, | ||
10 | asyncMiddleware, | 11 | asyncMiddleware, |
11 | authenticate, | 12 | authenticate, |
12 | ensureUserHasRight, | 13 | ensureUserHasRight, |
@@ -69,11 +70,13 @@ const runnerJobsRouter = express.Router() | |||
69 | // --------------------------------------------------------------------------- | 70 | // --------------------------------------------------------------------------- |
70 | 71 | ||
71 | runnerJobsRouter.post('/jobs/request', | 72 | runnerJobsRouter.post('/jobs/request', |
73 | apiRateLimiter, | ||
72 | asyncMiddleware(getRunnerFromTokenValidator), | 74 | asyncMiddleware(getRunnerFromTokenValidator), |
73 | asyncMiddleware(requestRunnerJob) | 75 | asyncMiddleware(requestRunnerJob) |
74 | ) | 76 | ) |
75 | 77 | ||
76 | runnerJobsRouter.post('/jobs/:jobUUID/accept', | 78 | runnerJobsRouter.post('/jobs/:jobUUID/accept', |
79 | apiRateLimiter, | ||
77 | asyncMiddleware(runnerJobGetValidator), | 80 | asyncMiddleware(runnerJobGetValidator), |
78 | acceptRunnerJobValidator, | 81 | acceptRunnerJobValidator, |
79 | asyncMiddleware(getRunnerFromTokenValidator), | 82 | asyncMiddleware(getRunnerFromTokenValidator), |
@@ -81,6 +84,7 @@ runnerJobsRouter.post('/jobs/:jobUUID/accept', | |||
81 | ) | 84 | ) |
82 | 85 | ||
83 | runnerJobsRouter.post('/jobs/:jobUUID/abort', | 86 | runnerJobsRouter.post('/jobs/:jobUUID/abort', |
87 | apiRateLimiter, | ||
84 | asyncMiddleware(jobOfRunnerGetValidator), | 88 | asyncMiddleware(jobOfRunnerGetValidator), |
85 | abortRunnerJobValidator, | 89 | abortRunnerJobValidator, |
86 | asyncMiddleware(abortRunnerJob) | 90 | asyncMiddleware(abortRunnerJob) |
@@ -88,6 +92,7 @@ runnerJobsRouter.post('/jobs/:jobUUID/abort', | |||
88 | 92 | ||
89 | runnerJobsRouter.post('/jobs/:jobUUID/update', | 93 | runnerJobsRouter.post('/jobs/:jobUUID/update', |
90 | runnerJobUpdateVideoFiles, | 94 | runnerJobUpdateVideoFiles, |
95 | apiRateLimiter, // Has to be after multer middleware to parse runner token | ||
91 | asyncMiddleware(jobOfRunnerGetValidator), | 96 | asyncMiddleware(jobOfRunnerGetValidator), |
92 | updateRunnerJobValidator, | 97 | updateRunnerJobValidator, |
93 | asyncMiddleware(updateRunnerJobController) | 98 | asyncMiddleware(updateRunnerJobController) |
@@ -101,6 +106,7 @@ runnerJobsRouter.post('/jobs/:jobUUID/error', | |||
101 | 106 | ||
102 | runnerJobsRouter.post('/jobs/:jobUUID/success', | 107 | runnerJobsRouter.post('/jobs/:jobUUID/success', |
103 | postRunnerJobSuccessVideoFiles, | 108 | postRunnerJobSuccessVideoFiles, |
109 | apiRateLimiter, // Has to be after multer middleware to parse runner token | ||
104 | asyncMiddleware(jobOfRunnerGetValidator), | 110 | asyncMiddleware(jobOfRunnerGetValidator), |
105 | successRunnerJobValidator, | 111 | successRunnerJobValidator, |
106 | asyncMiddleware(postRunnerJobSuccess) | 112 | asyncMiddleware(postRunnerJobSuccess) |
diff --git a/server/controllers/api/runners/manage-runners.ts b/server/controllers/api/runners/manage-runners.ts index eb08c4b1d..be7ebc0b3 100644 --- a/server/controllers/api/runners/manage-runners.ts +++ b/server/controllers/api/runners/manage-runners.ts | |||
@@ -2,6 +2,7 @@ import express from 'express' | |||
2 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | 2 | import { logger, loggerTagsFactory } from '@server/helpers/logger' |
3 | import { generateRunnerToken } from '@server/helpers/token-generator' | 3 | import { generateRunnerToken } from '@server/helpers/token-generator' |
4 | import { | 4 | import { |
5 | apiRateLimiter, | ||
5 | asyncMiddleware, | 6 | asyncMiddleware, |
6 | authenticate, | 7 | authenticate, |
7 | ensureUserHasRight, | 8 | ensureUserHasRight, |
@@ -19,15 +20,18 @@ const lTags = loggerTagsFactory('api', 'runner') | |||
19 | const manageRunnersRouter = express.Router() | 20 | const manageRunnersRouter = express.Router() |
20 | 21 | ||
21 | manageRunnersRouter.post('/register', | 22 | manageRunnersRouter.post('/register', |
23 | apiRateLimiter, | ||
22 | asyncMiddleware(registerRunnerValidator), | 24 | asyncMiddleware(registerRunnerValidator), |
23 | asyncMiddleware(registerRunner) | 25 | asyncMiddleware(registerRunner) |
24 | ) | 26 | ) |
25 | manageRunnersRouter.post('/unregister', | 27 | manageRunnersRouter.post('/unregister', |
28 | apiRateLimiter, | ||
26 | asyncMiddleware(getRunnerFromTokenValidator), | 29 | asyncMiddleware(getRunnerFromTokenValidator), |
27 | asyncMiddleware(unregisterRunner) | 30 | asyncMiddleware(unregisterRunner) |
28 | ) | 31 | ) |
29 | 32 | ||
30 | manageRunnersRouter.delete('/:runnerId', | 33 | manageRunnersRouter.delete('/:runnerId', |
34 | apiRateLimiter, | ||
31 | authenticate, | 35 | authenticate, |
32 | ensureUserHasRight(UserRight.MANAGE_RUNNERS), | 36 | ensureUserHasRight(UserRight.MANAGE_RUNNERS), |
33 | asyncMiddleware(deleteRunnerValidator), | 37 | asyncMiddleware(deleteRunnerValidator), |
@@ -35,6 +39,7 @@ manageRunnersRouter.delete('/:runnerId', | |||
35 | ) | 39 | ) |
36 | 40 | ||
37 | manageRunnersRouter.get('/', | 41 | manageRunnersRouter.get('/', |
42 | apiRateLimiter, | ||
38 | authenticate, | 43 | authenticate, |
39 | ensureUserHasRight(UserRight.MANAGE_RUNNERS), | 44 | ensureUserHasRight(UserRight.MANAGE_RUNNERS), |
40 | paginationValidator, | 45 | paginationValidator, |
diff --git a/server/controllers/api/runners/registration-tokens.ts b/server/controllers/api/runners/registration-tokens.ts index 5ac3773fe..117ff271b 100644 --- a/server/controllers/api/runners/registration-tokens.ts +++ b/server/controllers/api/runners/registration-tokens.ts | |||
@@ -1,6 +1,8 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | ||
2 | import { generateRunnerRegistrationToken } from '@server/helpers/token-generator' | 3 | import { generateRunnerRegistrationToken } from '@server/helpers/token-generator' |
3 | import { | 4 | import { |
5 | apiRateLimiter, | ||
4 | asyncMiddleware, | 6 | asyncMiddleware, |
5 | authenticate, | 7 | authenticate, |
6 | ensureUserHasRight, | 8 | ensureUserHasRight, |
@@ -12,19 +14,20 @@ import { | |||
12 | import { deleteRegistrationTokenValidator } from '@server/middlewares/validators/runners' | 14 | import { deleteRegistrationTokenValidator } from '@server/middlewares/validators/runners' |
13 | import { RunnerRegistrationTokenModel } from '@server/models/runner/runner-registration-token' | 15 | import { RunnerRegistrationTokenModel } from '@server/models/runner/runner-registration-token' |
14 | import { HttpStatusCode, ListRunnerRegistrationTokensQuery, UserRight } from '@shared/models' | 16 | import { HttpStatusCode, ListRunnerRegistrationTokensQuery, UserRight } from '@shared/models' |
15 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | ||
16 | 17 | ||
17 | const lTags = loggerTagsFactory('api', 'runner') | 18 | const lTags = loggerTagsFactory('api', 'runner') |
18 | 19 | ||
19 | const runnerRegistrationTokensRouter = express.Router() | 20 | const runnerRegistrationTokensRouter = express.Router() |
20 | 21 | ||
21 | runnerRegistrationTokensRouter.post('/registration-tokens/generate', | 22 | runnerRegistrationTokensRouter.post('/registration-tokens/generate', |
23 | apiRateLimiter, | ||
22 | authenticate, | 24 | authenticate, |
23 | ensureUserHasRight(UserRight.MANAGE_RUNNERS), | 25 | ensureUserHasRight(UserRight.MANAGE_RUNNERS), |
24 | asyncMiddleware(generateRegistrationToken) | 26 | asyncMiddleware(generateRegistrationToken) |
25 | ) | 27 | ) |
26 | 28 | ||
27 | runnerRegistrationTokensRouter.delete('/registration-tokens/:id', | 29 | runnerRegistrationTokensRouter.delete('/registration-tokens/:id', |
30 | apiRateLimiter, | ||
28 | authenticate, | 31 | authenticate, |
29 | ensureUserHasRight(UserRight.MANAGE_RUNNERS), | 32 | ensureUserHasRight(UserRight.MANAGE_RUNNERS), |
30 | asyncMiddleware(deleteRegistrationTokenValidator), | 33 | asyncMiddleware(deleteRegistrationTokenValidator), |
@@ -32,6 +35,7 @@ runnerRegistrationTokensRouter.delete('/registration-tokens/:id', | |||
32 | ) | 35 | ) |
33 | 36 | ||
34 | runnerRegistrationTokensRouter.get('/registration-tokens', | 37 | runnerRegistrationTokensRouter.get('/registration-tokens', |
38 | apiRateLimiter, | ||
35 | authenticate, | 39 | authenticate, |
36 | ensureUserHasRight(UserRight.MANAGE_RUNNERS), | 40 | ensureUserHasRight(UserRight.MANAGE_RUNNERS), |
37 | paginationValidator, | 41 | paginationValidator, |