aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/index.ts1
-rw-r--r--server/middlewares/robots.ts13
-rw-r--r--server/middlewares/validators/oembed.ts16
3 files changed, 29 insertions, 1 deletions
diff --git a/server/middlewares/index.ts b/server/middlewares/index.ts
index a0035f623..d2ed079b6 100644
--- a/server/middlewares/index.ts
+++ b/server/middlewares/index.ts
@@ -4,6 +4,7 @@ export * from './activitypub'
4export * from './async' 4export * from './async'
5export * from './auth' 5export * from './auth'
6export * from './pagination' 6export * from './pagination'
7export * from './robots'
7export * from './servers' 8export * from './servers'
8export * from './sort' 9export * from './sort'
9export * from './user-right' 10export * from './user-right'
diff --git a/server/middlewares/robots.ts b/server/middlewares/robots.ts
new file mode 100644
index 000000000..b22b24a9f
--- /dev/null
+++ b/server/middlewares/robots.ts
@@ -0,0 +1,13 @@
1import express from 'express'
2
3function disableRobots (req: express.Request, res: express.Response, next: express.NextFunction) {
4 res.setHeader('X-Robots-Tag', 'noindex')
5
6 return next()
7}
8
9// ---------------------------------------------------------------------------
10
11export {
12 disableRobots
13}
diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts
index 5e47211b5..96c8adc99 100644
--- a/server/middlewares/validators/oembed.ts
+++ b/server/middlewares/validators/oembed.ts
@@ -62,12 +62,26 @@ const oembedValidator = [
62 62
63 const url = req.query.url as string 63 const url = req.query.url as string
64 64
65 let urlPath: string
66
67 try {
68 urlPath = new URL(url).pathname
69 } catch (err) {
70 return res.fail({
71 status: HttpStatusCode.BAD_REQUEST_400,
72 message: err.message,
73 data: {
74 url
75 }
76 })
77 }
78
65 const isPlaylist = startPlaylistURLs.some(u => url.startsWith(u)) 79 const isPlaylist = startPlaylistURLs.some(u => url.startsWith(u))
66 const isVideo = isPlaylist ? false : startVideoURLs.some(u => url.startsWith(u)) 80 const isVideo = isPlaylist ? false : startVideoURLs.some(u => url.startsWith(u))
67 81
68 const startIsOk = isVideo || isPlaylist 82 const startIsOk = isVideo || isPlaylist
69 83
70 const matches = watchRegex.exec(url) 84 const matches = watchRegex.exec(urlPath)
71 85
72 if (startIsOk === false || matches === null) { 86 if (startIsOk === false || matches === null) {
73 return res.fail({ 87 return res.fail({