aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/plugins.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/plugins.ts')
-rw-r--r--server/controllers/plugins.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/server/controllers/plugins.ts b/server/controllers/plugins.ts
index 51db1ad89..f0491b16a 100644
--- a/server/controllers/plugins.ts
+++ b/server/controllers/plugins.ts
@@ -1,6 +1,8 @@
1import express from 'express' 1import express from 'express'
2import { join } from 'path' 2import { join } from 'path'
3import { logger } from '@server/helpers/logger' 3import { logger } from '@server/helpers/logger'
4import { CONFIG } from '@server/initializers/config'
5import { buildRateLimiter } from '@server/middlewares'
4import { optionalAuthenticate } from '@server/middlewares/auth' 6import { optionalAuthenticate } from '@server/middlewares/auth'
5import { getCompleteLocale, is18nLocale } from '../../shared/core-utils/i18n' 7import { getCompleteLocale, is18nLocale } from '../../shared/core-utils/i18n'
6import { HttpStatusCode } from '../../shared/models/http/http-error-codes' 8import { HttpStatusCode } from '../../shared/models/http/http-error-codes'
@@ -18,57 +20,72 @@ const sendFileOptions = {
18 20
19const pluginsRouter = express.Router() 21const pluginsRouter = express.Router()
20 22
23const pluginsRateLimiter = buildRateLimiter({
24 windowMs: CONFIG.RATES_LIMIT.PLUGINS.WINDOW_MS,
25 max: CONFIG.RATES_LIMIT.PLUGINS.MAX
26})
27
21pluginsRouter.get('/plugins/global.css', 28pluginsRouter.get('/plugins/global.css',
29 pluginsRateLimiter,
22 servePluginGlobalCSS 30 servePluginGlobalCSS
23) 31)
24 32
25pluginsRouter.get('/plugins/translations/:locale.json', 33pluginsRouter.get('/plugins/translations/:locale.json',
34 pluginsRateLimiter,
26 getPluginTranslations 35 getPluginTranslations
27) 36)
28 37
29pluginsRouter.get('/plugins/:pluginName/:pluginVersion/auth/:authName', 38pluginsRouter.get('/plugins/:pluginName/:pluginVersion/auth/:authName',
39 pluginsRateLimiter,
30 getPluginValidator(PluginType.PLUGIN), 40 getPluginValidator(PluginType.PLUGIN),
31 getExternalAuthValidator, 41 getExternalAuthValidator,
32 handleAuthInPlugin 42 handleAuthInPlugin
33) 43)
34 44
35pluginsRouter.get('/plugins/:pluginName/:pluginVersion/static/:staticEndpoint(*)', 45pluginsRouter.get('/plugins/:pluginName/:pluginVersion/static/:staticEndpoint(*)',
46 pluginsRateLimiter,
36 getPluginValidator(PluginType.PLUGIN), 47 getPluginValidator(PluginType.PLUGIN),
37 pluginStaticDirectoryValidator, 48 pluginStaticDirectoryValidator,
38 servePluginStaticDirectory 49 servePluginStaticDirectory
39) 50)
40 51
41pluginsRouter.get('/plugins/:pluginName/:pluginVersion/client-scripts/:staticEndpoint(*)', 52pluginsRouter.get('/plugins/:pluginName/:pluginVersion/client-scripts/:staticEndpoint(*)',
53 pluginsRateLimiter,
42 getPluginValidator(PluginType.PLUGIN), 54 getPluginValidator(PluginType.PLUGIN),
43 pluginStaticDirectoryValidator, 55 pluginStaticDirectoryValidator,
44 servePluginClientScripts 56 servePluginClientScripts
45) 57)
46 58
47pluginsRouter.use('/plugins/:pluginName/router', 59pluginsRouter.use('/plugins/:pluginName/router',
60 pluginsRateLimiter,
48 getPluginValidator(PluginType.PLUGIN, false), 61 getPluginValidator(PluginType.PLUGIN, false),
49 optionalAuthenticate, 62 optionalAuthenticate,
50 servePluginCustomRoutes 63 servePluginCustomRoutes
51) 64)
52 65
53pluginsRouter.use('/plugins/:pluginName/:pluginVersion/router', 66pluginsRouter.use('/plugins/:pluginName/:pluginVersion/router',
67 pluginsRateLimiter,
54 getPluginValidator(PluginType.PLUGIN), 68 getPluginValidator(PluginType.PLUGIN),
55 optionalAuthenticate, 69 optionalAuthenticate,
56 servePluginCustomRoutes 70 servePluginCustomRoutes
57) 71)
58 72
59pluginsRouter.get('/themes/:pluginName/:pluginVersion/static/:staticEndpoint(*)', 73pluginsRouter.get('/themes/:pluginName/:pluginVersion/static/:staticEndpoint(*)',
74 pluginsRateLimiter,
60 getPluginValidator(PluginType.THEME), 75 getPluginValidator(PluginType.THEME),
61 pluginStaticDirectoryValidator, 76 pluginStaticDirectoryValidator,
62 servePluginStaticDirectory 77 servePluginStaticDirectory
63) 78)
64 79
65pluginsRouter.get('/themes/:pluginName/:pluginVersion/client-scripts/:staticEndpoint(*)', 80pluginsRouter.get('/themes/:pluginName/:pluginVersion/client-scripts/:staticEndpoint(*)',
81 pluginsRateLimiter,
66 getPluginValidator(PluginType.THEME), 82 getPluginValidator(PluginType.THEME),
67 pluginStaticDirectoryValidator, 83 pluginStaticDirectoryValidator,
68 servePluginClientScripts 84 servePluginClientScripts
69) 85)
70 86
71pluginsRouter.get('/themes/:themeName/:themeVersion/css/:staticEndpoint(*)', 87pluginsRouter.get('/themes/:themeName/:themeVersion/css/:staticEndpoint(*)',
88 pluginsRateLimiter,
72 serveThemeCSSValidator, 89 serveThemeCSSValidator,
73 serveThemeCSSDirectory 90 serveThemeCSSDirectory
74) 91)