From a767a944303a92a382798f83a0f95ec5f8211445 Mon Sep 17 00:00:00 2001 From: Jonas Lochmann Date: Mon, 5 Oct 2020 02:00:00 +0200 Subject: [PATCH] Add checking the package name and activity name length --- src/database/app.ts | 2 ++ src/database/appactivity.ts | 3 +++ .../addinstalledapps.ts | 14 ++++++++++++-- .../updateappactivities.ts | 19 ++++++++++++++++++- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/database/app.ts b/src/database/app.ts index 9eaadb1..69f50c6 100644 --- a/src/database/app.ts +++ b/src/database/app.ts @@ -34,6 +34,8 @@ export type AppModelStatic = typeof Sequelize.Model & { new (values?: object, options?: Sequelize.BuildOptions): AppModel; } +export const maxPackageNameLength = 255 + export const attributes: SequelizeAttributes = { familyId: { ...familyIdColumn, diff --git a/src/database/appactivity.ts b/src/database/appactivity.ts index c04922f..e23ab15 100644 --- a/src/database/appactivity.ts +++ b/src/database/appactivity.ts @@ -32,6 +32,9 @@ export type AppActivityModelStatic = typeof Sequelize.Model & { new (values?: object, options?: Sequelize.BuildOptions): AppActivityModel; } +export const maxPackageNameLength = 255 +export const maxActivityNameLength = 255 + export const attributes: SequelizeAttributes = { familyId: { ...familyIdColumn, diff --git a/src/function/sync/apply-actions/dispatch-app-logic-action/addinstalledapps.ts b/src/function/sync/apply-actions/dispatch-app-logic-action/addinstalledapps.ts index 6c7d0b1..013b27e 100644 --- a/src/function/sync/apply-actions/dispatch-app-logic-action/addinstalledapps.ts +++ b/src/function/sync/apply-actions/dispatch-app-logic-action/addinstalledapps.ts @@ -1,6 +1,6 @@ /* * server component for the TimeLimit App - * Copyright (C) 2019 Jonas Lochmann + * Copyright (C) 2019 - 2020 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,14 +17,24 @@ import * as Sequelize from 'sequelize' import { AddInstalledAppsAction } from '../../../../action' -import { AppAttributes } from '../../../../database/app' +import { AppAttributes, maxPackageNameLength } from '../../../../database/app' import { Cache } from '../cache' +import { ApplyActionException } from '../exception' export async function dispatchAddInstalledApps ({ deviceId, action, cache }: { deviceId: string action: AddInstalledAppsAction cache: Cache }) { + action.apps.forEach((app) => { + if (app.packageName.length > maxPackageNameLength) { + throw new ApplyActionException({ + staticMessage: 'package name too long', + dynamicMessage: 'package name too long: ' + app.packageName + }) + } + }) + await cache.database.app.destroy({ where: { familyId: cache.familyId, diff --git a/src/function/sync/apply-actions/dispatch-app-logic-action/updateappactivities.ts b/src/function/sync/apply-actions/dispatch-app-logic-action/updateappactivities.ts index 7514880..82ea302 100644 --- a/src/function/sync/apply-actions/dispatch-app-logic-action/updateappactivities.ts +++ b/src/function/sync/apply-actions/dispatch-app-logic-action/updateappactivities.ts @@ -18,14 +18,31 @@ import { chunk } from 'lodash' import * as Sequelize from 'sequelize' import { UpdateAppActivitiesAction } from '../../../../action' -import { AppActivityAttributes } from '../../../../database/appactivity' +import { AppActivityAttributes, maxActivityNameLength, maxPackageNameLength } from '../../../../database/appactivity' import { Cache } from '../cache' +import { ApplyActionException } from '../exception' export async function dispatchUpdateAppActivities ({ deviceId, action, cache }: { deviceId: string action: UpdateAppActivitiesAction cache: Cache }) { + action.updatedOrAdded.forEach((app) => { + if (app.packageName.length > maxPackageNameLength) { + throw new ApplyActionException({ + staticMessage: 'package name too long', + dynamicMessage: 'package name too long: ' + app.packageName + }) + } + + if (app.activityName.length > maxActivityNameLength) { + throw new ApplyActionException({ + staticMessage: 'activity name too long', + dynamicMessage: 'activity name too long: ' + app.activityName + }) + } + }) + if (action.updatedOrAdded.length > 0) { const chuncks = chunk(action.updatedOrAdded, 500)