Skip to content

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

Ensure playlist is owned by actor/instance

Chocobozzz0fc3f91d8399
diff --git a/server/core/lib/activitypub/playlists/create-update.ts b/server/core/lib/activitypub/playlists/create-update.ts
index f604e2dfb7..746853f75b 100644
--- a/server/core/lib/activitypub/playlists/create-update.ts
+++ b/server/core/lib/activitypub/playlists/create-update.ts
@@ -49,7 +49,7 @@ export async function createAccountPlaylists (playlistUrls: string[], account: M
throw new Error(`Cannot refresh remote playlist ${playlistUrl}: invalid body.`)
}
- return createOrUpdateVideoPlaylist({ playlistObject })
+ return createOrUpdateVideoPlaylist({ playlistObject, contextUrl: playlistUrl })
} catch (err) {
logger.warn(`Cannot create or update playlist ${playlistUrl}`, { err, ...lTags(playlistUrl) })
}
@@ -58,9 +58,17 @@ export async function createAccountPlaylists (playlistUrls: string[], account: M
export async function createOrUpdateVideoPlaylist (options: {
playlistObject: PlaylistObject
+ // Which is the context where we retrieved the playlist
+ // Can be the actor that signed the activity URL or the playlist URL we fetched
+ contextUrl: string
to?: string[]
}) {
- const { playlistObject, to } = options
+ const { playlistObject, contextUrl, to } = options
+
+ if (!checkUrlsSameHost(playlistObject.id, contextUrl)) {
+ throw new Error(`Playlist ${playlistObject.id} is not on the same host as context URL ${contextUrl}`)
+ }
+
const playlistAttributes = playlistObjectToDBAttributes(playlistObject, to || playlistObject.to)
const channel = await getRemotePlaylistChannel(playlistObject)
@@ -82,7 +90,11 @@ export async function createOrUpdateVideoPlaylist (options: {
return playlist
}
-export async function getRemotePlaylistChannel (playlistObject: PlaylistObject) {
+// ---------------------------------------------------------------------------
+// Private
+// ---------------------------------------------------------------------------
+
+async function getRemotePlaylistChannel (playlistObject: PlaylistObject) {
if (!isArray(playlistObject.attributedTo) || playlistObject.attributedTo.length !== 1) {
throw new Error('Not attributed to for playlist object ' + getAPId(playlistObject))
}
@@ -101,10 +113,6 @@ export async function getRemotePlaylistChannel (playlistObject: PlaylistObject)
return actor.VideoChannel
}
-// ---------------------------------------------------------------------------
-// Private
-// ---------------------------------------------------------------------------
-
async function fetchElementUrls (playlistObject: PlaylistObject) {
let accItems: string[] = []
await crawlCollectionPage<string>(playlistObject.id, items => {
diff --git a/server/core/lib/activitypub/playlists/get.ts b/server/core/lib/activitypub/playlists/get.ts
index 03cdf43747..32d1f4b6e2 100644
--- a/server/core/lib/activitypub/playlists/get.ts
+++ b/server/core/lib/activitypub/playlists/get.ts
@@ -1,4 +1,3 @@
-import { APObjectId } from '@peertube/peertube-models'
import { VideoPlaylistModel } from '@server/models/video/video-playlist.js'
import { MVideoPlaylistFullSummary } from '@server/types/models/index.js'
import { getAPId } from '../activity.js'
@@ -6,9 +5,7 @@ import { createOrUpdateVideoPlaylist } from './create-update.js'
import { scheduleRefreshIfNeeded } from './refresh.js'
import { fetchRemoteVideoPlaylist } from './shared/index.js'
-export async function getOrCreateAPVideoPlaylist (playlistObjectArg: APObjectId): Promise<MVideoPlaylistFullSummary> {
- const playlistUrl = getAPId(playlistObjectArg)
-
+export async function getOrCreateAPVideoPlaylist (playlistUrl: string): Promise<MVideoPlaylistFullSummary> {
const playlistFromDatabase = await VideoPlaylistModel.loadByUrlWithAccountAndChannelSummary(playlistUrl)
if (playlistFromDatabase) {
@@ -21,9 +18,9 @@ export async function getOrCreateAPVideoPlaylist (playlistObjectArg: APObjectId)
if (!playlistObject) throw new Error('Cannot fetch remote playlist with url: ' + playlistUrl)
// playlistUrl is just an alias/redirection, so process object id instead
- if (playlistObject.id !== playlistUrl) return getOrCreateAPVideoPlaylist(playlistObject)
+ if (playlistObject.id !== playlistUrl) return getOrCreateAPVideoPlaylist(getAPId(playlistObject))
- const playlistCreated = await createOrUpdateVideoPlaylist({ playlistObject })
+ const playlistCreated = await createOrUpdateVideoPlaylist({ playlistObject, contextUrl: playlistUrl })
return playlistCreated
}
diff --git a/server/core/lib/activitypub/playlists/refresh.ts b/server/core/lib/activitypub/playlists/refresh.ts
index 4781e3ff69..1e749f2810 100644
--- a/server/core/lib/activitypub/playlists/refresh.ts
+++ b/server/core/lib/activitypub/playlists/refresh.ts
@@ -29,7 +29,7 @@ async function refreshVideoPlaylistIfNeeded (videoPlaylist: MVideoPlaylistOwnerD
return videoPlaylist
}
- await createOrUpdateVideoPlaylist({ playlistObject })
+ await createOrUpdateVideoPlaylist({ playlistObject, contextUrl: videoPlaylist.url })
return videoPlaylist
} catch (err) {
diff --git a/server/core/lib/activitypub/process/process-create.ts b/server/core/lib/activitypub/process/process-create.ts
index e0aec2c1d1..9ddcf82be0 100644
--- a/server/core/lib/activitypub/process/process-create.ts
+++ b/server/core/lib/activitypub/process/process-create.ts
@@ -186,5 +186,5 @@ async function processCreatePlaylist (
const byAccount = byActor.Account
if (!byAccount) throw new Error('Cannot create video playlist with the non account actor ' + byActor.url)
- await createOrUpdateVideoPlaylist({ playlistObject, to: activity.to })
+ await createOrUpdateVideoPlaylist({ playlistObject, contextUrl: byActor.url, to: activity.to })
}
diff --git a/server/core/lib/activitypub/process/process-update.ts b/server/core/lib/activitypub/process/process-update.ts
index 2a3e0db07e..8dacf2e80a 100644
--- a/server/core/lib/activitypub/process/process-update.ts
+++ b/server/core/lib/activitypub/process/process-update.ts
@@ -127,5 +127,5 @@ async function processUpdatePlaylist (
const byAccount = byActor.Account
if (!byAccount) throw new Error('Cannot update video playlist with the non account actor ' + byActor.url)
- await createOrUpdateVideoPlaylist({ playlistObject, to: activity.to })
+ await createOrUpdateVideoPlaylist({ playlistObject, contextUrl: byActor.url, to: activity.to })
}