aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/logs.ts52
1 files changed, 49 insertions, 3 deletions
diff --git a/server/middlewares/validators/logs.ts b/server/middlewares/validators/logs.ts
index 901d8ca64..324ba6915 100644
--- a/server/middlewares/validators/logs.ts
+++ b/server/middlewares/validators/logs.ts
@@ -1,11 +1,56 @@
1import express from 'express' 1import express from 'express'
2import { query } from 'express-validator' 2import { body, query } from 'express-validator'
3import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc'
3import { isStringArray } from '@server/helpers/custom-validators/search' 4import { isStringArray } from '@server/helpers/custom-validators/search'
4import { isValidLogLevel } from '../../helpers/custom-validators/logs' 5import { CONFIG } from '@server/initializers/config'
6import { HttpStatusCode } from '@shared/models'
7import {
8 isValidClientLogLevel,
9 isValidClientLogMessage,
10 isValidClientLogMeta,
11 isValidClientLogStackTrace,
12 isValidClientLogUserAgent,
13 isValidLogLevel
14} from '../../helpers/custom-validators/logs'
5import { isDateValid, toArray } from '../../helpers/custom-validators/misc' 15import { isDateValid, toArray } from '../../helpers/custom-validators/misc'
6import { logger } from '../../helpers/logger' 16import { logger } from '../../helpers/logger'
7import { areValidationErrors } from './shared' 17import { areValidationErrors } from './shared'
8 18
19const createClientLogValidator = [
20 body('message')
21 .custom(isValidClientLogMessage).withMessage('Should have a valid log message'),
22
23 body('url')
24 .custom(isUrlValid).withMessage('Should have a valid log url'),
25
26 body('level')
27 .custom(isValidClientLogLevel).withMessage('Should have a valid log message'),
28
29 body('stackTrace')
30 .optional()
31 .custom(isValidClientLogStackTrace).withMessage('Should have a valid log stack trace'),
32
33 body('meta')
34 .optional()
35 .custom(isValidClientLogMeta).withMessage('Should have a valid log meta'),
36
37 body('userAgent')
38 .optional()
39 .custom(isValidClientLogUserAgent).withMessage('Should have a valid log user agent'),
40
41 (req: express.Request, res: express.Response, next: express.NextFunction) => {
42 logger.debug('Checking createClientLogValidator parameters.', { parameters: req.query })
43
44 if (CONFIG.LOG.ACCEPT_CLIENT_LOG !== true) {
45 return res.sendStatus(HttpStatusCode.FORBIDDEN_403)
46 }
47
48 if (areValidationErrors(req, res)) return
49
50 return next()
51 }
52]
53
9const getLogsValidator = [ 54const getLogsValidator = [
10 query('startDate') 55 query('startDate')
11 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), 56 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
@@ -49,5 +94,6 @@ const getAuditLogsValidator = [
49 94
50export { 95export {
51 getLogsValidator, 96 getLogsValidator,
52 getAuditLogsValidator 97 getAuditLogsValidator,
98 createClientLogValidator
53} 99}