ActivityPub-federated video streaming platform using P2P directly in your web browser
Security hardening
Chocobozzz90cd512f501b
diff --git a/client/src/app/modal/admin-config-wizard/steps/admin-config-wizard-form.component.html b/client/src/app/modal/admin-config-wizard/steps/admin-config-wizard-form.component.htmlindex ed3fcb40a6..ed379630af 100644--- a/client/src/app/modal/admin-config-wizard/steps/admin-config-wizard-form.component.html+++ b/client/src/app/modal/admin-config-wizard/steps/admin-config-wizard-form.component.html@@ -41,7 +41,7 @@<label for="platformTypeInstitution"><div>- <my-custom-icon [html]="iconInstitution"></my-custom-icon>+ <my-custom-icon [unsafeHTML]="iconInstitution"></my-custom-icon></div><div>@@ -57,7 +57,7 @@<label for="platformTypePrivate"><div>- <my-custom-icon [html]="iconKey"></my-custom-icon>+ <my-custom-icon [unsafeHTML]="iconKey"></my-custom-icon></div><div>diff --git a/client/src/app/shared/shared-icons/custom-icon.component.ts b/client/src/app/shared/shared-icons/custom-icon.component.tsindex 03ed5c84e5..f500402ff1 100644--- a/client/src/app/shared/shared-icons/custom-icon.component.ts+++ b/client/src/app/shared/shared-icons/custom-icon.component.ts@@ -10,12 +10,12 @@ import { ChangeDetectionStrategy, Component, ElementRef, OnInit, inject, input }export class CustomIconComponent implements OnInit {private el = inject(ElementRef)- readonly html = input.required<string>()+ readonly unsafeHTML = input.required<string>()ngOnInit () {const nativeElement = this.el.nativeElement as HTMLElement- nativeElement.innerHTML = this.html()+ nativeElement.innerHTML = this.unsafeHTML()nativeElement.ariaHidden = 'true'}}diff --git a/client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts b/client/src/app/shared/shared-user-subscription/remote-subscribe.component.tsindex 84e2400786..bbfc332168 100644--- a/client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts+++ b/client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts@@ -59,9 +59,12 @@ export class RemoteSubscribeComponent extends FormReactive implements OnInit {throw new Error('No subscribe template in webfinger response')}).then(url => {- if (isIOS()) return window.location.href = url+ // Ensure the URL is valid+ const parsed = new URL(url)- return window.open(url)+ if (isIOS()) return window.location.href = parsed.toString()++ return window.open(parsed.toString())}).catch(err => {logger.error(err)diff --git a/server/core/initializers/database.ts b/server/core/initializers/database.tsindex 701ca735fc..7ee27a41d1 100644--- a/server/core/initializers/database.ts+++ b/server/core/initializers/database.ts@@ -11,6 +11,8 @@ import { RunnerRegistrationTokenModel } from '@server/models/runner/runner-regisimport { RunnerModel } from '@server/models/runner/runner.js'import { TrackerModel } from '@server/models/server/tracker.js'import { VideoTrackerModel } from '@server/models/server/video-tracker.js'+import { LocalVideoViewerWatchSectionModel } from '@server/models/stat/local-video-viewer-watch-section.js'+import { LocalVideoViewerModel } from '@server/models/stat/local-video-viewer.js'import { UserExportModel } from '@server/models/user/user-export.js'import { UserImportModel } from '@server/models/user/user-import.js'import { UserNotificationModel } from '@server/models/user/user-notification.js'@@ -30,8 +32,6 @@ import { VideoLiveScheduleModel } from '@server/models/video/video-live-scheduleimport { VideoLiveSessionModel } from '@server/models/video/video-live-session.js'import { VideoPasswordModel } from '@server/models/video/video-password.js'import { VideoSourceModel } from '@server/models/video/video-source.js'-import { LocalVideoViewerWatchSectionModel } from '@server/models/stat/local-video-viewer-watch-section.js'-import { LocalVideoViewerModel } from '@server/models/stat/local-video-viewer.js'import { WatchedWordsListModel } from '@server/models/watched-words/watched-words-list.js'import { readFileSync } from 'fs'import pg from 'pg'@@ -55,13 +55,14 @@ import { VideoRedundancyModel } from '../models/redundancy/video-redundancy.js'import { PluginModel } from '../models/server/plugin.js'import { ServerBlocklistModel } from '../models/server/server-blocklist.js'import { ServerModel } from '../models/server/server.js'+import { VideoStatModel } from '../models/stat/video-stat.js'import { UserNotificationSettingModel } from '../models/user/user-notification-setting.js'+import { ChangeOwnershipModel } from '../models/video/change-ownership.js'import { ScheduleVideoUpdateModel } from '../models/video/schedule-video-update.js'import { TagModel } from '../models/video/tag.js'import { ThumbnailModel } from '../models/video/thumbnail.js'import { VideoBlacklistModel } from '../models/video/video-blacklist.js'import { VideoCaptionModel } from '../models/video/video-caption.js'-import { ChangeOwnershipModel } from '../models/video/change-ownership.js'import { VideoChannelModel } from '../models/video/video-channel.js'import { VideoCommentModel } from '../models/video/video-comment.js'import { VideoFileModel } from '../models/video/video-file.js'@@ -73,7 +74,6 @@ import { VideoShareModel } from '../models/video/video-share.js'import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist.js'import { VideoTagModel } from '../models/video/video-tag.js'import { VideoModel } from '../models/video/video.js'-import { VideoStatModel } from '../models/stat/video-stat.js'import { CONFIG } from './config.js'pg.defaults.parseInt8 = true // Avoid BIGINT to be converted to string@@ -237,7 +237,7 @@ async function checkPostgresExtensions () {return Promise.all(promises)}-async function checkPostgresExtension (extension: string) {+async function checkPostgresExtension (extension: 'pg_trgm' | 'unaccent') {const query = `SELECT 1 FROM pg_available_extensions WHERE name = '${extension}' AND installed_version IS NOT NULL;`const options = {type: QueryTypes.SELECT as QueryTypes.SELECT,diff --git a/server/core/models/actor/actor-follow.ts b/server/core/models/actor/actor-follow.tsindex 7e45d4af95..58071000eb 100644--- a/server/core/models/actor/actor-follow.ts+++ b/server/core/models/actor/actor-follow.ts@@ -1,4 +1,5 @@import { ActorFollow, type FollowState } from '@peertube/peertube-models'+import { isTestInstance } from '@peertube/peertube-node-utils'import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc.js'import { afterCommitIfTransaction } from '@server/helpers/database-utils.js'import { getServerActor } from '@server/models/application/application.js'@@ -47,7 +48,6 @@ import { VideoChannelModel } from '../video/video-channel.js'import { ActorModel, unusedActorAttributesForAPI } from './actor.js'import { InstanceListFollowersQueryBuilder, ListFollowersOptions } from './sql/instance-list-followers-query-builder.js'import { InstanceListFollowingQueryBuilder, ListFollowingOptions } from './sql/instance-list-following-query-builder.js'-import { isTestInstance } from '@peertube/peertube-node-utils'@Table({tableName: 'actorFollow',@@ -708,13 +708,17 @@ export class ActorFollowModel extends SequelizeModel<ActorFollowModel> {start?: numbercount?: number- columnUrl?: string // Default 'url'+ columnUrl?: 'url' | 'sharedInboxUrl' // Default 'url'distinct?: boolean // Default falseselectTotal?: boolean // Default true}) {const { type, actorIds, t, start, count, columnUrl = 'url', distinct = false, selectTotal = true } = options+ if (new Set([ 'url', 'sharedInboxUrl' ]).has(columnUrl) === false) {+ throw new Error('Invalid columnUrl')+ }+let firstJoin: stringlet secondJoin: stringdiff --git a/server/core/models/shared/sql/common-helpers.ts b/server/core/models/shared/sql/common-helpers.tsindex a7e05c50d8..13a8b6cc05 100644--- a/server/core/models/shared/sql/common-helpers.ts+++ b/server/core/models/shared/sql/common-helpers.ts@@ -1,7 +1,9 @@import { forceNumber } from '@peertube/peertube-core-utils'import { FollowState } from '@peertube/peertube-models'+import { sequelizeTypescript } from '@server/initializers/database.js'import { literal } from 'sequelize'import { Literal } from 'sequelize/types/utils'+import { createSafeIn } from '../query.js'// FIXME: have to specify the result type to not break peertube typings generationexport function buildLocalAccountIdsIn (): Literal {@@ -18,7 +20,7 @@ export function buildLocalActorIdsIn (): Literal {}export function buildBlockedAccountSQL (blockerIds: number[]) {- const blockerIdsString = blockerIds.join(', ')+ const blockerIdsString = createSafeIn(sequelizeTypescript, blockerIds)return 'SELECT "targetAccountId" AS "id" FROM "accountBlocklist" WHERE "accountId" IN (' + blockerIdsString + ')' +' UNION ' +diff --git a/server/core/models/shared/update.ts b/server/core/models/shared/update.tsindex b5c075aac2..ab1f5193dc 100644--- a/server/core/models/shared/update.ts+++ b/server/core/models/shared/update.ts@@ -5,11 +5,16 @@ const updating = new Set<string>()// Sequelize always skip the update if we only update updatedAt fieldexport async function setAsUpdated (options: {sequelize: Sequelize- table: string+ table: 'runnerJob' | 'actorFollow' | 'videoPlaylist' | 'video' | 'videoChannel'id: numbertransaction?: Transaction}) {const { sequelize, table, id, transaction } = options++ if (new Set([ 'runnerJob', 'actorFollow', 'videoPlaylist', 'video', 'videoChannel' ]).has(table) === false) {+ throw new Error('Invalid table')+ }+const key = table + '-' + idif (updating.has(key)) returndiff --git a/server/core/models/stat/local-video-viewer.ts b/server/core/models/stat/local-video-viewer.tsindex 05790b5730..3357bd9578 100644--- a/server/core/models/stat/local-video-viewer.ts+++ b/server/core/models/stat/local-video-viewer.ts@@ -387,6 +387,10 @@ export class LocalVideoViewerModel extends SequelizeModel<LocalVideoViewerModel>}) {const { groupByColumn, startDate, endDate, videoId } = options+ if (new Set([ 'country', 'subdivisionName', 'client', 'device', 'operatingSystem' ]).has(groupByColumn) === false) {+ throw new Error('Invalid groupByColumn')+ }+const queryOptions: QueryOptionsWithType<QueryTypes.SELECT> = {type: QueryTypes.SELECT as QueryTypes.SELECT,replacements: { videoId, startDate, endDate }diff --git a/server/core/models/video/video-comment.ts b/server/core/models/video/video-comment.tsindex 664f3e69c5..f7dcd1c455 100644--- a/server/core/models/video/video-comment.ts+++ b/server/core/models/video/video-comment.ts@@ -1,4 +1,4 @@-import { pick } from '@peertube/peertube-core-utils'+import { forceNumber, pick } from '@peertube/peertube-core-utils'import {ActivityTagObject,ActivityTombstoneObject,@@ -480,7 +480,7 @@ export class VideoCommentModel extends SequelizeModel<VideoCommentModel> {[Op.in]: Sequelize.literal('(' +'WITH RECURSIVE children (id, "inReplyToCommentId") AS ( ' +- `SELECT id, "inReplyToCommentId" FROM "videoComment" WHERE id = ${comment.id} ` ++ `SELECT id, "inReplyToCommentId" FROM "videoComment" WHERE id = ${forceNumber(comment.id)} ` +'UNION ' +'SELECT "parent"."id", "parent"."inReplyToCommentId" FROM "videoComment" "parent" ' +'INNER JOIN "children" ON "children"."inReplyToCommentId" = "parent"."id"' +diff --git a/server/core/models/video/video.ts b/server/core/models/video/video.tsindex cb8310afd8..d287d57a4b 100644--- a/server/core/models/video/video.ts+++ b/server/core/models/video/video.ts@@ -1,4 +1,4 @@-import { buildVideoEmbedPath, buildVideoWatchPath, maxBy, minBy, pick, wait } from '@peertube/peertube-core-utils'+import { buildVideoEmbedPath, buildVideoWatchPath, forceNumber, maxBy, minBy, pick, wait } from '@peertube/peertube-core-utils'import {FileStorage,ResultList,@@ -975,7 +975,9 @@ export class VideoModel extends SequelizeModel<VideoModel> {.then(rows => rows.map(r => r.id))}- static listAllAndSharedByActorForOutbox (actorId: number, start: number, count: number) {+ static listAllAndSharedByActorForOutbox (actorIdArg: number, start: number, count: number) {+ const actorId = forceNumber(actorIdArg)+function getRawQuery (select: string) {const queryVideo = 'SELECT ' + select + ' FROM "video" AS "Video" ' +'INNER JOIN "videoChannel" AS "VideoChannel" ON "VideoChannel"."id" = "Video"."channelId" ' +