Don't log error on actor delete signature error

This commit is contained in:
Chocobozzz 2020-01-29 15:17:42 +01:00
parent 0bc1b31d60
commit 75ba887d10
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 18 additions and 11 deletions

View File

@ -14,7 +14,7 @@ import {
videosCustomGetValidator, videosCustomGetValidator,
videosShareValidator videosShareValidator
} from '../../middlewares' } from '../../middlewares'
import { getAccountVideoRateValidator, videoCommentGetValidator } from '../../middlewares/validators' import { getAccountVideoRateValidatorFactory, videoCommentGetValidator } from '../../middlewares/validators'
import { AccountModel } from '../../models/account/account' import { AccountModel } from '../../models/account/account'
import { ActorFollowModel } from '../../models/activitypub/actor-follow' import { ActorFollowModel } from '../../models/activitypub/actor-follow'
import { VideoModel } from '../../models/video/video' import { VideoModel } from '../../models/video/video'
@ -63,13 +63,13 @@ activityPubClientRouter.get('/accounts?/:name/playlists',
) )
activityPubClientRouter.get('/accounts?/:name/likes/:videoId', activityPubClientRouter.get('/accounts?/:name/likes/:videoId',
executeIfActivityPub, executeIfActivityPub,
asyncMiddleware(getAccountVideoRateValidator('like')), asyncMiddleware(getAccountVideoRateValidatorFactory('like')),
getAccountVideoRate('like') getAccountVideoRateFactory('like')
) )
activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId', activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId',
executeIfActivityPub, executeIfActivityPub,
asyncMiddleware(getAccountVideoRateValidator('dislike')), asyncMiddleware(getAccountVideoRateValidatorFactory('dislike')),
getAccountVideoRate('dislike') getAccountVideoRateFactory('dislike')
) )
activityPubClientRouter.get('/videos/watch/:id', activityPubClientRouter.get('/videos/watch/:id',
@ -192,7 +192,7 @@ async function accountPlaylistsController (req: express.Request, res: express.Re
return activityPubResponse(activityPubContextify(activityPubResult), res) return activityPubResponse(activityPubContextify(activityPubResult), res)
} }
function getAccountVideoRate (rateType: VideoRateType) { function getAccountVideoRateFactory (rateType: VideoRateType) {
return (req: express.Request, res: express.Response) => { return (req: express.Request, res: express.Response) => {
const accountVideoRate = res.locals.accountVideoRate const accountVideoRate = res.locals.accountVideoRate

View File

@ -50,7 +50,7 @@ const inboxQueue = queue<QueueParam, Error>((task, cb) => {
function inboxController (req: express.Request, res: express.Response) { function inboxController (req: express.Request, res: express.Response) {
const rootActivity: RootActivity = req.body const rootActivity: RootActivity = req.body
let activities: Activity[] = [] let activities: Activity[]
if ([ 'Collection', 'CollectionPage' ].indexOf(rootActivity.type) !== -1) { if ([ 'Collection', 'CollectionPage' ].indexOf(rootActivity.type) !== -1) {
activities = (rootActivity as ActivityPubCollection).items activities = (rootActivity as ActivityPubCollection).items

View File

@ -1,10 +1,11 @@
import { NextFunction, Request, Response } from 'express' import { NextFunction, Request, Response } from 'express'
import { ActivityPubSignature } from '../../shared' import { ActivityDelete, ActivityPubSignature } from '../../shared'
import { logger } from '../helpers/logger' import { logger } from '../helpers/logger'
import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto' import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto'
import { ACCEPT_HEADERS, ACTIVITY_PUB, HTTP_SIGNATURE } from '../initializers/constants' import { ACCEPT_HEADERS, ACTIVITY_PUB, HTTP_SIGNATURE } from '../initializers/constants'
import { getOrCreateActorAndServerAndModel } from '../lib/activitypub' import { getOrCreateActorAndServerAndModel } from '../lib/activitypub'
import { loadActorUrlOrGetFromWebfinger } from '../helpers/webfinger' import { loadActorUrlOrGetFromWebfinger } from '../helpers/webfinger'
import { isActorDeleteActivityValid } from '@server/helpers/custom-validators/activitypub/actor'
async function checkSignature (req: Request, res: Response, next: NextFunction) { async function checkSignature (req: Request, res: Response, next: NextFunction) {
try { try {
@ -23,7 +24,13 @@ async function checkSignature (req: Request, res: Response, next: NextFunction)
return next() return next()
} catch (err) { } catch (err) {
logger.warn('Error in ActivityPub signature checker.', err) const activity: ActivityDelete = req.body
if (isActorDeleteActivityValid(activity) && activity.object === activity.actor) {
logger.debug('Handling signature error on actor delete activity', { err })
return res.sendStatus(204)
}
logger.warn('Error in ActivityPub signature checker.', { err })
return res.sendStatus(403) return res.sendStatus(403)
} }
} }

View File

@ -24,7 +24,7 @@ const videoUpdateRateValidator = [
} }
] ]
const getAccountVideoRateValidator = function (rateType: VideoRateType) { const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) {
return [ return [
param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
@ -64,6 +64,6 @@ const videoRatingValidator = [
export { export {
videoUpdateRateValidator, videoUpdateRateValidator,
getAccountVideoRateValidator, getAccountVideoRateValidatorFactory,
videoRatingValidator videoRatingValidator
} }