Added getLog schema validation + removed loggingSecurity class
ADD
src/assets/server/rest/v1/schemas/logging/logging-get.json
+{
+ "title": "Get Logging",
+ "description": "",
+ "type": "object",
+ "properties": {
+ "ID": {
+ "$ref": "common.json#/definitions/id"
+ }
+ },
+ "required": [
+ "ID"
+ ]
+}

MODIFY
src/server/rest/v1/service/LoggingService.ts
src/server/rest/v1/service/LoggingService.ts
@@ -8,7 +8,6 @@ import Constants from '../../../../utils/Constants';
import { DataResult } from '../../../../types/DataResult';
import { HTTPAuthError } from '../../../../types/HTTPError';
import { Log } from '../../../../types/Log';
-import LoggingSecurity from './security/LoggingSecurity';
import LoggingStorage from '../../../../storage/mongodb/LoggingStorage';
import LoggingValidator from '../validator/LoggingValidator';
import { ServerAction } from '../../../../types/Server';
@@ -34,7 +33,7 @@ export default class LoggingService {
public static async handleGetLog(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = LoggingSecurity.filterLogRequest(req.query);
+ const filteredRequest = LoggingValidator.getInstance().validateLoggingGetReq(req.query);
// Check auth
if (!await Authorizations.canReadLog(req.user)) {
throw new AppAuthError({
@@ -139,7 +138,7 @@ export default class LoggingService {
}, {
limit: filteredRequest.Limit,
skip: filteredRequest.Skip,
- sort: filteredRequest.SortFields,
+ sort: UtilsService.httpSortFieldsToMongoDB(filteredRequest.SortFields),
onlyRecordCount: filteredRequest.OnlyRecordCount
}, [
'id', 'level', 'timestamp', 'type', 'source', 'host', 'process', 'action', 'message',

DELETE
src/server/rest/v1/service/security/LoggingSecurity.ts
-import { HttpLogRequest, HttpLogsRequest } from '../../../../../types/requests/HttpLoggingRequest';
-
-import UtilsSecurity from './UtilsSecurity';
-import sanitize from 'mongo-sanitize';
-
-export default class LoggingSecurity {
- static filterLogsRequest(request: any): HttpLogsRequest {
- const filteredRequest = {} as HttpLogsRequest;
- // Get logs
- filteredRequest.StartDateTime = sanitize(request.StartDateTime);
- filteredRequest.EndDateTime = sanitize(request.EndDateTime);
- filteredRequest.Level = sanitize(request.Level);
- filteredRequest.Source = sanitize(request.Source);
- filteredRequest.Host = sanitize(request.Host);
- filteredRequest.Search = sanitize(request.Search);
- filteredRequest.SortDate = sanitize(request.SortDate);
- filteredRequest.Type = sanitize(request.Type);
- filteredRequest.Action = sanitize(request.Action);
- filteredRequest.UserID = sanitize(request.UserID);
- UtilsSecurity.filterSkipAndLimit(request, filteredRequest);
- UtilsSecurity.filterSort(request, filteredRequest);
- return filteredRequest;
- }
-
- static filterLogRequest(request: any): HttpLogRequest {
- return {
- ID: sanitize(request.ID)
- };
- }
-}
-

MODIFY
src/server/rest/v1/validator/LoggingValidator.ts
src/server/rest/v1/validator/LoggingValidator.ts
-import { HttpLogsRequest } from '../../../../types/requests/HttpLoggingRequest';
+import { HttpLogRequest, HttpLogsRequest } from '../../../../types/requests/HttpLoggingRequest';
+
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from './SchemaValidator';
import fs from 'fs';
@@ -7,10 +8,12 @@ import global from '../../../../types/GlobalType';
export default class LoggingValidator extends SchemaValidator {
private static instance: LoggingValidator|null = null;
private loggingsGet: Schema;
+ private loggingGet: Schema;
private constructor() {
super('LoggingValidator');
- this.loggingsGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/loggings/loggings-get.json`, 'utf8'));
+ this.loggingsGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/logging/loggings-get.json`, 'utf8'));
+ this.loggingGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/logging/logging-get.json`, 'utf8'));
}
public static getInstance(): LoggingValidator {
@@ -25,4 +28,10 @@ export default class LoggingValidator extends SchemaValidator {
this.validate(this.loggingsGet, data);
return data;
}
+
+ public validateLoggingGetReq(data: any): HttpLogRequest {
+ // Validate schema
+ this.validate(this.loggingGet, data);
+ return data;
+ }
}

MODIFY
src/types/requests/HttpLoggingRequest.ts
src/types/requests/HttpLoggingRequest.ts
@@ -14,7 +14,6 @@ export interface HttpLogsRequest extends HttpDatabaseRequest {
Level: LogLevel;
Source: string;
Host: string;
- SortDate: string;
Type: LogType;
Action: string;
UserID: string;

Added getLog schema validation + removed loggingSecurity class