aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/runners
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-06-20 14:17:34 +0200
committerChocobozzz <me@florianbigard.com>2023-06-20 14:17:34 +0200
commite915cde30ec47258a2beeec5ca748c928b59858c (patch)
treef5692ab20c534a61487f3bd471bb6105ed58d88a /server/controllers/api/runners
parent923e41fa4f342019298b46e407ea1f0207f74205 (diff)
downloadPeerTube-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.ts2
-rw-r--r--server/controllers/api/runners/jobs-files.ts5
-rw-r--r--server/controllers/api/runners/jobs.ts6
-rw-r--r--server/controllers/api/runners/manage-runners.ts5
-rw-r--r--server/controllers/api/runners/registration-tokens.ts6
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
7const runnersRouter = express.Router() 7const runnersRouter = express.Router()
8 8
9// No api route limiter here, they are defined in child routers
10
9runnersRouter.use('/', manageRunnersRouter) 11runnersRouter.use('/', manageRunnersRouter)
10runnersRouter.use('/', runnerJobsRouter) 12runnersRouter.use('/', runnerJobsRouter)
11runnersRouter.use('/', runnerJobFilesRouter) 13runnersRouter.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'
3import { proxifyHLS, proxifyWebTorrentFile } from '@server/lib/object-storage' 3import { proxifyHLS, proxifyWebTorrentFile } from '@server/lib/object-storage'
4import { VideoPathManager } from '@server/lib/video-path-manager' 4import { VideoPathManager } from '@server/lib/video-path-manager'
5import { getStudioTaskFilePath } from '@server/lib/video-studio' 5import { getStudioTaskFilePath } from '@server/lib/video-studio'
6import { asyncMiddleware } from '@server/middlewares' 6import { apiRateLimiter, asyncMiddleware } from '@server/middlewares'
7import { jobOfRunnerGetValidator } from '@server/middlewares/validators/runners' 7import { jobOfRunnerGetValidator } from '@server/middlewares/validators/runners'
8import { 8import {
9 runnerJobGetVideoStudioTaskFileValidator, 9 runnerJobGetVideoStudioTaskFileValidator,
@@ -16,18 +16,21 @@ const lTags = loggerTagsFactory('api', 'runner')
16const runnerJobFilesRouter = express.Router() 16const runnerJobFilesRouter = express.Router()
17 17
18runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/max-quality', 18runnerJobFilesRouter.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
24runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/previews/max-quality', 25runnerJobFilesRouter.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
30runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/studio/task-files/:filename', 32runnerJobFilesRouter.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'
7import { sequelizeTypescript } from '@server/initializers/database' 7import { sequelizeTypescript } from '@server/initializers/database'
8import { getRunnerJobHandlerClass, updateLastRunnerContact } from '@server/lib/runners' 8import { getRunnerJobHandlerClass, updateLastRunnerContact } from '@server/lib/runners'
9import { 9import {
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
71runnerJobsRouter.post('/jobs/request', 72runnerJobsRouter.post('/jobs/request',
73 apiRateLimiter,
72 asyncMiddleware(getRunnerFromTokenValidator), 74 asyncMiddleware(getRunnerFromTokenValidator),
73 asyncMiddleware(requestRunnerJob) 75 asyncMiddleware(requestRunnerJob)
74) 76)
75 77
76runnerJobsRouter.post('/jobs/:jobUUID/accept', 78runnerJobsRouter.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
83runnerJobsRouter.post('/jobs/:jobUUID/abort', 86runnerJobsRouter.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
89runnerJobsRouter.post('/jobs/:jobUUID/update', 93runnerJobsRouter.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
102runnerJobsRouter.post('/jobs/:jobUUID/success', 107runnerJobsRouter.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'
2import { logger, loggerTagsFactory } from '@server/helpers/logger' 2import { logger, loggerTagsFactory } from '@server/helpers/logger'
3import { generateRunnerToken } from '@server/helpers/token-generator' 3import { generateRunnerToken } from '@server/helpers/token-generator'
4import { 4import {
5 apiRateLimiter,
5 asyncMiddleware, 6 asyncMiddleware,
6 authenticate, 7 authenticate,
7 ensureUserHasRight, 8 ensureUserHasRight,
@@ -19,15 +20,18 @@ const lTags = loggerTagsFactory('api', 'runner')
19const manageRunnersRouter = express.Router() 20const manageRunnersRouter = express.Router()
20 21
21manageRunnersRouter.post('/register', 22manageRunnersRouter.post('/register',
23 apiRateLimiter,
22 asyncMiddleware(registerRunnerValidator), 24 asyncMiddleware(registerRunnerValidator),
23 asyncMiddleware(registerRunner) 25 asyncMiddleware(registerRunner)
24) 26)
25manageRunnersRouter.post('/unregister', 27manageRunnersRouter.post('/unregister',
28 apiRateLimiter,
26 asyncMiddleware(getRunnerFromTokenValidator), 29 asyncMiddleware(getRunnerFromTokenValidator),
27 asyncMiddleware(unregisterRunner) 30 asyncMiddleware(unregisterRunner)
28) 31)
29 32
30manageRunnersRouter.delete('/:runnerId', 33manageRunnersRouter.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
37manageRunnersRouter.get('/', 41manageRunnersRouter.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 @@
1import express from 'express' 1import express from 'express'
2import { logger, loggerTagsFactory } from '@server/helpers/logger'
2import { generateRunnerRegistrationToken } from '@server/helpers/token-generator' 3import { generateRunnerRegistrationToken } from '@server/helpers/token-generator'
3import { 4import {
5 apiRateLimiter,
4 asyncMiddleware, 6 asyncMiddleware,
5 authenticate, 7 authenticate,
6 ensureUserHasRight, 8 ensureUserHasRight,
@@ -12,19 +14,20 @@ import {
12import { deleteRegistrationTokenValidator } from '@server/middlewares/validators/runners' 14import { deleteRegistrationTokenValidator } from '@server/middlewares/validators/runners'
13import { RunnerRegistrationTokenModel } from '@server/models/runner/runner-registration-token' 15import { RunnerRegistrationTokenModel } from '@server/models/runner/runner-registration-token'
14import { HttpStatusCode, ListRunnerRegistrationTokensQuery, UserRight } from '@shared/models' 16import { HttpStatusCode, ListRunnerRegistrationTokensQuery, UserRight } from '@shared/models'
15import { logger, loggerTagsFactory } from '@server/helpers/logger'
16 17
17const lTags = loggerTagsFactory('api', 'runner') 18const lTags = loggerTagsFactory('api', 'runner')
18 19
19const runnerRegistrationTokensRouter = express.Router() 20const runnerRegistrationTokensRouter = express.Router()
20 21
21runnerRegistrationTokensRouter.post('/registration-tokens/generate', 22runnerRegistrationTokensRouter.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
27runnerRegistrationTokensRouter.delete('/registration-tokens/:id', 29runnerRegistrationTokensRouter.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
34runnerRegistrationTokensRouter.get('/registration-tokens', 37runnerRegistrationTokensRouter.get('/registration-tokens',
38 apiRateLimiter,
35 authenticate, 39 authenticate,
36 ensureUserHasRight(UserRight.MANAGE_RUNNERS), 40 ensureUserHasRight(UserRight.MANAGE_RUNNERS),
37 paginationValidator, 41 paginationValidator,