X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Ffeeds.ts;h=04b4e00c9c6a6b6f7b43346c433d0327a471843a;hb=9452d4fd3321148fb80b64a67bd9983fee6c208e;hp=aa16cc99378b2148eeaf4846f9d62e1c3d6df172;hpb=76148b27f7501bac061992136852be4303370c8d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts index aa16cc993..04b4e00c9 100644 --- a/server/middlewares/validators/feeds.ts +++ b/server/middlewares/validators/feeds.ts @@ -1,18 +1,19 @@ -import * as express from 'express' +import express from 'express' import { param, query } from 'express-validator' +import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' -import { exists, isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' +import { exists, isIdOrUUIDValid, isIdValid, toCompleteUUID } from '../../helpers/custom-validators/misc' import { logger } from '../../helpers/logger' import { + areValidationErrors, + checkCanSeeVideo, doesAccountIdExist, doesAccountNameWithHostExist, doesUserFeedTokenCorrespond, doesVideoChannelIdExist, - doesVideoChannelNameWithHostExist -} from '../../helpers/middlewares' -import { doesVideoExist } from '../../helpers/middlewares/videos' -import { areValidationErrors } from './utils' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' + doesVideoChannelNameWithHostExist, + doesVideoExist +} from './shared' const feedsFormatValidator = [ param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), @@ -98,7 +99,10 @@ const videoSubscriptionFeedsValidator = [ ] const videoCommentsFeedsValidator = [ - query('videoId').optional().custom(isIdOrUUIDValid), + query('videoId') + .customSanitizer(toCompleteUUID) + .optional() + .custom(isIdOrUUIDValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking feeds parameters', { parameters: req.query }) @@ -109,7 +113,10 @@ const videoCommentsFeedsValidator = [ return res.fail({ message: 'videoId cannot be mixed with a channel filter' }) } - if (req.query.videoId && !await doesVideoExist(req.query.videoId, res)) return + if (req.query.videoId) { + if (!await doesVideoExist(req.query.videoId, res)) return + if (!await checkCanSeeVideo({ req, res, paramId: req.query.videoId, video: res.locals.videoAll })) return + } return next() }