Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Check on abuse report on server too

Chocobozzzaf0c8a47da7d
diff --git a/packages/tests/src/api/check-params/abuses.ts b/packages/tests/src/api/check-params/abuses.ts
index 5a53a2fbbf..4b6e09cfd4 100644
--- a/packages/tests/src/api/check-params/abuses.ts
+++ b/packages/tests/src/api/check-params/abuses.ts
@@ -281,6 +281,32 @@ describe('Test abuses API validators', function () {
await makePostBodyRequest({ url: server.url, path, token: userToken, fields, expectedStatus: HttpStatusCode.OK_200 })
})
+
+ it('Should fail to report a video the reporter owns', async function () {
+ const fields = { video: { id: server.store.videoCreated.id }, reason: 'my super reason' }
+
+ await makePostBodyRequest({
+ url: server.url,
+ path,
+ token: server.accessToken,
+ fields,
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
+ })
+
+ it('Should fail to report a video the reporter collaborates on', async function () {
+ const collaboratorToken = await server.channelCollaborators.createEditor('abuse_collaborator', 'root_channel')
+
+ const fields = { video: { id: server.store.videoCreated.id }, reason: 'my super reason' }
+
+ await makePostBodyRequest({
+ url: server.url,
+ path,
+ token: collaboratorToken,
+ fields,
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
+ })
})
describe('When updating an abuse', function () {
diff --git a/server/core/middlewares/validators/abuse.ts b/server/core/middlewares/validators/abuse.ts
index f43041c08b..3021000f85 100644
--- a/server/core/middlewares/validators/abuse.ts
+++ b/server/core/middlewares/validators/abuse.ts
@@ -17,6 +17,8 @@ import {
import { exists, isIdOrUUIDValid, isIdValid, toCompleteUUID, toIntOrNull } from '@server/helpers/custom-validators/misc.js'
import { createLogger } from '@server/helpers/logger.js'
import { AbuseMessageModel } from '@server/models/abuse/abuse-message.js'
+import { VideoChannelCollaboratorModel } from '@server/models/video/video-channel-collaborator.js'
+import { MUserAccountId, MVideoFull } from '@server/types/models/index.js'
import { areValidationErrors, doesAbuseExist, doesAccountIdExist, doesCommentIdExist, doesVideoExist } from './shared/index.js'
const logger = createLogger()
@@ -67,6 +69,8 @@ const abuseReportValidator = [
return
}
+ if (body.video?.id && !await checkUserCanReportVideo({ user: res.locals.oauth.token.User, video: res.locals.videoFull, req, res })) return
+
return next()
}
]
@@ -243,6 +247,33 @@ const deleteAbuseMessageValidator = [
// ---------------------------------------------------------------------------
+async function checkUserCanReportVideo (options: {
+ user: MUserAccountId
+ video: MVideoFull
+ req: express.Request
+ res: express.Response
+}) {
+ const { user, video, req, res } = options
+
+ const channel = video.VideoChannel
+
+ const isOwner = channel.Account.userId === user.id
+ const isCollaborator = !isOwner && await VideoChannelCollaboratorModel.isCollaborator({ user, channel })
+
+ if (isOwner || isCollaborator) {
+ res.fail({
+ status: HttpStatusCode.FORBIDDEN_403,
+ message: req.t('You cannot report a video you own or collaborate on.')
+ })
+
+ return false
+ }
+
+ return true
+}
+
+// ---------------------------------------------------------------------------
+
export {
abuseListForAdminsValidator,
abuseReportValidator,
diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml
index fb57f6ec44..16b775b439 100644
--- a/support/doc/api/openapi.yaml
+++ b/support/doc/api/openapi.yaml
@@ -4582,6 +4582,8 @@ paths:
$ref: '#/components/schemas/Abuse'
post:
summary: Report an abuse
+ description: >
+ You cannot report a video that you own or on which you are a collaborator (video channel editor).
security:
- OAuth2: []
tags:
@@ -4647,6 +4649,8 @@ paths:
$ref: '#/components/schemas/id'
'400':
description: incorrect request parameters
+ '403':
+ description: cannot report a video you own or that you collaborate on
'/api/v1/abuses/{abuseId}':
put: