Skip to content

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

More privacy checks

Chocobozzz5133552edd75
diff --git a/client/src/app/shared/shared-moderation/report-modals/video-report.component.ts b/client/src/app/shared/shared-moderation/report-modals/video-report.component.ts
index e226125cb6..d009d84ff1 100644
--- a/client/src/app/shared/shared-moderation/report-modals/video-report.component.ts
+++ b/client/src/app/shared/shared-moderation/report-modals/video-report.component.ts
@@ -101,7 +101,8 @@ export class VideoReportComponent extends FormReactive implements OnInit {
reason,
predefinedReasons,
video: {
- id: this.video().id,
+ // Use the UUID: it is required by the server to report unlisted and password protected videos
+ id: this.video().uuid,
startAt: hasStart && startAt ? startAt : undefined,
endAt: hasEnd && endAt ? endAt : undefined
}
diff --git a/client/src/app/shared/shared-video-miniature/video-miniature.component.ts b/client/src/app/shared/shared-video-miniature/video-miniature.component.ts
index b6382e3fdf..a49f766078 100644
--- a/client/src/app/shared/shared-video-miniature/video-miniature.component.ts
+++ b/client/src/app/shared/shared-video-miniature/video-miniature.component.ts
@@ -291,7 +291,7 @@ export class VideoMiniatureComponent implements OnInit {
}
addToWatchLater () {
- const body = { videoId: this.video().id }
+ const body = { video: this.video() }
this.videoPlaylistService.addVideoInPlaylist(this.watchLaterPlaylist.id, body)
.subscribe(
diff --git a/client/src/app/shared/shared-video-playlist/bulk-update-videos-in-playlist-modal.component.ts b/client/src/app/shared/shared-video-playlist/bulk-update-videos-in-playlist-modal.component.ts
index ea2c36715c..062fcf9033 100644
--- a/client/src/app/shared/shared-video-playlist/bulk-update-videos-in-playlist-modal.component.ts
+++ b/client/src/app/shared/shared-video-playlist/bulk-update-videos-in-playlist-modal.component.ts
@@ -4,7 +4,7 @@ import { AuthService, Notifier } from '@app/core'
import { formatICU } from '@app/helpers'
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal'
import { uniqify } from '@peertube/peertube-core-utils'
-import { Video, VideoPlaylistElementCreate, VideosExistInPlaylists } from '@peertube/peertube-models'
+import { Video, VideosExistInPlaylists } from '@peertube/peertube-models'
import debug from 'debug'
import { concat, Observable, of, Subject, Subscription } from 'rxjs'
import { catchError, debounceTime, map, switchMap } from 'rxjs/operators'
@@ -13,7 +13,7 @@ import { GlobalIconComponent } from '../shared-icons/global-icon.component'
import { ButtonComponent } from '../shared-main/buttons/button.component'
import { CollaboratorStateComponent } from '../shared-main/channel/collaborator-state.component'
import { PlaylistCreateBlockComponent } from './shared/playlist-create-block.component'
-import { CachedPlaylist, VideoPlaylistService } from './video-playlist.service'
+import { CachedPlaylist, PlaylistElementToAdd, VideoPlaylistService } from './video-playlist.service'
const debugLogger = debug('peertube:playlists:BulkUpdateVideosInPlaylistModalComponent')
@@ -216,9 +216,9 @@ export class BulkUpdateVideosInPlaylistModalComponent implements OnInit, OnDestr
private addVideosInPlaylist (playlist: CachedPlaylist) {
const existing = new Set(this.elementsPerPlaylist[playlist.id].map(e => e.videoId))
- const body: VideoPlaylistElementCreate[] = this.videos
+ const body: PlaylistElementToAdd[] = this.videos
.filter(v => !existing.has(v.id))
- .map(v => ({ videoId: v.id }))
+ .map(v => ({ video: v }))
return this.videoPlaylistService.addVideoInPlaylist(playlist.id, body)
.pipe(
diff --git a/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.ts b/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.ts
index 0419601565..4aa84d36e2 100644
--- a/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.ts
+++ b/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.ts
@@ -14,7 +14,7 @@ import {
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { AuthService, DisableForReuseHook, Notifier } from '@app/core'
import { secondsToTime } from '@peertube/peertube-core-utils'
-import { CachedVideoExistInPlaylist, Video, VideoChannelSummary, VideoPlaylistElementCreate } from '@peertube/peertube-models'
+import { CachedVideoExistInPlaylist, Video, VideoChannelSummary } from '@peertube/peertube-models'
import debug from 'debug'
import { Subject, Subscription } from 'rxjs'
import { debounceTime, filter } from 'rxjs/operators'
@@ -23,7 +23,7 @@ import { TimestampInputComponent } from '../shared-forms/timestamp-input.compone
import { GlobalIconComponent } from '../shared-icons/global-icon.component'
import { CollaboratorStateComponent } from '../shared-main/channel/collaborator-state.component'
import { PlaylistCreateBlockComponent } from './shared/playlist-create-block.component'
-import { CachedPlaylist, VideoPlaylistService } from './video-playlist.service'
+import { CachedPlaylist, PlaylistElementToAdd, VideoPlaylistService } from './video-playlist.service'
const debugLogger = debug('peertube:playlists:VideoAddToPlaylistComponent')
@@ -374,7 +374,7 @@ export class VideoAddToPlaylistComponent implements OnInit, OnChanges, OnDestroy
}
private addVideoInPlaylist (playlist: PlaylistSummary, element: PlaylistElement) {
- const body: VideoPlaylistElementCreate = { videoId: this.video().id }
+ const body: PlaylistElementToAdd = { video: this.video() }
if (element.startTimestamp) body.startTimestamp = element.startTimestamp
if (element.stopTimestamp && element.stopTimestamp !== this.video().duration) body.stopTimestamp = element.stopTimestamp
diff --git a/client/src/app/shared/shared-video-playlist/video-playlist.service.ts b/client/src/app/shared/shared-video-playlist/video-playlist.service.ts
index 7756ce6c4d..d0d107818c 100644
--- a/client/src/app/shared/shared-video-playlist/video-playlist.service.ts
+++ b/client/src/app/shared/shared-video-playlist/video-playlist.service.ts
@@ -8,6 +8,7 @@ import {
CachedVideoExistInPlaylist,
CachedVideosExistInPlaylists,
ResultList,
+ Video,
VideoPlaylistElement as ServerVideoPlaylistElement,
VideoChannelSummary,
VideoExistInPlaylist,
@@ -35,6 +36,10 @@ const debugLogger = debug('peertube:playlists:VideoPlaylistService')
export type CachedPlaylist = VideoPlaylist | { id: number, displayName: string, videoChannel?: VideoChannelSummary }
+export type PlaylistElementToAdd = Omit<VideoPlaylistElementCreate, 'videoId'> & {
+ video: Pick<Video, 'id' | 'uuid'>
+}
+
@Injectable({ providedIn: 'root' })
export class VideoPlaylistService {
private authHttp = inject(HttpClient)
@@ -227,14 +232,20 @@ export class VideoPlaylistService {
// ---------------------------------------------------------------------------
- addVideoInPlaylist (playlistId: number, bodyArg: VideoPlaylistElementCreate | VideoPlaylistElementCreate[]) {
+ addVideoInPlaylist (playlistId: number, elementsArg: PlaylistElementToAdd | PlaylistElementToAdd[]) {
const url = VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + playlistId + '/videos'
- return from(arrayify(bodyArg))
+ return from(arrayify(elementsArg))
.pipe(
- concatMap(body => this.authHttp.post<{ videoPlaylistElement: { id: number } }>(url, body).pipe(map(res => ({ res, body })))),
- tap(({ res, body }) => {
- const existsResult = this.videoExistsCache[body.videoId]
+ concatMap(({ video, ...attributes }) => {
+ // Use the UUID: the server refuses the numeric id of an unlisted video we don't own
+ const body: VideoPlaylistElementCreate = { ...attributes, videoId: video.uuid }
+
+ return this.authHttp.post<{ videoPlaylistElement: { id: number } }>(url, body)
+ .pipe(map(res => ({ res, videoId: video.id, body })))
+ }),
+ tap(({ res, videoId, body }) => {
+ const existsResult = this.videoExistsCache[videoId]
if (existsResult) {
existsResult.push({
@@ -245,7 +256,7 @@ export class VideoPlaylistService {
})
}
- this.runVideoExistsInPlaylistCheck(body.videoId)
+ this.runVideoExistsInPlaylistCheck(videoId)
if (this.myAccountPlaylistCache) {
const playlist = this.myAccountPlaylistCache.data.find(p => p.id === playlistId)
diff --git a/client/src/standalone/videos/shared/video-fetcher.ts b/client/src/standalone/videos/shared/video-fetcher.ts
index 99e3156a33..a3af245e90 100644
--- a/client/src/standalone/videos/shared/video-fetcher.ts
+++ b/client/src/standalone/videos/shared/video-fetcher.ts
@@ -63,7 +63,8 @@ export class VideoFetcher {
const params = new URLSearchParams()
params.append('domain', new URL(document.referrer).host)
- return this.http.fetch(this.getVideoUrl(video.uuid) + '/embed-privacy/allowed?' + params.toString(), { optionalAuth: false })
+ // Send auth so the owner can embed their private/internal video
+ return this.http.fetch(this.getVideoUrl(video.uuid) + '/embed-privacy/allowed?' + params.toString(), { optionalAuth: true })
.then(res => res.json() as Promise<VideoEmbedPrivacyAllowed>)
.then(({ domainAllowed }) => domainAllowed)
}
diff --git a/packages/models/src/videos/playlist/video-playlist-element-create.model.ts b/packages/models/src/videos/playlist/video-playlist-element-create.model.ts
index c31702892e..80079cc8bc 100644
--- a/packages/models/src/videos/playlist/video-playlist-element-create.model.ts
+++ b/packages/models/src/videos/playlist/video-playlist-element-create.model.ts
@@ -1,5 +1,5 @@
export interface VideoPlaylistElementCreate {
- videoId: number
+ videoId: number | string
startTimestamp?: number
stopTimestamp?: number
diff --git a/packages/server-commands/src/moderation/abuses-command.ts b/packages/server-commands/src/moderation/abuses-command.ts
index e267709e24..604708a4f3 100644
--- a/packages/server-commands/src/moderation/abuses-command.ts
+++ b/packages/server-commands/src/moderation/abuses-command.ts
@@ -20,7 +20,7 @@ export class AbusesCommand extends AbstractCommand {
reason: string
accountId?: number
- videoId?: number
+ videoId?: number | string
commentId?: number
predefinedReasons?: AbusePredefinedReasonsString[]
diff --git a/packages/tests/src/api/activitypub/cleaner.ts b/packages/tests/src/api/activitypub/cleaner.ts
index 534d0c30f2..b59e69b9e2 100644
--- a/packages/tests/src/api/activitypub/cleaner.ts
+++ b/packages/tests/src/api/activitypub/cleaner.ts
@@ -3,10 +3,12 @@
import { expect } from 'chai'
import { SQLCommand } from '@tests/shared/sql-command.js'
import { wait } from '@peertube/peertube-core-utils'
+import { HttpStatusCode, VideoPrivacy } from '@peertube/peertube-models'
import {
cleanupTests,
createMultipleServers,
doubleFollow,
+ makeActivityPubGetRequest,
PeerTubeServer,
setAccessTokensToServers,
waitJobs
@@ -272,6 +274,37 @@ describe('Test AP cleaner', function () {
await checkRemote('kyle')
})
+ it('Should not clean rates of remote unlisted videos', async function () {
+ this.timeout(120000)
+
+ // Server 3 does not federate its own unlisted videos, but still receives remote unlisted videos
+ await servers[2].kill()
+ await servers[2].run({ federation: { videos: { federate_unlisted: false, cleanup_remote_interactions: true } } })
+
+ const remoteUnlisted = await servers[0].videos.quickUpload({ name: 'server 1 unlisted', privacy: VideoPrivacy.UNLISTED })
+ const localUnlisted = await servers[2].videos.quickUpload({ name: 'server 3 unlisted', privacy: VideoPrivacy.UNLISTED })
+ await waitJobs(servers)
+
+ await servers[2].videos.rate({ id: remoteUnlisted.uuid, rating: 'like' })
+ await servers[2].videos.rate({ id: localUnlisted.uuid, rating: 'like' })
+ await waitJobs(servers)
+
+ // The origin of the remote unlisted video fetches the rate in its cleaner
+ {
+ const { id } = await servers[2].videos.get({ id: remoteUnlisted.uuid })
+ await makeActivityPubGetRequest(servers[2].url, '/accounts/root/likes/' + id, HttpStatusCode.OK_200)
+ }
+
+ // Nobody needs the rate of a local unlisted video: don't leak its URL
+ await makeActivityPubGetRequest(servers[2].url, '/accounts/root/likes/' + localUnlisted.id, HttpStatusCode.NOT_FOUND_404)
+
+ await wait(5000)
+ await waitJobs(servers)
+
+ const video = await servers[0].videos.get({ id: remoteUnlisted.uuid })
+ expect(video.likes).to.equal(1)
+ })
+
it('Should remove unavailable remote resources', async function () {
this.timeout(240000)
diff --git a/packages/tests/src/api/activitypub/client.ts b/packages/tests/src/api/activitypub/client.ts
index 0972f70c74..6c9bca7065 100644
--- a/packages/tests/src/api/activitypub/client.ts
+++ b/packages/tests/src/api/activitypub/client.ts
@@ -32,10 +32,13 @@ describe('Test ActivityPub', function () {
let video: VideoCreateResult
let privateVideo: VideoCreateResult
+ let unlistedVideo: VideoCreateResult
let playlist: VideoPlaylistCreateResult
let privatePlaylist: VideoPlaylistCreateResult
+ let unlistedPlaylist: VideoPlaylistCreateResult
let privateVideoPlaylistElementId: number
+ let unlistedPlaylistElementId: number
let comment: VideoComment
@@ -147,6 +150,7 @@ describe('Test ActivityPub', function () {
{
video = await servers[0].videos.quickUpload({ name: 'video' })
privateVideo = await servers[0].videos.quickUpload({ name: 'private video', privacy: VideoPrivacy.PRIVATE })
+ unlistedVideo = await servers[0].videos.quickUpload({ name: 'unlisted video', privacy: VideoPrivacy.UNLISTED })
}
{
@@ -172,6 +176,22 @@ describe('Test ActivityPub', function () {
privateVideoPlaylistElementId = id
}
+ {
+ unlistedPlaylist = await servers[0].playlists.create({
+ attributes: {
+ displayName: 'unlisted playlist',
+ privacy: VideoPlaylistPrivacy.UNLISTED,
+ videoChannelId: servers[0].store.channel.id
+ }
+ })
+
+ const { id } = await servers[0].playlists.addElement({
+ playlistId: unlistedPlaylist.uuid,
+ attributes: { videoId: video.uuid }
+ })
+ unlistedPlaylistElementId = id
+ }
+
comment = await servers[0].comments.createThread({ text: 'thread', videoId: video.id })
await doubleFollow(servers[0], servers[1])
@@ -229,13 +249,13 @@ describe('Test ActivityPub', function () {
expect(res.header.location).to.equal(servers[0].url + '/videos/watch/' + video.uuid)
})
- it('Should return the watch action', async function () {
+ it('Should return the watch action of a remote video', async function () {
this.timeout(50000)
- await servers[0].views.simulateViewer({ id: video.uuid, currentTimes: [ 0, 2 ] })
+ await servers[1].views.simulateViewer({ id: video.uuid, currentTimes: [ 0, 2 ] })
await processViewersStats(servers)
- const res = await makeActivityPubGetRequest(servers[0].url, '/videos/local-viewer/1', HttpStatusCode.OK_200)
+ const res = await makeActivityPubGetRequest(servers[1].url, '/videos/local-viewer/1', HttpStatusCode.OK_200)
const object: WatchActionObject = res.body
expect(object.type).to.equal('WatchAction')
@@ -246,6 +266,30 @@ describe('Test ActivityPub', function () {
expect(object.watchSections[0].endTimestamp).to.equal(2)
})
+ it('Should not return the watch action of a local video', async function () {
+ this.timeout(50000)
+
+ // Stats of a local viewer
+ await servers[0].views.simulateViewer({ id: privateVideo.uuid, token: servers[0].accessToken, currentTimes: [ 0, 2 ] })
+ await processViewersStats(servers)
+
+ // servers[0] has stats received from servers[1] and stats of its local viewer
+ for (const id of [ 1, 2 ]) {
+ await makeActivityPubGetRequest(servers[0].url, '/videos/local-viewer/' + id, HttpStatusCode.NOT_FOUND_404)
+ }
+ })
+
+ it('Should only return rates of public videos', async function () {
+ for (const id of [ video.id, privateVideo.id, unlistedVideo.id ]) {
+ await servers[0].videos.rate({ id, rating: 'like' })
+ }
+
+ await makeActivityPubGetRequest(servers[0].url, '/accounts/root/likes/' + video.id, HttpStatusCode.OK_200)
+
+ await makeActivityPubGetRequest(servers[0].url, '/accounts/root/likes/' + privateVideo.id, HttpStatusCode.NOT_FOUND_404)
+ await makeActivityPubGetRequest(servers[0].url, '/accounts/root/likes/' + unlistedVideo.id, HttpStatusCode.NOT_FOUND_404)
+ })
+
it('Should not return private video or private playlist', async function () {
await makeActivityPubGetRequest(servers[0].url, '/videos/watch/' + privateVideo.uuid, HttpStatusCode.UNAUTHORIZED_401)
await makeActivityPubGetRequest(servers[0].url, '/video-playlists/' + privatePlaylist.uuid, HttpStatusCode.UNAUTHORIZED_401)
@@ -260,6 +304,17 @@ describe('Test ActivityPub', function () {
expect(object.url).to.be.null
})
+ it('Should only return an unlisted playlist element using the playlist UUID', async function () {
+ const suffix = '/videos/' + unlistedPlaylistElementId
+
+ await makeActivityPubGetRequest(servers[0].url, '/video-playlists/' + unlistedPlaylist.id + suffix, HttpStatusCode.NOT_FOUND_404)
+
+ const res = await makeActivityPubGetRequest(servers[0].url, '/video-playlists/' + unlistedPlaylist.uuid + suffix)
+ const object: PlaylistElementObject = res.body
+
+ expect(object.url).to.equal(servers[0].url + '/videos/watch/' + video.uuid)
+ })
+
after(async function () {
await cleanupTests(servers)
})
diff --git a/packages/tests/src/api/check-params/abuses.ts b/packages/tests/src/api/check-params/abuses.ts
index 4b6e09cfd4..c617ec5f41 100644
--- a/packages/tests/src/api/check-params/abuses.ts
+++ b/packages/tests/src/api/check-params/abuses.ts
@@ -1,7 +1,7 @@
/* oxlint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import { checkBadCountPagination, checkBadSort, checkBadStartPagination } from '@tests/shared/checks.js'
-import { AbuseCreate, AbuseState, HttpStatusCode } from '@peertube/peertube-models'
+import { AbuseCreate, AbuseState, HttpStatusCode, VideoPrivacy } from '@peertube/peertube-models'
import {
AbusesCommand,
cleanupTests,
@@ -294,6 +294,38 @@ describe('Test abuses API validators', function () {
})
})
+ it('Should fail to report a video the reporter cannot see', async function () {
+ const privateVideo = await server.videos.quickUpload({ name: 'private', privacy: VideoPrivacy.PRIVATE })
+ const blacklistedVideo = await server.videos.quickUpload({ name: 'blacklisted', privacy: VideoPrivacy.PUBLIC })
+ await server.blacklist.add({ videoId: blacklistedVideo.uuid })
+
+ for (const videoId of [ privateVideo.id, privateVideo.uuid, blacklistedVideo.id, blacklistedVideo.uuid ]) {
+ await command.report({ videoId, reason: 'my super reason', token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
+ }
+ })
+
+ it('Should fail to report an unlisted or password protected video using its numeric id', async function () {
+ const unlistedVideo = await server.videos.quickUpload({ name: 'unlisted', privacy: VideoPrivacy.UNLISTED })
+ const passwordProtectedVideo = await server.videos.quickUpload({
+ name: 'password protected',
+ privacy: VideoPrivacy.PASSWORD_PROTECTED,
+ videoPasswords: [ 'password' ]
+ })
+
+ for (const video of [ unlistedVideo, passwordProtectedVideo ]) {
+ await command.report({
+ videoId: video.id,
+ reason: 'my super reason',
+ token: userToken,
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
+
+ for (const videoId of [ video.uuid, video.shortUUID ]) {
+ await command.report({ videoId, reason: 'my super reason', token: userToken })
+ }
+ }
+ })
+
it('Should fail to report a video the reporter collaborates on', async function () {
const collaboratorToken = await server.channelCollaborators.createEditor('abuse_collaborator', 'root_channel')
diff --git a/packages/tests/src/api/check-params/channels.ts b/packages/tests/src/api/check-params/channels.ts
index d2b8e69028..db75426796 100644
--- a/packages/tests/src/api/check-params/channels.ts
+++ b/packages/tests/src/api/check-params/channels.ts
@@ -128,6 +128,33 @@ describe('Test video channels API validator', function () {
})
})
+ it('Should fail to list collaborations without being authenticated', async function () {
+ await server.channels.listByAccount({
+ accountName: 'fake',
+ includeCollaborations: true,
+ token: null,
+ expectedStatus: HttpStatusCode.UNAUTHORIZED_401
+ })
+ })
+
+ it('Should fail to list collaborations of another account', async function () {
+ await server.channels.listByAccount({
+ accountName: 'root',
+ includeCollaborations: true,
+ token: userInfo.accessToken,
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
+ })
+
+ it('Should succeed to list collaborations of its own account', async function () {
+ await server.channels.listByAccount({
+ accountName: 'fake',
+ includeCollaborations: true,
+ token: userInfo.accessToken,
+ expectedStatus: HttpStatusCode.OK_200
+ })
+ })
+
it('Should fail with an invalid statsDays value', async function () {
await server.channels.listByAccount({
accountName: 'fake',
diff --git a/packages/tests/src/api/check-params/services.ts b/packages/tests/src/api/check-params/services.ts
index eb43be7a89..00d0fd0c47 100644
--- a/packages/tests/src/api/check-params/services.ts
+++ b/packages/tests/src/api/check-params/services.ts
@@ -23,6 +23,8 @@ describe('Test services API validators', function () {
let privateVideo: VideoCreateResult
let unlistedVideo: VideoCreateResult
+ let blacklistedPublicVideo: VideoCreateResult
+ let blacklistedPrivateVideo: VideoCreateResult
let privatePlaylist: VideoPlaylistCreateResult
let unlistedPlaylist: VideoPlaylistCreateResult
@@ -41,6 +43,13 @@ describe('Test services API validators', function () {
privateVideo = await server.videos.quickUpload({ name: 'private', privacy: VideoPrivacy.PRIVATE })
unlistedVideo = await server.videos.quickUpload({ name: 'unlisted', privacy: VideoPrivacy.UNLISTED })
+ blacklistedPublicVideo = await server.videos.quickUpload({ name: 'blacklisted public', privacy: VideoPrivacy.PUBLIC })
+ blacklistedPrivateVideo = await server.videos.quickUpload({ name: 'blacklisted private', privacy: VideoPrivacy.PRIVATE })
+
+ for (const video of [ blacklistedPublicVideo, blacklistedPrivateVideo ]) {
+ await server.blacklist.add({ videoId: video.uuid })
+ }
+
{
const created = await server.playlists.create({
attributes: {
@@ -141,6 +150,16 @@ describe('Test services API validators', function () {
}
})
+ it('Should fail with a blacklisted video', async function () {
+ for (const video of [ blacklistedPublicVideo, blacklistedPrivateVideo ]) {
+ for (const id of [ video.id, video.uuid ]) {
+ const embedUrl = `${server.url}/videos/watch/${id}`
+
+ await checkParamEmbed(server, embedUrl, HttpStatusCode.FORBIDDEN_403)
+ }
+ }
+ })
+
it('Should fail with a private playlist', async function () {
const embedUrl = `${server.url}/videos/watch/playlist/${privatePlaylist.uuid}`
diff --git a/packages/tests/src/api/check-params/video-blacklist.ts b/packages/tests/src/api/check-params/video-blacklist.ts
index e40d259ce1..1c44aee242 100644
--- a/packages/tests/src/api/check-params/video-blacklist.ts
+++ b/packages/tests/src/api/check-params/video-blacklist.ts
@@ -1,6 +1,6 @@
/* oxlint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
-import { HttpStatusCode, VideoBlacklistType } from '@peertube/peertube-models'
+import { HttpStatusCode, VideoBlacklistType, VideoPrivacy } from '@peertube/peertube-models'
import {
BlacklistCommand,
cleanupTests,
@@ -292,6 +292,19 @@ describe('Test video blacklist API validators', function () {
})
})
+ describe('When getting a blacklisted video', function () {
+ it('Should not be able to get a blacklisted internal video of another user', async function () {
+ const { uuid } = await servers[0].videos.quickUpload({ name: 'internal', privacy: VideoPrivacy.INTERNAL, token: userToken })
+ await command.add({ videoId: uuid })
+
+ await servers[0].videos.get({ id: uuid, token: anotherUserToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
+
+ for (const token of [ userToken, servers[0].accessToken ]) {
+ await servers[0].videos.get({ id: uuid, token })
+ }
+ })
+ })
+
after(async function () {
await cleanupTests(servers)
})
diff --git a/packages/tests/src/api/check-params/video-embed-privacy.ts b/packages/tests/src/api/check-params/video-embed-privacy.ts
index 604b458fc4..bdfe32dcb0 100644
--- a/packages/tests/src/api/check-params/video-embed-privacy.ts
+++ b/packages/tests/src/api/check-params/video-embed-privacy.ts
@@ -1,4 +1,4 @@
-import { HttpStatusCode, VideoCreateResult, VideoEmbedPrivacyPolicy } from '@peertube/peertube-models'
+import { HttpStatusCode, VideoCreateResult, VideoEmbedPrivacyPolicy, VideoPrivacy } from '@peertube/peertube-models'
import {
PeerTubeServer,
cleanupTests,
@@ -10,6 +10,9 @@ import {
describe('Test video embed privacy validator', function () {
let server: PeerTubeServer
let video: VideoCreateResult
+ let privateVideo: VideoCreateResult
+ let unlistedVideo: VideoCreateResult
+ let passwordProtectedVideo: VideoCreateResult
let ownerAccessToken: string
let userAccessToken: string
@@ -32,6 +35,15 @@ describe('Test video embed privacy validator', function () {
invitedEditorAccessToken = await server.channelCollaborators.createInvited('invited_editor', 'owner_channel')
video = await server.videos.upload({ token: ownerAccessToken })
+
+ privateVideo = await server.videos.quickUpload({ name: 'private', privacy: VideoPrivacy.PRIVATE, token: ownerAccessToken })
+ unlistedVideo = await server.videos.quickUpload({ name: 'unlisted', privacy: VideoPrivacy.UNLISTED, token: ownerAccessToken })
+ passwordProtectedVideo = await server.videos.quickUpload({
+ name: 'password protected',
+ privacy: VideoPrivacy.PASSWORD_PROTECTED,
+ videoPasswords: [ 'password' ],
+ token: ownerAccessToken
+ })
})
describe('When getting embed privacy', function () {
@@ -110,8 +122,47 @@ describe('Test video embed privacy validator', function () {
})
})
+ it('Should fail with a private video without the appropriate rights', async function () {
+ await server.videoEmbedPrivacy.isDomainAllowed({
+ videoId: privateVideo.uuid,
+ domain: 'example.com',
+ token: null,
+ expectedStatus: HttpStatusCode.UNAUTHORIZED_401
+ })
+
+ await server.videoEmbedPrivacy.isDomainAllowed({
+ videoId: privateVideo.uuid,
+ domain: 'example.com',
+ token: userAccessToken,
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
+ })
+
+ it('Should fail with an unlisted video using its numeric id', async function () {
+ await server.videoEmbedPrivacy.isDomainAllowed({
+ videoId: unlistedVideo.id,
+ domain: 'example.com',
+ token: null,
+ expectedStatus: HttpStatusCode.UNAUTHORIZED_401
+ })
+
+ await server.videoEmbedPrivacy.isDomainAllowed({
+ videoId: unlistedVideo.id,
+ domain: 'example.com',
+ token: userAccessToken,
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
+ })
+
it('Should succeed with correct params', async function () {
await server.videoEmbedPrivacy.isDomainAllowed({ videoId: video.id, domain: 'example.com' })
+
+ for (const token of [ null, userAccessToken ]) {
+ await server.videoEmbedPrivacy.isDomainAllowed({ videoId: unlistedVideo.uuid, domain: 'example.com', token })
+ await server.videoEmbedPrivacy.isDomainAllowed({ videoId: passwordProtectedVideo.uuid, domain: 'example.com', token })
+ }
+
+ await server.videoEmbedPrivacy.isDomainAllowed({ videoId: privateVideo.uuid, domain: 'example.com', token: ownerAccessToken })
})
})
diff --git a/packages/tests/src/api/search/search-activitypub-video-channels.ts b/packages/tests/src/api/search/search-activitypub-video-channels.ts
index 1b7d446318..2ff4fd1bc1 100644
--- a/packages/tests/src/api/search/search-activitypub-video-channels.ts
+++ b/packages/tests/src/api/search/search-activitypub-video-channels.ts
@@ -90,14 +90,17 @@ describe('Test ActivityPub video channels search', function () {
'channel1_server1@' + servers[0].host
]
- for (const search of searches) {
- const body = await command.searchChannels({ search, token: servers[0].accessToken })
+ // Local handles are resolved from the database, so anonymous users can search them too
+ for (const token of [ undefined, servers[0].accessToken ]) {
+ for (const search of searches) {
+ const body = await command.searchChannels({ search, token })
- expect(body.total).to.equal(1)
- expect(body.data).to.be.an('array')
- expect(body.data).to.have.lengthOf(1)
- expect(body.data[0].name).to.equal('channel1_server1')
- expect(body.data[0].displayName).to.equal('Channel 1 server 1')
+ expect(body.total).to.equal(1)
+ expect(body.data).to.be.an('array')
+ expect(body.data).to.have.lengthOf(1)
+ expect(body.data[0].name).to.equal('channel1_server1')
+ expect(body.data[0].displayName).to.equal('Channel 1 server 1')
+ }
}
})
diff --git a/packages/tests/src/client/embed-html.ts b/packages/tests/src/client/embed-html.ts
index 8bdee9db75..9e13838e03 100644
--- a/packages/tests/src/client/embed-html.ts
+++ b/packages/tests/src/client/embed-html.ts
@@ -15,11 +15,13 @@ describe('Test embed HTML generation', function () {
let privateVideoId: string
let internalVideoId: string
let unlistedVideoId: string
+ let unlistedVideoNumericId: number
let passwordProtectedVideoId: string
let playlistIds: (string | number)[] = []
let privatePlaylistId: string
let unlistedPlaylistId: string
+ let unlistedPlaylistNumericId: number
let playlistName: string
let playlistDescription: string
@@ -34,6 +36,7 @@ describe('Test embed HTML generation', function () {
internalVideoId,
passwordProtectedVideoId,
unlistedVideoId,
+ unlistedVideoNumericId,
videoName,
videoDescriptionPlainText,
@@ -41,6 +44,7 @@ describe('Test embed HTML generation', function () {
playlistName,
playlistDescription,
unlistedPlaylistId,
+ unlistedPlaylistNumericId,
privatePlaylistId,
instanceConfig
} = await prepareClientTests())
@@ -173,6 +177,22 @@ describe('Test embed HTML generation', function () {
expect(res.text).to.not.contain('private')
expect(res.text).to.contain('<meta name="robots" content="noindex" />')
})
+
+ it('Should not leak unlisted video and playlist information in embed using their numeric id', async function () {
+ {
+ const res = await makeHTMLRequest(servers[0].url, '/videos/embed/' + unlistedVideoNumericId)
+
+ expect(res.text).to.not.contain(unlistedVideoId)
+ expect(res.text).to.contain('<meta name="robots" content="noindex" />')
+ }
+
+ {
+ const res = await makeHTMLRequest(servers[0].url, '/video-playlists/embed/' + unlistedPlaylistNumericId)
+
+ expect(res.text).to.not.contain(unlistedPlaylistId)
+ expect(res.text).to.contain('<meta name="robots" content="noindex" />')
+ }
+ })
})
after(async function () {
diff --git a/packages/tests/src/client/index-html.ts b/packages/tests/src/client/index-html.ts
index 6c7da19058..d9744a92dd 100644
--- a/packages/tests/src/client/index-html.ts
+++ b/packages/tests/src/client/index-html.ts
@@ -12,6 +12,7 @@ describe('Test index HTML generation', function () {
let privateVideoId: string
let internalVideoId: string
let unlistedVideoId: string
+ let unlistedVideoNumericId: number
let passwordProtectedVideoId: string
let playlist: VideoPlaylistCreateResult
@@ -19,6 +20,7 @@ describe('Test index HTML generation', function () {
let playlistIds: (string | number)[] = []
let privatePlaylistId: string
let unlistedPlaylistId: string
+ let unlistedPlaylistNumericId: number
let instanceConfig: {
name: string
@@ -36,8 +38,10 @@ describe('Test index HTML generation', function () {
internalVideoId,
passwordProtectedVideoId,
unlistedVideoId,
+ unlistedVideoNumericId,
privatePlaylistId,
unlistedPlaylistId,
+ unlistedPlaylistNumericId,
instanceConfig
} = await prepareClientTests())
})
@@ -265,6 +269,34 @@ describe('Test index HTML generation', function () {
}
})
+ it('Should not display unlisted video using its numeric id', async function () {
+ for (const basePath of getWatchVideoBasePaths()) {
+ const res = await makeGetRequest({
+ url: servers[0].url,
+ path: basePath + unlistedVideoNumericId,
+ accept: 'text/html',
+ expectedStatus: HttpStatusCode.NOT_FOUND_404
+ })
+
+ expect(res.text).to.not.contain(unlistedVideoId)
+ expect(res.text).to.not.contain('<meta property="og:title" content="unlisted" />')
+ }
+ })
+
+ it('Should not display unlisted video playlist using its numeric id', async function () {
+ for (const basePath of getWatchPlaylistBasePaths()) {
+ const res = await makeGetRequest({
+ url: servers[0].url,
+ path: basePath + unlistedPlaylistNumericId,
+ accept: 'text/html',
+ expectedStatus: HttpStatusCode.NOT_FOUND_404
+ })
+
+ expect(res.text).to.not.contain(unlistedPlaylistId)
+ expect(res.text).to.not.contain('<meta property="og:title" content="unlisted" />')
+ }
+ })
+
it('Should not display private video playlist', async function () {
for (const basePath of getWatchPlaylistBasePaths()) {
const res = await makeGetRequest({
diff --git a/packages/tests/src/external-plugins/auth-ldap.ts b/packages/tests/src/external-plugins/auth-ldap.ts
index ae6e9e9381..d7678ac3f9 100644
--- a/packages/tests/src/external-plugins/auth-ldap.ts
+++ b/packages/tests/src/external-plugins/auth-ldap.ts
@@ -95,11 +95,11 @@ describe('Official plugin auth-ldap', function () {
})
it('Should not be able to ask password reset', async function () {
- await server.users.askResetPassword({ email: '[email protected]', expectedStatus: HttpStatusCode.CONFLICT_409 })
+ await server.users.askResetPassword({ email: '[email protected]' })
})
it('Should not be able to ask email verification', async function () {
- await server.users.askSendVerifyEmail({ email: '[email protected]', expectedStatus: HttpStatusCode.CONFLICT_409 })
+ await server.users.askSendVerifyEmail({ email: '[email protected]' })
})
it('Should set the correct roles', async function () {
diff --git a/packages/tests/src/shared/client.ts b/packages/tests/src/shared/client.ts
index f79299d298..b116123759 100644
--- a/packages/tests/src/shared/client.ts
+++ b/packages/tests/src/shared/client.ts
@@ -72,11 +72,13 @@ export async function prepareClientTests () {
let privateVideoId: string
let internalVideoId: string
let unlistedVideoId: string
+ let unlistedVideoNumericId: number
let passwordProtectedVideoId: string
let playlistIds: (string | number)[] = []
let privatePlaylistId: string
let unlistedPlaylistId: string
+ let unlistedPlaylistNumericId: number
const videoName = 'my super name for server 1'
const videoDescription = 'my<br> super __description__ for *server* 1<p></p>'
@@ -111,7 +113,10 @@ export async function prepareClientTests () {
{
;({ uuid: privateVideoId } = await servers[0].videos.quickUpload({ name: 'private', privacy: VideoPrivacy.PRIVATE }))
- ;({ uuid: unlistedVideoId } = await servers[0].videos.quickUpload({ name: 'unlisted', privacy: VideoPrivacy.UNLISTED }))
+ ;({ uuid: unlistedVideoId, id: unlistedVideoNumericId } = await servers[0].videos.quickUpload({
+ name: 'unlisted',
+ privacy: VideoPrivacy.UNLISTED
+ }))
;({ uuid: internalVideoId } = await servers[0].videos.quickUpload({ name: 'internal', privacy: VideoPrivacy.INTERNAL }))
;({ uuid: passwordProtectedVideoId } = await servers[0].videos.quickUpload({
name: 'password protected',
@@ -145,8 +150,9 @@ export async function prepareClientTests () {
videoChannelId: servers[0].store.channel.id
}
- const { uuid } = await servers[0].playlists.create({ attributes })
+ const { uuid, id } = await servers[0].playlists.create({ attributes })
unlistedPlaylistId = uuid
+ unlistedPlaylistNumericId = id
}
{
@@ -185,9 +191,11 @@ export async function prepareClientTests () {
privatePlaylistId,
unlistedPlaylistId,
+ unlistedPlaylistNumericId,
privateVideoId,
unlistedVideoId,
+ unlistedVideoNumericId,
internalVideoId,
passwordProtectedVideoId,
diff --git a/server/core/controllers/api/search/search-video-channels.ts b/server/core/controllers/api/search/search-video-channels.ts
index 961be6237c..428c064713 100644
--- a/server/core/controllers/api/search/search-video-channels.ts
+++ b/server/core/controllers/api/search/search-video-channels.ts
@@ -12,7 +12,7 @@ import { HttpStatusCode, ResultList, VideoChannel, VideoChannelsSearchQueryAfter
import { isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils.js'
import { createLogger } from '../../../helpers/logger.js'
import { getFormattedObjects } from '../../../helpers/utils.js'
-import { getOrCreateAPActor, loadActorUrlOrGetFromWebfinger } from '../../../lib/activitypub/actors/index.js'
+import { getOrCreateAPActor, loadActorUrlFromDB, loadActorUrlOrGetFromWebfinger } from '../../../lib/activitypub/actors/index.js'
import {
asyncMiddleware,
openapiOperationDoc,
@@ -120,16 +120,16 @@ async function searchVideoChannelURI (search: string, res: express.Response) {
const canSearchRemoteURI = isUserAbleToSearchRemoteURI(res)
if (!isURISearch(search)) {
- // Resolving a "name@host" handle requires an outbound webfinger lookup
- if (!canSearchRemoteURI) return res.json({ total: 0, data: [] })
-
try {
- uri = await loadActorUrlOrGetFromWebfinger(search)
+ // Only users able to search remote URIs can trigger an outbound webfinger lookup
+ uri = canSearchRemoteURI
+ ? await loadActorUrlOrGetFromWebfinger(search)
+ : await loadActorUrlFromDB(search)
} catch (err) {
logger.warn('Cannot load actor URL or get from webfinger.', { search, err })
-
- return res.json({ total: 0, data: [] })
}
+
+ if (!uri) return res.json({ total: 0, data: [] })
}
if (canSearchRemoteURI) {
diff --git a/server/core/controllers/api/video-playlist.ts b/server/core/controllers/api/video-playlist.ts
index 5da3d4b3a9..d9663881ac 100644
--- a/server/core/controllers/api/video-playlist.ts
+++ b/server/core/controllers/api/video-playlist.ts
@@ -428,7 +428,7 @@ async function removeVideoPlaylist (req: express.Request, res: express.Response)
async function addVideoInPlaylist (req: express.Request, res: express.Response) {
const body: VideoPlaylistElementCreate = req.body
const videoPlaylist = res.locals.videoPlaylistFull
- const video = res.locals.videoThumbnails
+ const video = res.locals.videoThumbnailsBlacklist
const playlistElement = await sequelizeTypescript.transaction(async t => {
const position = await VideoPlaylistElementModel.getNextPositionOf(videoPlaylist.id, t)
diff --git a/server/core/helpers/peertube-jsonld.ts b/server/core/helpers/peertube-jsonld.ts
index 7e9419d4ad..a17a1748b9 100644
--- a/server/core/helpers/peertube-jsonld.ts
+++ b/server/core/helpers/peertube-jsonld.ts
@@ -63,10 +63,19 @@ async function checkRSA2017Signature (publicKey: string, originalBody: any): Pro
return { verified: false, body }
}
- const [ documentHash, optionsHash ] = await Promise.all([
- hashObject(compacted),
- createSignatureHash(body.signature)
- ])
+ let documentHash: string
+ let optionsHash: string
+
+ try {
+ ;[ documentHash, optionsHash ] = await Promise.all([
+ hashObject(compacted),
+ createSignatureHash(body.signature)
+ ])
+ } catch (err) {
+ // Canonicalization is aborted if it exceeds its work factor or timeout: the signature cannot be verified
+ logger.warn('Cannot canonicalize JSON-LD object to check its signature: %s.', err.message)
+ return { verified: false, body }
+ }
const toVerify = optionsHash + documentHash
diff --git a/server/core/lib/activitypub/actors/webfinger.ts b/server/core/lib/activitypub/actors/webfinger.ts
index 18ba0652d9..a8f32b882f 100644
--- a/server/core/lib/activitypub/actors/webfinger.ts
+++ b/server/core/lib/activitypub/actors/webfinger.ts
@@ -1,4 +1,5 @@
import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc.js'
+import { isHostValid } from '@server/helpers/custom-validators/servers.js'
import { doJSONRequest } from '@server/helpers/requests.js'
import { REMOTE_SCHEME, REQUEST_TIMEOUTS, WEBSERVER } from '@server/initializers/constants.js'
import { ActorModel } from '@server/models/actor/actor.js'
@@ -9,10 +10,15 @@ type WebFingerJRD = {
}
export async function loadActorUrlOrGetFromWebfinger (uriArg: string) {
- // Handle strings like @[email protected]
- const uri = uriArg.startsWith('@') ? uriArg.slice(1) : uriArg
+ const actorUrl = await loadActorUrlFromDB(uriArg)
+ if (actorUrl) return actorUrl
+
+ return getUrlFromWebfinger(removeHandlePrefix(uriArg))
+}
- const [ name, host ] = uri.split('@')
+// Resolve the handle without any outbound request
+export async function loadActorUrlFromDB (uriArg: string) {
+ const [ name, host ] = removeHandlePrefix(uriArg).split('@')
let actor: MActorFull
if (!host || host === WEBSERVER.HOST) {
@@ -21,14 +27,14 @@ export async function loadActorUrlOrGetFromWebfinger (uriArg: string) {
actor = await ActorModel.loadByNameAndHost(name, host)
}
- if (actor) return actor.url
-
- return getUrlFromWebfinger(uri)
+ return actor?.url
}
export async function getUrlFromWebfinger (uri: string) {
- const [ name, host ] = uri.split('@')
- if (!name || !host) throw new Error(`Invalid webfinger address "${uri}"`)
+ const parts = uri.split('@')
+ const [ name, host ] = parts
+
+ if (parts.length !== 2 || !name || !isWebfingerHostValid(host)) throw new Error(`Invalid webfinger address "${uri}"`)
const url = `${REMOTE_SCHEME.HTTP}://${host}/.well-known/webfinger?resource=${encodeURIComponent('acct:' + uri)}`
@@ -46,3 +52,17 @@ export async function getUrlFromWebfinger (uri: string) {
return selfLink.href
}
+
+// ---------------------------------------------------------------------------
+
+function removeHandlePrefix (uri: string) {
+ // Handle strings like @[email protected]
+ return uri.startsWith('@')
+ ? uri.slice(1)
+ : uri
+}
+
+function isWebfingerHostValid (host: string) {
+ // isHostValid accepts a path/query/fragment, but the host must not change the request path
+ return isHostValid(host) && /[/?#\\\s]/.test(host) === false
+}
diff --git a/server/core/lib/html/shared/playlist-html.ts b/server/core/lib/html/shared/playlist-html.ts
index 154555a441..71796bbb6e 100644
--- a/server/core/lib/html/shared/playlist-html.ts
+++ b/server/core/lib/html/shared/playlist-html.ts
@@ -26,7 +26,7 @@ export class PlaylistHtml {
])
// Let Angular application handle errors
- if (!videoPlaylist || videoPlaylist.privacy === VideoPlaylistPrivacy.PRIVATE) {
+ if (!this.canBuildPlaylistTags(videoPlaylist, videoPlaylistId)) {
res.status(HttpStatusCode.NOT_FOUND_404)
return html
}
@@ -51,7 +51,7 @@ export class PlaylistHtml {
const [ html, playlist ] = await Promise.all([ PageHtml.getEmbedHTML(), playlistPromise ])
- if (!playlist || playlist.privacy === VideoPlaylistPrivacy.PRIVATE) {
+ if (!this.canBuildPlaylistTags(playlist, playlistId)) {
return buildEmptyEmbedHTML({ html, playlist })
}
@@ -73,6 +73,15 @@ export class PlaylistHtml {
// Private
// ---------------------------------------------------------------------------
+ private static canBuildPlaylistTags (playlist: MVideoPlaylist, playlistId: string) {
+ if (!playlist || playlist.privacy === VideoPlaylistPrivacy.PRIVATE) return false
+
+ // Unlisted playlists can only be fetched using their UUID
+ if (playlist.privacy === VideoPlaylistPrivacy.UNLISTED && !validator.default.isUUID(playlistId, 4)) return false
+
+ return true
+ }
+
private static buildPlaylistHTML (options: {
req: express.Request
diff --git a/server/core/lib/html/shared/video-html.ts b/server/core/lib/html/shared/video-html.ts
index 8f43205952..c82cfbbb4e 100644
--- a/server/core/lib/html/shared/video-html.ts
+++ b/server/core/lib/html/shared/video-html.ts
@@ -32,7 +32,7 @@ export class VideoHtml {
}
// Let Angular application handle errors
- if (!video || isVideoInPrivateDirectory(video.privacy) || video.VideoBlacklist) {
+ if (!this.canBuildVideoTags(video, videoId)) {
res.status(HttpStatusCode.NOT_FOUND_404)
return html
}
@@ -57,7 +57,7 @@ export class VideoHtml {
const [ html, video ] = await Promise.all([ PageHtml.getEmbedHTML(), videoPromise ])
- if (!video || isVideoInPrivateDirectory(video.privacy) || video.VideoBlacklist) {
+ if (!this.canBuildVideoTags(video, videoId)) {
return buildEmptyEmbedHTML({ html, video })
}
@@ -79,6 +79,15 @@ export class VideoHtml {
// Private
// ---------------------------------------------------------------------------
+ private static canBuildVideoTags (video: MVideoSeo, videoId: string) {
+ if (!video || isVideoInPrivateDirectory(video.privacy) || video.VideoBlacklist) return false
+
+ // Unlisted videos can only be fetched using their UUID
+ if (video.privacy === VideoPrivacy.UNLISTED && !validator.default.isUUID(videoId, 4)) return false
+
+ return true
+ }
+
private static buildVideoHTML (options: {
req: express.Request
diff --git a/server/core/lib/model-loaders/video.ts b/server/core/lib/model-loaders/video.ts
index aca6d8f22a..f52f7e3961 100644
--- a/server/core/lib/model-loaders/video.ts
+++ b/server/core/lib/model-loaders/video.ts
@@ -7,7 +7,7 @@ import {
MVideoFull,
MVideoId,
MVideoImmutable,
- MVideoThumbnails,
+ MVideoThumbnailsBlacklist,
MVideoWithBlacklist,
MVideoWithRights
} from '@server/types/models/index.js'
@@ -18,7 +18,7 @@ type VideoLoadType =
| 'ap'
| 'full'
| 'with-blacklist'
- | 'with-thumbnails'
+ | 'with-thumbnails-blacklist'
| 'with-rights'
| 'id'
| 'none'
@@ -28,7 +28,7 @@ function loadVideo (id: number | string, fetchType: 'for-api', userId?: number):
function loadVideo (id: number | string, fetchType: 'ap'): Promise<MVideoAP>
function loadVideo (id: number | string, fetchType: 'full', userId?: number): Promise<MVideoFull>
function loadVideo (id: number | string, fetchType: 'with-blacklist', userId?: number): Promise<MVideoWithBlacklist>
-function loadVideo (id: number | string, fetchType: 'with-thumbnails', userId?: number): Promise<MVideoThumbnails>
+function loadVideo (id: number | string, fetchType: 'with-thumbnails-blacklist', userId?: number): Promise<MVideoThumbnailsBlacklist>
function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoId>
function loadVideo (id: number | string, fetchType: 'unsafe-immutable-only'): Promise<MVideoImmutable>
function loadVideo (id: number | string, fetchType: 'with-rights'): Promise<MVideoWithRights>
@@ -36,12 +36,12 @@ function loadVideo (
id: number | string,
fetchType: VideoLoadType,
userId?: number
-): Promise<MVideoAP | MVideoFull | MVideoWithBlacklist | MVideoId | MVideoImmutable | MVideoThumbnails | MVideoWithRights>
+): Promise<MVideoAP | MVideoFull | MVideoWithBlacklist | MVideoId | MVideoImmutable | MVideoThumbnailsBlacklist | MVideoWithRights>
function loadVideo (
id: number | string,
fetchType: VideoLoadType,
userId?: number
-): Promise<MVideoAP | MVideoFull | MVideoWithBlacklist | MVideoId | MVideoImmutable | MVideoThumbnails> {
+): Promise<MVideoAP | MVideoFull | MVideoWithBlacklist | MVideoId | MVideoImmutable | MVideoThumbnailsBlacklist> {
if (fetchType === 'for-api') return VideoModel.loadForGetAPI({ id, userId })
if (fetchType === 'ap') return VideoModel.loadAP(id)
@@ -52,7 +52,7 @@ function loadVideo (
if (fetchType === 'with-blacklist') return VideoModel.loadWithBlacklist(id)
- if (fetchType === 'with-thumbnails') return VideoModel.loadWithThumbnails(id)
+ if (fetchType === 'with-thumbnails-blacklist') return VideoModel.loadWithThumbnailsAndBlacklist(id)
if (fetchType === 'with-rights') return VideoModel.loadWithRights(id)
diff --git a/server/core/middlewares/validators/abuse.ts b/server/core/middlewares/validators/abuse.ts
index 3021000f85..2c85cd3a44 100644
--- a/server/core/middlewares/validators/abuse.ts
+++ b/server/core/middlewares/validators/abuse.ts
@@ -1,7 +1,7 @@
import express from 'express'
import { body, param, query } from 'express-validator'
import { forceNumber } from '@peertube/peertube-core-utils'
-import { AbuseCreate, HttpStatusCode, UserRight } from '@peertube/peertube-models'
+import { AbuseCreate, HttpStatusCode, UserRight, VideoPrivacy } from '@peertube/peertube-models'
import {
areAbusePredefinedReasonsValid,
isAbuseFilterValid,
@@ -14,12 +14,19 @@ import {
isAbuseTimestampValid,
isAbuseVideoIsValid
} from '@server/helpers/custom-validators/abuses.js'
-import { exists, isIdOrUUIDValid, isIdValid, toCompleteUUID, toIntOrNull } from '@server/helpers/custom-validators/misc.js'
+import { exists, isIdOrUUIDValid, isIdValid, isUUIDValid, 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'
+import {
+ areValidationErrors,
+ checkCanSeeVideo,
+ doesAbuseExist,
+ doesAccountIdExist,
+ doesCommentIdExist,
+ doesVideoExist
+} from './shared/index.js'
const logger = createLogger()
@@ -69,7 +76,12 @@ const abuseReportValidator = [
return
}
- if (body.video?.id && !await checkUserCanReportVideo({ user: res.locals.oauth.token.User, video: res.locals.videoFull, req, res })) return
+ if (body.video?.id) {
+ const video = res.locals.videoFull
+
+ if (!await checkUserCanSeeReportedVideo({ video, paramId: body.video.id + '', req, res })) return
+ if (!await checkUserCanReportVideo({ user: res.locals.oauth.token.User, video, req, res })) return
+ }
return next()
}
@@ -247,6 +259,29 @@ const deleteAbuseMessageValidator = [
// ---------------------------------------------------------------------------
+// The reporter gets the video name/UUID back in its abuse list: check it can see the video
+async function checkUserCanSeeReportedVideo (options: {
+ video: MVideoFull
+ paramId: string
+ req: express.Request
+ res: express.Response
+}) {
+ const { video, paramId, req, res } = options
+
+ // Don't require the password to report a password protected video, but the reporter must know its UUID
+ if (video.privacy === VideoPrivacy.PASSWORD_PROTECTED && !video.isBlacklisted()) {
+ if (isUUIDValid(paramId)) return true
+
+ res.fail({
+ status: HttpStatusCode.FORBIDDEN_403,
+ message: req.t('Cannot report this video')
+ })
+ return false
+ }
+
+ return checkCanSeeVideo({ req, res, video, paramId })
+}
+
async function checkUserCanReportVideo (options: {
user: MUserAccountId
video: MVideoFull
diff --git a/server/core/middlewares/validators/oembed.ts b/server/core/middlewares/validators/oembed.ts
index 4b01826071..cbba35e985 100644
--- a/server/core/middlewares/validators/oembed.ts
+++ b/server/core/middlewares/validators/oembed.ts
@@ -111,9 +111,8 @@ const oembedValidator = [
}
if (
- video.privacy === VideoPrivacy.PUBLIC ||
- (video.privacy === VideoPrivacy.UNLISTED && isUUIDValid(elementId) === true) ||
- video.VideoBlacklist
+ !video.VideoBlacklist &&
+ (video.privacy === VideoPrivacy.PUBLIC || (video.privacy === VideoPrivacy.UNLISTED && isUUIDValid(elementId) === true))
) {
res.locals.videoWithRights = video
return next()
diff --git a/server/core/middlewares/validators/shared/videos.ts b/server/core/middlewares/validators/shared/videos.ts
index 9edd2e984d..e841248fef 100644
--- a/server/core/middlewares/validators/shared/videos.ts
+++ b/server/core/middlewares/validators/shared/videos.ts
@@ -18,7 +18,7 @@ import {
MVideoFull,
MVideoId,
MVideoImmutable,
- MVideoThumbnails,
+ MVideoThumbnailsBlacklist,
MVideoUUID,
MVideoWithBlacklist,
MVideoWithRights
@@ -66,8 +66,8 @@ export async function doesVideoExist (id: number | string, res: Response, fetchT
res.locals.videoWithBlacklist = video as MVideoWithBlacklist
break
- case 'with-thumbnails':
- res.locals.videoThumbnails = video as MVideoThumbnails
+ case 'with-thumbnails-blacklist':
+ res.locals.videoThumbnailsBlacklist = video as MVideoThumbnailsBlacklist
break
case 'with-rights':
@@ -148,17 +148,18 @@ async function checkCanSeeUserAuthVideo (options: {
const privacy = videoWithRights.privacy
- if (privacy === VideoPrivacy.INTERNAL) {
- // We know we have a user
- return true
- }
-
+ // Check the blacklist first: it applies to any privacy
if (videoWithRights.isBlacklisted()) {
if (await canUserManageProtectedVideo({ user, req, video: videoWithRights, right: UserRight.MANAGE_VIDEO_BLACKLIST })) return true
return fail()
}
+ if (privacy === VideoPrivacy.INTERNAL) {
+ // We know we have a user
+ return true
+ }
+
if (privacy === VideoPrivacy.PRIVATE || privacy === VideoPrivacy.UNLISTED) {
if (await canUserManageProtectedVideo({ user, req, video: videoWithRights, right: UserRight.SEE_ALL_VIDEOS })) return true
diff --git a/server/core/middlewares/validators/users/user-email-verification.ts b/server/core/middlewares/validators/users/user-email-verification.ts
index 032eff5c51..54c5551cd0 100644
--- a/server/core/middlewares/validators/users/user-email-verification.ts
+++ b/server/core/middlewares/validators/users/user-email-verification.ts
@@ -48,10 +48,10 @@ export const usersAskSendUserVerifyEmailValidator = [
const user = userEmail || userPendingEmail
if (user.pluginAuth) {
- return res.fail({
- status: HttpStatusCode.CONFLICT_409,
- message: 'Cannot ask verification email of a user that uses a plugin authentication.'
- })
+ logger.debug(`User with email ${email} uses a plugin authentication, cannot send verification email.`)
+
+ // Do not leak our emails
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
}
return next()
diff --git a/server/core/middlewares/validators/users/users.ts b/server/core/middlewares/validators/users/users.ts
index 5f25d65cc5..6274739dbb 100644
--- a/server/core/middlewares/validators/users/users.ts
+++ b/server/core/middlewares/validators/users/users.ts
@@ -412,10 +412,9 @@ export const usersAskResetPasswordValidator = [
}
if (res.locals.user.pluginAuth) {
- return res.fail({
- status: HttpStatusCode.CONFLICT_409,
- message: 'Cannot recover password of a user that uses a plugin authentication.'
- })
+ logger.debug('User with email %s uses a plugin authentication, cannot recover its password.', email)
+ // Do not leak our emails
+ return res.status(HttpStatusCode.NO_CONTENT_204).end()
}
return next()
diff --git a/server/core/middlewares/validators/videos/video-channels.ts b/server/core/middlewares/validators/videos/video-channels.ts
index 60b98e33e9..f921e82b11 100644
--- a/server/core/middlewares/validators/videos/video-channels.ts
+++ b/server/core/middlewares/validators/videos/video-channels.ts
@@ -128,7 +128,8 @@ export const listAccountChannelsValidator = [
(req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
- if (req.query.withStats === true) {
+ // Stats and collaborations of an account are private
+ if (req.query.withStats === true || req.query.includeCollaborations === true) {
const user = res.locals.oauth?.token.User
if (!checkCanManageAccount({ account: res.locals.account, user, specialRight: UserRight.MANAGE_USERS, req, res })) return
diff --git a/server/core/middlewares/validators/videos/video-embed-privacy.ts b/server/core/middlewares/validators/videos/video-embed-privacy.ts
index 70ec97f50f..787876dc42 100644
--- a/server/core/middlewares/validators/videos/video-embed-privacy.ts
+++ b/server/core/middlewares/validators/videos/video-embed-privacy.ts
@@ -3,7 +3,7 @@ import { isHostValid } from '@server/helpers/custom-validators/servers.js'
import { areVideoEmbedPrivacyDomainsValid, isVideoEmbedPrivacyPolicyValid } from '@server/helpers/custom-validators/video-embed-privacy.js'
import express from 'express'
import { body, query } from 'express-validator'
-import { areValidationErrors, checkCanManageVideo, doesVideoExist, isValidVideoIdParam } from '../shared/index.js'
+import { areValidationErrors, checkCanManageVideo, checkCanSeeVideo, doesVideoExist, isValidVideoIdParam } from '../shared/index.js'
export const isVideoEmbedOnDomainAllowedValidator = [
isValidVideoIdParam('videoId'),
@@ -15,6 +15,13 @@ export const isVideoEmbedOnDomainAllowedValidator = [
if (areValidationErrors(req, res)) return
if (!await doesVideoExist(req.params.videoId, res, 'with-blacklist')) return
+ // Don't leak private/internal/blacklisted videos, or unlisted videos fetched using their numeric id
+ // Password protected videos only expose their embed policy, so password is not required
+ const video = res.locals.videoWithBlacklist
+ if (video.requiresUserAuth({ urlParamId: req.params.videoId, checkBlacklist: true })) {
+ if (!await checkCanSeeVideo({ req, res, video, paramId: req.params.videoId })) return
+ }
+
return next()
}
]
diff --git a/server/core/middlewares/validators/videos/video-playlists.ts b/server/core/middlewares/validators/videos/video-playlists.ts
index 9e1164fc26..c7b3d54ad7 100644
--- a/server/core/middlewares/validators/videos/video-playlists.ts
+++ b/server/core/middlewares/validators/videos/video-playlists.ts
@@ -272,7 +272,7 @@ export const videoPlaylistsAddVideoValidator = [
if (areValidationErrors(req, res)) return
if (!await doesVideoPlaylistExist({ id: req.params.playlistId, req, res, fetchType: 'all' })) return
- if (!await doesVideoExist(req.body.videoId, res, 'with-thumbnails')) return
+ if (!await doesVideoExist(req.body.videoId, res, 'with-thumbnails-blacklist')) return
const videoPlaylist = getPlaylist(res)
@@ -288,7 +288,7 @@ export const videoPlaylistsAddVideoValidator = [
return
}
- if (!await checkCanSeeVideo({ req, res, video: res.locals.videoThumbnails, paramId: req.body.videoId })) return
+ if (!await checkCanSeeVideo({ req, res, video: res.locals.videoThumbnailsBlacklist, paramId: req.body.videoId })) return
return next()
}
@@ -369,6 +369,14 @@ export const videoPlaylistElementAPGetValidator = [
})
}
+ // Unlisted playlist elements can only be fetched using the playlist UUID (the element URL contains it)
+ if (videoPlaylistElement.VideoPlaylist.privacy === VideoPlaylistPrivacy.UNLISTED && !isUUIDValid(playlistId)) {
+ return res.fail({
+ status: HttpStatusCode.NOT_FOUND_404,
+ message: req.t('Video playlist element not found')
+ })
+ }
+
res.locals.videoPlaylistElementAP = videoPlaylistElement
return next()
diff --git a/server/core/middlewares/validators/videos/video-rates.ts b/server/core/middlewares/validators/videos/video-rates.ts
index 837ab9f623..229d9e3f0a 100644
--- a/server/core/middlewares/validators/videos/video-rates.ts
+++ b/server/core/middlewares/validators/videos/video-rates.ts
@@ -1,6 +1,8 @@
import express from 'express'
import { body, param, query } from 'express-validator'
-import { HttpStatusCode, VideoRateType } from '@peertube/peertube-models'
+import { HttpStatusCode, VideoPrivacy, VideoRateType } from '@peertube/peertube-models'
+import { isStateForFederation } from '@server/lib/activitypub/videos/federate.js'
+import { MVideoWithBlacklist } from '@server/types/models/index.js'
import { isAccountNameValid } from '../../../helpers/custom-validators/accounts.js'
import { isIdValid } from '../../../helpers/custom-validators/misc.js'
import { isRatingValid } from '../../../helpers/custom-validators/video-rates.js'
@@ -37,7 +39,8 @@ const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) {
if (areValidationErrors(req, res)) return
const rate = await AccountVideoRateModel.loadLocalAndPopulateVideo(rateType, req.params.accountName, +req.params.videoId)
- if (!rate) {
+
+ if (!rate || !canExposeRate(rate.Video)) {
return res.fail({
status: HttpStatusCode.NOT_FOUND_404,
message: 'Video rate not found'
@@ -51,6 +54,18 @@ const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) {
]
}
+// The rate URL uses the video numeric id: don't expose rates of non-public videos to not leak their URL
+function canExposeRate (video: MVideoWithBlacklist) {
+ if (video.isBlacklisted() && video.VideoBlacklist.unfederated === true) return false
+ if (!isStateForFederation(video.state)) return false
+
+ if (video.privacy === VideoPrivacy.PUBLIC) return true
+
+ // A remote unlisted video is only stored here if its origin federates unlisted videos
+ // The origin checks our rate in its activitypub-cleaner and would delete it if we return a 404
+ return !video.isLocal() && video.privacy === VideoPrivacy.UNLISTED
+}
+
const videoRatingValidator = [
query('rating')
.optional()
diff --git a/server/core/middlewares/validators/videos/video-view.ts b/server/core/middlewares/validators/videos/video-view.ts
index c7b9b155bc..db8b99f98f 100644
--- a/server/core/middlewares/validators/videos/video-view.ts
+++ b/server/core/middlewares/validators/videos/video-view.ts
@@ -25,7 +25,10 @@ export const getVideoLocalViewerValidator = [
if (areValidationErrors(req, res, { tags })) return
const localViewer = await LocalVideoViewerModel.loadFullById(+req.params.localViewerId)
- if (!localViewer) {
+
+ // Viewer stats are only federated to the origin server for remote videos
+ // Don't leak viewer stats of local videos (URL of unlisted/private videos, viewer location etc.)
+ if (localViewer?.Video.remote !== true) {
return res.fail({
status: HttpStatusCode.NOT_FOUND_404,
message: 'Local viewer not found',
diff --git a/server/core/models/account/account-video-rate.ts b/server/core/models/account/account-video-rate.ts
index 6b3a06a3f4..f28453e324 100644
--- a/server/core/models/account/account-video-rate.ts
+++ b/server/core/models/account/account-video-rate.ts
@@ -13,6 +13,7 @@ import { CONSTRAINTS_FIELDS, USER_EXPORT_MAX_ITEMS, VIDEO_RATE_TYPES } from '../
import { ActorModel } from '../actor/actor.js'
import { SequelizeModel, getSort, throwIfNotValid } from '../shared/index.js'
import { VideoChannelModel, ScopeNames as VideoChannelScopeNames } from '../video/video-channel.js'
+import { VideoBlacklistModel } from '../video/video-blacklist.js'
import { VideoModel } from '../video/video.js'
import { AccountModel } from './account.js'
@@ -143,7 +144,13 @@ export class AccountVideoRateModel extends SequelizeModel<AccountVideoRateModel>
},
{
model: VideoModel.unscoped(),
- required: true
+ required: true,
+ include: [
+ {
+ model: VideoBlacklistModel.unscoped(),
+ required: false
+ }
+ ]
}
]
}
diff --git a/server/core/models/video/sql/video/video-model-get-query-builder.ts b/server/core/models/video/sql/video/video-model-get-query-builder.ts
index f2f756d9a5..a87609a352 100644
--- a/server/core/models/video/sql/video/video-model-get-query-builder.ts
+++ b/server/core/models/video/sql/video/video-model-get-query-builder.ts
@@ -19,6 +19,7 @@ export type GetType =
| 'account'
| 'all-files'
| 'thumbnails'
+ | 'thumbnails-blacklist'
| 'blacklist'
| 'id'
| 'video'
@@ -45,6 +46,7 @@ const blacklistedInclude = new Set<GetType>([
'account-blacklist',
'account-blacklist-files',
'blacklist',
+ 'thumbnails-blacklist',
'seo'
])
@@ -55,6 +57,7 @@ const thumbnailsInclude = new Set<GetType>([
'account-blacklist-files',
'all-files',
'thumbnails',
+ 'thumbnails-blacklist',
'seo'
])
diff --git a/server/core/models/video/video.ts b/server/core/models/video/video.ts
index f8d00f6d34..6844caf51b 100644
--- a/server/core/models/video/video.ts
+++ b/server/core/models/video/video.ts
@@ -108,6 +108,7 @@ import type {
MVideoSeo,
MVideoSummary,
MVideoThumbnails,
+ MVideoThumbnailsBlacklist,
MVideoWithAllFiles,
MVideoWithBlacklist,
MVideoWithFile,
@@ -1416,6 +1417,12 @@ export class VideoModel extends SequelizeModel<VideoModel> {
return queryBuilder.queryVideo({ id, transaction, type: 'thumbnails' })
}
+ static loadWithThumbnailsAndBlacklist (id: number | string, transaction?: Transaction): Promise<MVideoThumbnailsBlacklist> {
+ const queryBuilder = new VideoModelGetQueryBuilder(VideoModel.sequelize)
+
+ return queryBuilder.queryVideo({ id, transaction, type: 'thumbnails-blacklist' })
+ }
+
static loadWithBlacklist (id: number | string, transaction?: Transaction): Promise<MVideoWithBlacklist> {
const queryBuilder = new VideoModelGetQueryBuilder(VideoModel.sequelize)
diff --git a/server/core/types/express.d.ts b/server/core/types/express.d.ts
index 2a8c69ac1a..bc58845a2a 100644
--- a/server/core/types/express.d.ts
+++ b/server/core/types/express.d.ts
@@ -34,7 +34,7 @@ import {
MVideoPassword,
MVideoPlaylistFull,
MVideoPlaylistFullSummary,
- MVideoThumbnails,
+ MVideoThumbnailsBlacklist,
MVideoWithBlacklist,
MVideoWithRights,
MWatchedWordsList,
@@ -161,7 +161,7 @@ declare module 'express' {
videoImmutable?: MVideoImmutable
videoWithBlacklist?: MVideoWithBlacklist
videoWithRights?: MVideoWithRights
- videoThumbnails?: MVideoThumbnails
+ videoThumbnailsBlacklist?: MVideoThumbnailsBlacklist
videoId?: MVideoId
videoLive?: MVideoLiveWithSettingSchedules
diff --git a/server/core/types/models/video/video-rate.ts b/server/core/types/models/video/video-rate.ts
index 61a5028287..9493bf6117 100644
--- a/server/core/types/models/video/video-rate.ts
+++ b/server/core/types/models/video/video-rate.ts
@@ -1,7 +1,7 @@
import { AccountVideoRateModel } from '@server/models/account/account-video-rate.js'
import { PickWith } from '@peertube/peertube-typescript-utils'
import { MAccountAudience, MAccountUrl } from '../account/account.js'
-import { MVideo, MVideoFormattable, MVideoUrl } from './video.js'
+import { MVideoFormattable, MVideoUrl, MVideoWithBlacklist } from './video.js'
type Use<K extends keyof AccountVideoRateModel, M> = PickWith<AccountVideoRateModel, K, M>
@@ -20,7 +20,7 @@ export type MAccountVideoRateAccountUrl =
export type MAccountVideoRateAccountVideo =
& MAccountVideoRate
& Use<'Account', MAccountAudience>
- & Use<'Video', MVideo>
+ & Use<'Video', MVideoWithBlacklist>
// ############################################################################
diff --git a/server/core/types/models/video/video.ts b/server/core/types/models/video/video.ts
index b18d05100c..1ddf5c0101 100644
--- a/server/core/types/models/video/video.ts
+++ b/server/core/types/models/video/video.ts
@@ -92,6 +92,10 @@ export type MVideoWithBlacklist =
& MVideo
& Use<'VideoBlacklist', MVideoBlacklistLight>
+export type MVideoThumbnailsBlacklist =
+ & MVideoThumbnails
+ & Use<'VideoBlacklist', MVideoBlacklistLight>
+
export type MVideoTag =
& MVideo
& Use<'Tags', MTag[]>