aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/well-known.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/well-known.ts')
-rw-r--r--server/controllers/well-known.ts15
1 files changed, 14 insertions, 1 deletions
diff --git a/server/controllers/well-known.ts b/server/controllers/well-known.ts
index bb9acfb37..322cf6ea2 100644
--- a/server/controllers/well-known.ts
+++ b/server/controllers/well-known.ts
@@ -1,7 +1,7 @@
1import cors from 'cors' 1import cors from 'cors'
2import express from 'express' 2import express from 'express'
3import { join } from 'path' 3import { join } from 'path'
4import { asyncMiddleware, handleStaticError, webfingerValidator } from '@server/middlewares' 4import { asyncMiddleware, buildRateLimiter, handleStaticError, webfingerValidator } from '@server/middlewares'
5import { root } from '@shared/core-utils' 5import { root } from '@shared/core-utils'
6import { CONFIG } from '../initializers/config' 6import { CONFIG } from '../initializers/config'
7import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants' 7import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants'
@@ -9,14 +9,21 @@ import { cacheRoute } from '../middlewares/cache/cache'
9 9
10const wellKnownRouter = express.Router() 10const wellKnownRouter = express.Router()
11 11
12const wellKnownRateLimiter = buildRateLimiter({
13 windowMs: CONFIG.RATES_LIMIT.WELL_KNOWN.WINDOW_MS,
14 max: CONFIG.RATES_LIMIT.WELL_KNOWN.MAX
15})
16
12wellKnownRouter.use(cors()) 17wellKnownRouter.use(cors())
13 18
14wellKnownRouter.get('/.well-known/webfinger', 19wellKnownRouter.get('/.well-known/webfinger',
20 wellKnownRateLimiter,
15 asyncMiddleware(webfingerValidator), 21 asyncMiddleware(webfingerValidator),
16 webfingerController 22 webfingerController
17) 23)
18 24
19wellKnownRouter.get('/.well-known/security.txt', 25wellKnownRouter.get('/.well-known/security.txt',
26 wellKnownRateLimiter,
20 cacheRoute(ROUTE_CACHE_LIFETIME.SECURITYTXT), 27 cacheRoute(ROUTE_CACHE_LIFETIME.SECURITYTXT),
21 (_, res: express.Response) => { 28 (_, res: express.Response) => {
22 res.type('text/plain') 29 res.type('text/plain')
@@ -26,6 +33,7 @@ wellKnownRouter.get('/.well-known/security.txt',
26 33
27// nodeinfo service 34// nodeinfo service
28wellKnownRouter.use('/.well-known/nodeinfo', 35wellKnownRouter.use('/.well-known/nodeinfo',
36 wellKnownRateLimiter,
29 cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO), 37 cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO),
30 (_, res: express.Response) => { 38 (_, res: express.Response) => {
31 return res.json({ 39 return res.json({
@@ -41,6 +49,7 @@ wellKnownRouter.use('/.well-known/nodeinfo',
41 49
42// dnt-policy.txt service (see https://www.eff.org/dnt-policy) 50// dnt-policy.txt service (see https://www.eff.org/dnt-policy)
43wellKnownRouter.use('/.well-known/dnt-policy.txt', 51wellKnownRouter.use('/.well-known/dnt-policy.txt',
52 wellKnownRateLimiter,
44 cacheRoute(ROUTE_CACHE_LIFETIME.DNT_POLICY), 53 cacheRoute(ROUTE_CACHE_LIFETIME.DNT_POLICY),
45 (_, res: express.Response) => { 54 (_, res: express.Response) => {
46 res.type('text/plain') 55 res.type('text/plain')
@@ -51,18 +60,21 @@ wellKnownRouter.use('/.well-known/dnt-policy.txt',
51 60
52// dnt service (see https://www.w3.org/TR/tracking-dnt/#status-resource) 61// dnt service (see https://www.w3.org/TR/tracking-dnt/#status-resource)
53wellKnownRouter.use('/.well-known/dnt/', 62wellKnownRouter.use('/.well-known/dnt/',
63 wellKnownRateLimiter,
54 (_, res: express.Response) => { 64 (_, res: express.Response) => {
55 res.json({ tracking: 'N' }) 65 res.json({ tracking: 'N' })
56 } 66 }
57) 67)
58 68
59wellKnownRouter.use('/.well-known/change-password', 69wellKnownRouter.use('/.well-known/change-password',
70 wellKnownRateLimiter,
60 (_, res: express.Response) => { 71 (_, res: express.Response) => {
61 res.redirect('/my-account/settings') 72 res.redirect('/my-account/settings')
62 } 73 }
63) 74)
64 75
65wellKnownRouter.use('/.well-known/host-meta', 76wellKnownRouter.use('/.well-known/host-meta',
77 wellKnownRateLimiter,
66 (_, res: express.Response) => { 78 (_, res: express.Response) => {
67 res.type('application/xml') 79 res.type('application/xml')
68 80
@@ -76,6 +88,7 @@ wellKnownRouter.use('/.well-known/host-meta',
76) 88)
77 89
78wellKnownRouter.use('/.well-known/', 90wellKnownRouter.use('/.well-known/',
91 wellKnownRateLimiter,
79 cacheRoute(ROUTE_CACHE_LIFETIME.WELL_KNOWN), 92 cacheRoute(ROUTE_CACHE_LIFETIME.WELL_KNOWN),
80 express.static(CONFIG.STORAGE.WELL_KNOWN_DIR, { fallthrough: false }), 93 express.static(CONFIG.STORAGE.WELL_KNOWN_DIR, { fallthrough: false }),
81 handleStaticError 94 handleStaticError