diff options
Diffstat (limited to 'server/controllers/plugins.ts')
-rw-r--r-- | server/controllers/plugins.ts | 17 |
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 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { join } from 'path' | 2 | import { join } from 'path' |
3 | import { logger } from '@server/helpers/logger' | 3 | import { logger } from '@server/helpers/logger' |
4 | import { CONFIG } from '@server/initializers/config' | ||
5 | import { buildRateLimiter } from '@server/middlewares' | ||
4 | import { optionalAuthenticate } from '@server/middlewares/auth' | 6 | import { optionalAuthenticate } from '@server/middlewares/auth' |
5 | import { getCompleteLocale, is18nLocale } from '../../shared/core-utils/i18n' | 7 | import { getCompleteLocale, is18nLocale } from '../../shared/core-utils/i18n' |
6 | import { HttpStatusCode } from '../../shared/models/http/http-error-codes' | 8 | import { HttpStatusCode } from '../../shared/models/http/http-error-codes' |
@@ -18,57 +20,72 @@ const sendFileOptions = { | |||
18 | 20 | ||
19 | const pluginsRouter = express.Router() | 21 | const pluginsRouter = express.Router() |
20 | 22 | ||
23 | const pluginsRateLimiter = buildRateLimiter({ | ||
24 | windowMs: CONFIG.RATES_LIMIT.PLUGINS.WINDOW_MS, | ||
25 | max: CONFIG.RATES_LIMIT.PLUGINS.MAX | ||
26 | }) | ||
27 | |||
21 | pluginsRouter.get('/plugins/global.css', | 28 | pluginsRouter.get('/plugins/global.css', |
29 | pluginsRateLimiter, | ||
22 | servePluginGlobalCSS | 30 | servePluginGlobalCSS |
23 | ) | 31 | ) |
24 | 32 | ||
25 | pluginsRouter.get('/plugins/translations/:locale.json', | 33 | pluginsRouter.get('/plugins/translations/:locale.json', |
34 | pluginsRateLimiter, | ||
26 | getPluginTranslations | 35 | getPluginTranslations |
27 | ) | 36 | ) |
28 | 37 | ||
29 | pluginsRouter.get('/plugins/:pluginName/:pluginVersion/auth/:authName', | 38 | pluginsRouter.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 | ||
35 | pluginsRouter.get('/plugins/:pluginName/:pluginVersion/static/:staticEndpoint(*)', | 45 | pluginsRouter.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 | ||
41 | pluginsRouter.get('/plugins/:pluginName/:pluginVersion/client-scripts/:staticEndpoint(*)', | 52 | pluginsRouter.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 | ||
47 | pluginsRouter.use('/plugins/:pluginName/router', | 59 | pluginsRouter.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 | ||
53 | pluginsRouter.use('/plugins/:pluginName/:pluginVersion/router', | 66 | pluginsRouter.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 | ||
59 | pluginsRouter.get('/themes/:pluginName/:pluginVersion/static/:staticEndpoint(*)', | 73 | pluginsRouter.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 | ||
65 | pluginsRouter.get('/themes/:pluginName/:pluginVersion/client-scripts/:staticEndpoint(*)', | 80 | pluginsRouter.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 | ||
71 | pluginsRouter.get('/themes/:themeName/:themeVersion/css/:staticEndpoint(*)', | 87 | pluginsRouter.get('/themes/:themeName/:themeVersion/css/:staticEndpoint(*)', |
88 | pluginsRateLimiter, | ||
72 | serveThemeCSSValidator, | 89 | serveThemeCSSValidator, |
73 | serveThemeCSSDirectory | 90 | serveThemeCSSDirectory |
74 | ) | 91 | ) |