Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.
TypeScript cloud-alternativecollaborationcollaborative-editingdropboxfile-serverfile-sharingfile-storagefile-syncfull-text-searchhomelabnextcloudon-premiseopen-sourceprivacy-firstprivate-cloudrealtimesecureself-hostedstorage-serverwebdav
fix(backend:sync): add validation for path filter size, length, and repetitions
johaven0fdcda95cac6
diff --git a/backend/src/applications/sync/constants/sync.ts b/backend/src/applications/sync/constants/sync.tsindex d24be33e..fff402e7 100644--- a/backend/src/applications/sync/constants/sync.ts+++ b/backend/src/applications/sync/constants/sync.ts@@ -5,6 +5,9 @@ export const CHECK_SERVER_RESP = { server: SYNC_IN_SERVER_AGENT } as constexport const SYNC_CHECKSUM_ALG = 'sha512-256'export const SYNC_DIFF_DONE = 'done'export const SYNC_FILE_NAME_PREFIX = '.sync-in.'+export const SYNC_MAX_PATH_FILTERS = 100+export const SYNC_MAX_PATH_FILTER_LENGTH = 200+export const SYNC_MAX_PATH_FILTER_REPETITIONS = 25export enum SYNC_REPOSITORY {PERSONAL = SPACE_ALIAS.PERSONAL,diff --git a/backend/src/applications/sync/dtos/sync-path.dto.ts b/backend/src/applications/sync/dtos/sync-path.dto.tsindex d9f42e96..9f7acecd 100644--- a/backend/src/applications/sync/dtos/sync-path.dto.ts+++ b/backend/src/applications/sync/dtos/sync-path.dto.ts@@ -1,6 +1,13 @@import { Transform, Type } from 'class-transformer'-import { IsArray, IsBoolean, IsEnum, IsInt, IsNotEmpty, IsOptional, IsString, ValidateNested } from 'class-validator'-import { SYNC_PATH_CONFLICT_MODE, SYNC_PATH_DIFF_MODE, SYNC_PATH_MODE, SYNC_PATH_SCHEDULER_UNIT } from '../constants/sync'+import { ArrayMaxSize, IsArray, IsBoolean, IsEnum, IsInt, IsNotEmpty, IsOptional, IsString, MaxLength, ValidateNested } from 'class-validator'+import {+ SYNC_MAX_PATH_FILTER_LENGTH,+ SYNC_MAX_PATH_FILTERS,+ SYNC_PATH_CONFLICT_MODE,+ SYNC_PATH_DIFF_MODE,+ SYNC_PATH_MODE,+ SYNC_PATH_SCHEDULER_UNIT+} from '../constants/sync'import { SyncPathSettings } from '../interfaces/sync-path.interface'class SyncPathSchedulerDto {@@ -32,20 +39,23 @@ export class SyncPathDto implements SyncPathSettings {@IsString()permissions: string- @Transform(({ value }) => value.toLowerCase())+ @Transform(({ value }) => (typeof value === 'string' ? value.toLowerCase() : value))@IsEnum(SYNC_PATH_MODE)mode: SYNC_PATH_MODE- @Transform(({ value }) => value.toLowerCase())+ @Transform(({ value }) => (typeof value === 'string' ? value.toLowerCase() : value))@IsEnum(SYNC_PATH_DIFF_MODE)diffMode: SYNC_PATH_DIFF_MODE- @Transform(({ value }) => value.toLowerCase())+ @Transform(({ value }) => (typeof value === 'string' ? value.toLowerCase() : value))@IsEnum(SYNC_PATH_CONFLICT_MODE)conflictMode: SYNC_PATH_CONFLICT_MODE+ @Transform(({ value }) => (Array.isArray(value) ? value.map((filter) => (typeof filter === 'string' ? filter.trim() : filter)) : value))@IsArray()+ @ArrayMaxSize(SYNC_MAX_PATH_FILTERS)@IsString({ each: true })+ @MaxLength(SYNC_MAX_PATH_FILTER_LENGTH, { each: true })filters: string[]@Transform(({ value }) => (value ? value : { value: 0, unit: SYNC_PATH_SCHEDULER_UNIT.DISABLED }))diff --git a/backend/src/applications/sync/utils/functions.ts b/backend/src/applications/sync/utils/functions.tsindex ab78413e..c3b014c4 100644--- a/backend/src/applications/sync/utils/functions.ts+++ b/backend/src/applications/sync/utils/functions.ts@@ -1,10 +1,7 @@import { BadRequestException } from '@nestjs/common'import path from 'node:path'import safeRegex from 'safe-regex2'-import { SYNC_FILE_NAME_PREFIX } from '../constants/sync'--const MAX_PATH_FILTER_LENGTH = 200-const MAX_PATH_FILTER_REPETITIONS = 25+import { SYNC_FILE_NAME_PREFIX, SYNC_MAX_PATH_FILTER_LENGTH, SYNC_MAX_PATH_FILTER_REPETITIONS } from '../constants/sync'export function getSyncTmpFilePath(rPath: string): string {return `${path.dirname(rPath)}/${SYNC_FILE_NAME_PREFIX}${path.basename(rPath)}`@@ -15,7 +12,7 @@ export function transformPathFilters(value: unknown): RegExp | null {return null}- if (value.length > MAX_PATH_FILTER_LENGTH) {+ if (value.length > SYNC_MAX_PATH_FILTER_LENGTH) {throw new BadRequestException('Path filter pattern is too long')}@@ -26,7 +23,7 @@ export function transformPathFilters(value: unknown): RegExp | null {throw new BadRequestException('Invalid path filter pattern')}- if (!safeRegex(pathFilter, { limit: MAX_PATH_FILTER_REPETITIONS })) {+ if (!safeRegex(pathFilter, { limit: SYNC_MAX_PATH_FILTER_REPETITIONS })) {throw new BadRequestException('Unsafe path filter pattern')}