diff options
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/videos/video-imports.ts | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts index a3a5cc531..9c6d213c4 100644 --- a/server/middlewares/validators/videos/video-imports.ts +++ b/server/middlewares/validators/videos/video-imports.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { body, param } from 'express-validator' | 2 | import { body, param } from 'express-validator' |
3 | import { isValid as isIPValid, parse as parseIP } from 'ipaddr.js' | 3 | import { isResolvingToUnicastOnly } from '@server/helpers/dns' |
4 | import { isPreImportVideoAccepted } from '@server/lib/moderation' | 4 | import { isPreImportVideoAccepted } from '@server/lib/moderation' |
5 | import { Hooks } from '@server/lib/plugins/hooks' | 5 | import { Hooks } from '@server/lib/plugins/hooks' |
6 | import { MUserAccountId, MVideoImport } from '@server/types/models' | 6 | import { MUserAccountId, MVideoImport } from '@server/types/models' |
@@ -76,17 +76,13 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([ | |||
76 | if (req.body.targetUrl) { | 76 | if (req.body.targetUrl) { |
77 | const hostname = new URL(req.body.targetUrl).hostname | 77 | const hostname = new URL(req.body.targetUrl).hostname |
78 | 78 | ||
79 | if (isIPValid(hostname)) { | 79 | if (await isResolvingToUnicastOnly(hostname) !== true) { |
80 | const parsed = parseIP(hostname) | 80 | cleanUpReqFiles(req) |
81 | 81 | ||
82 | if (parsed.range() !== 'unicast') { | 82 | return res.fail({ |
83 | cleanUpReqFiles(req) | 83 | status: HttpStatusCode.FORBIDDEN_403, |
84 | 84 | message: 'Cannot use non unicast IP as targetUrl.' | |
85 | return res.fail({ | 85 | }) |
86 | status: HttpStatusCode.FORBIDDEN_403, | ||
87 | message: 'Cannot use non unicast IP as targetUrl.' | ||
88 | }) | ||
89 | } | ||
90 | } | 86 | } |
91 | } | 87 | } |
92 | 88 | ||