-import * as express from 'express'
+import express from 'express'
import { body } from 'express-validator'
import { isPreImportVideoAccepted } from '@server/lib/moderation'
import { Hooks } from '@server/lib/plugins/hooks'
import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
import { areValidationErrors, doesVideoChannelOfAccountExist } from '../shared'
import { getCommonVideoEditAttributes } from './videos'
+import { isValid as isIPValid, parse as parseIP } from 'ipaddr.js'
const videoImportAddValidator = getCommonVideoEditAttributes().concat([
body('channelId')
return res.fail({ message: 'Should have a magnetUri or a targetUrl or a torrent file.' })
}
+ if (req.body.targetUrl) {
+ const hostname = new URL(req.body.targetUrl).hostname
+
+ if (isIPValid(hostname)) {
+ const parsed = parseIP(hostname)
+
+ if (parsed.range() !== 'unicast') {
+ cleanUpReqFiles(req)
+
+ return res.fail({
+ status: HttpStatusCode.FORBIDDEN_403,
+ message: 'Cannot use non unicast IP as targetUrl.'
+ })
+ }
+ }
+ }
+
if (!await isImportAccepted(req, res)) return cleanUpReqFiles(req)
return next()