From 4638cd713dcdd007cd7f49b9a95fa62ac7823e7c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 15 Nov 2022 14:41:55 +0100 Subject: Don't inject untrusted input Even if it's already checked in middlewares It's better to have safe modals too --- .../video/sql/video/videos-id-list-query-builder.ts | 5 +++-- server/models/video/video-channel.ts | 4 ++-- server/models/video/video-playlist-element.ts | 21 +++++++++++++-------- server/models/video/video-share.ts | 5 +++-- 4 files changed, 21 insertions(+), 14 deletions(-) (limited to 'server/models/video') diff --git a/server/models/video/sql/video/videos-id-list-query-builder.ts b/server/models/video/sql/video/videos-id-list-query-builder.ts index 14f903851..7c864bf27 100644 --- a/server/models/video/sql/video/videos-id-list-query-builder.ts +++ b/server/models/video/sql/video/videos-id-list-query-builder.ts @@ -6,6 +6,7 @@ import { buildDirectionAndField, createSafeIn, parseRowCountResult } from '@serv import { MUserAccountId, MUserId } from '@server/types/models' import { VideoInclude, VideoPrivacy, VideoState } from '@shared/models' import { AbstractRunQuery } from '../../../shared/abstract-run-query' +import { forceNumber } from '@shared/core-utils' /** * @@ -689,12 +690,12 @@ export class VideosIdListQueryBuilder extends AbstractRunQuery { } private setLimit (countArg: number) { - const count = parseInt(countArg + '', 10) + const count = forceNumber(countArg) this.limit = `LIMIT ${count}` } private setOffset (startArg: number) { - const start = parseInt(startArg + '', 10) + const start = forceNumber(startArg) this.offset = `OFFSET ${start}` } } diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 91dafbcf1..9e461b6ca 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -19,7 +19,7 @@ import { } from 'sequelize-typescript' import { CONFIG } from '@server/initializers/config' import { MAccountActor } from '@server/types/models' -import { pick } from '@shared/core-utils' +import { forceNumber, pick } from '@shared/core-utils' import { AttributesOnly } from '@shared/typescript-utils' import { ActivityPubActor } from '../../../shared/models/activitypub' import { VideoChannel, VideoChannelSummary } from '../../../shared/models/videos' @@ -280,7 +280,7 @@ export type SummaryOptions = { ] }, [ScopeNames.WITH_STATS]: (options: AvailableWithStatsOptions = { daysPrior: 30 }) => { - const daysPrior = parseInt(options.daysPrior + '', 10) + const daysPrior = forceNumber(options.daysPrior) return { attributes: { diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts index b45f15bd6..7181b5599 100644 --- a/server/models/video/video-playlist-element.ts +++ b/server/models/video/video-playlist-element.ts @@ -23,6 +23,7 @@ import { MVideoPlaylistElementVideoUrlPlaylistPrivacy, MVideoPlaylistVideoThumbnail } from '@server/types/models/video/video-playlist-element' +import { forceNumber } from '@shared/core-utils' import { AttributesOnly } from '@shared/typescript-utils' import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object' import { VideoPrivacy } from '../../../shared/models/videos' @@ -185,7 +186,9 @@ export class VideoPlaylistElementModel extends Model { - const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId } + const playlistWhere = validator.isUUID('' + playlistId) + ? { uuid: playlistId } + : { id: playlistId } const query = { include: [ @@ -262,13 +265,15 @@ export class VideoPlaylistElementModel extends Model position ? position + 1 : 1) } - static reassignPositionOf ( - videoPlaylistId: number, - firstPosition: number, - endPosition: number, - newPosition: number, + static reassignPositionOf (options: { + videoPlaylistId: number + firstPosition: number + endPosition: number + newPosition: number transaction?: Transaction - ) { + }) { + const { videoPlaylistId, firstPosition, endPosition, newPosition, transaction } = options + const query = { where: { videoPlaylistId, @@ -281,7 +286,7 @@ export class VideoPlaylistElementModel extends Model { - const safeOwnerId = parseInt(actorOwnerId + '', 10) + const safeOwnerId = forceNumber(actorOwnerId) // /!\ On actor model const query = { @@ -148,7 +149,7 @@ export class VideoShareModel extends Model { - const safeChannelId = parseInt(videoChannelId + '', 10) + const safeChannelId = forceNumber(videoChannelId) // /!\ On actor model const query = { -- cgit v1.2.3