ActivityPub-federated video streaming platform using P2P directly in your web browser
Ensure actors and videos are on the same host
Chocobozzz63d487d2a4a2
diff --git a/server/core/lib/activitypub/process/process-update.ts b/server/core/lib/activitypub/process/process-update.tsindex 71910a6f12..bb5b0283c0 100644--- a/server/core/lib/activitypub/process/process-update.ts+++ b/server/core/lib/activitypub/process/process-update.ts@@ -27,6 +27,7 @@ import { upsertAPPlayerSettings } from '../player-settings.js'import { createOrUpdateVideoPlaylist } from '../playlists/index.js'import { forwardVideoRelatedActivity } from '../send/shared/send-utils.js'import { APVideoUpdater, canVideoBeFederated, getOrCreateAPVideo, maybeGetOrCreateAPVideo } from '../videos/index.js'+import { checkUrlsSameHost } from '../url.js'async function processUpdateActivity (options: APProcessorOptions<ActivityUpdate<ActivityUpdateObject>>) {const { activity, byActor } = options@@ -35,7 +36,7 @@ async function processUpdateActivity (options: APProcessorOptions<ActivityUpdateconst objectType = object.typeif (objectType === 'Video') {- return retryTransactionWrapper(processUpdateVideo, activity)+ return retryTransactionWrapper(processUpdateVideo, byActor, activity)}if (isActorTypeValid(objectType as ActivityPubActorType)) {@@ -69,9 +70,14 @@ export {// ----------------------------------------------------------------------------async function processUpdateVideo (activity: ActivityUpdate<VideoObject | string>) {+async function processUpdateVideo (byActor: MActorSignature, activity: ActivityUpdate<VideoObject | string>) {const videoObject = activity.object as VideoObject+ if (!checkUrlsSameHost(byActor.url, videoObject.id)) {+ logger.warn('Video sent by update is not from the same host as the actor.', { videoObject, byActor })+ return undefined+ }+if (sanitizeAndCheckVideoTorrentObject(videoObject) === false) {logger.debug('Video sent by update is not valid.', { videoObject })return undefined@@ -85,7 +91,7 @@ async function processUpdateVideo (activity: ActivityUpdate<VideoObject | string// We did not have this video, it has been created so no need to updateif (created) return- const updater = new APVideoUpdater(videoObject, video)+ const updater = new APVideoUpdater(videoObject, video, byActor.url)return updater.update(arrayify(activity.to))}diff --git a/server/core/lib/activitypub/videos/refresh.ts b/server/core/lib/activitypub/videos/refresh.tsindex edf46dbb76..7c5fa92446 100644--- a/server/core/lib/activitypub/videos/refresh.ts+++ b/server/core/lib/activitypub/videos/refresh.ts@@ -45,7 +45,7 @@ export async function refreshVideoIfNeeded (options: {return video}- const videoUpdater = new APVideoUpdater(videoObject, video)+ const videoUpdater = new APVideoUpdater(videoObject, video, video.url)await videoUpdater.update()await syncVideoExternalAttributes(video, videoObject, options.syncParam)diff --git a/server/core/lib/activitypub/videos/updater.ts b/server/core/lib/activitypub/videos/updater.tsindex f17115bb20..f8e6cfee76 100644--- a/server/core/lib/activitypub/videos/updater.ts+++ b/server/core/lib/activitypub/videos/updater.ts@@ -16,6 +16,7 @@ import {import { Transaction } from 'sequelize'import { haveActorsSameRemoteHost } from '../actors/check-actor.js'import { APVideoAbstractBuilder, getVideoAttributesFromObject, updateVideoRates } from './shared/index.js'+import { checkUrlsSameHost } from '../url.js'export class APVideoUpdater extends APVideoAbstractBuilder {private readonly wasPrivateVideo: boolean@@ -27,7 +28,8 @@ export class APVideoUpdater extends APVideoAbstractBuilder {constructor (protected readonly videoObject: VideoObject,- private readonly video: MVideoAccountLightBlacklistAllFiles+ private readonly video: MVideoAccountLightBlacklistAllFiles,+ private readonly contextUrl: string) {super()@@ -46,6 +48,14 @@ export class APVideoUpdater extends APVideoAbstractBuilder {{ videoObject: this.videoObject, ...this.lTags() })+ if (!checkUrlsSameHost(this.contextUrl, this.videoObject.id)) {+ logger.warn('Video sent by update is not from the same host as the context URL.', {+ videoObject: this.videoObject,+ contextUrl: this.contextUrl+ })+ return undefined+ }+const oldInputFileUpdatedAt = this.video.inputFileUpdatedAttry {@@ -89,13 +99,11 @@ export class APVideoUpdater extends APVideoAbstractBuilder {await updateVideoRates(videoUpdated, this.videoObject)// Notify our users?- if (this.wasPrivateVideo || this.wasUnlistedVideo) {- Notifier.Instance.notifyOnNewVideoOrLiveIfNeeded(videoUpdated)- }-if (videoUpdated.isLive && oldState !== videoUpdated.state) {PeerTubeSocket.Instance.sendVideoLiveNewState(videoUpdated)Notifier.Instance.notifyOnNewVideoOrLiveIfNeeded(videoUpdated)+ } else if (this.wasPrivateVideo || this.wasUnlistedVideo) {+ Notifier.Instance.notifyOnNewVideoOrLiveIfNeeded(videoUpdated)}Hooks.runAction('action:activity-pub.remote-video.updated', { video: videoUpdated, videoAPObject: this.videoObject })@@ -162,9 +170,9 @@ export class APVideoUpdater extends APVideoAbstractBuilder {}private async setOrDeleteLive (videoUpdated: MVideoFull, transaction?: Transaction) {- if (!this.video.isLive) return-- if (this.video.isLive) return this.insertOrReplaceLive(videoUpdated, transaction)+ if (this.video.isLive) {+ return this.insertOrReplaceLive(videoUpdated, transaction)+ }// Delete existing live if it existsawait VideoLiveModel.destroy({