How to use the express-validator.sanitizeQuery function in express-validator

To help you get started, we’ve selected a few express-validator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mserajnik / hyve / services / server / src / middleware / files.js View on Github external
const {
  check,
  validationResult,
  sanitizeParam,
  sanitizeQuery
} = require('express-validator')

const constraintsHelper = require('../util/constraints')

module.exports = {
  get: {
    inputValidationConfig: [
      sanitizeQuery('page').trim(),
      check('page')
        .exists().withMessage('MissingPageParameterError')
        .isInt({ min: 1 }).withMessage('InvalidPageParameterError'),
      sanitizeQuery('tags'),
      check('tags')
        .optional()
        .isArray({ min: 1 }).withMessage('InvalidTagsParameterError')
        .custom(tags => {
          for (const tag of tags) {
            if (['*', '**', '-', '-*', '-**'].includes(tag)) {
              return false
            }
          }

          return true
        }).withMessage('InvalidTagsParameterError'),
github mserajnik / hyve / services / server / src / middleware / files.js View on Github external
'id',
            'size',
            'width',
            'height',
            'mime',
            'tags',
            'namespaces',
            'random'
          ]
        ).withMessage('InvalidSortParameterError'),
      sanitizeQuery('direction').trim(),
      check('direction')
        .optional({ nullable: true, checkFalsy: true })
        .isString().withMessage('InvalidDirectionParameterError')
        .isIn(['asc', 'desc']).withMessage('InvalidDirectionParameterError'),
      sanitizeQuery('namespaces'),
      check('namespaces')
        .optional()
        .isArray({ min: 1 }).withMessage('InvalidNamespacesParameterError')
    ],
    validateInput: (req, res, next) => {
      const err = validationResult(req)

      if (!err.isEmpty()) {
        return next({
          customStatus: 400,
          customName: err.array()[0].msg
        })
      }

      if (req.query.sort === 'namespaces' && !req.query.namespaces) {
        return next({
github mserajnik / hyve / services / server / src / middleware / files.js View on Github external
return true
        }).withMessage('InvalidTagsParameterError'),
      sanitizeQuery('constraints'),
      check('constraints')
        .optional()
        .isArray({ min: 1 }).withMessage('InvalidConstraintsParameterError')
        .custom(constraints => {
          for (const constraint of constraints) {
            if (!constraintsHelper.isValidConstraint(constraint)) {
              return false
            }
          }

          return true
        }).withMessage('InvalidConstraintsParameterError'),
      sanitizeQuery('sort').trim(),
      check('sort')
        .optional({ nullable: true, checkFalsy: true })
        .isString().withMessage('InvalidSortParameterError')
        .isIn(
          [
            'id',
            'size',
            'width',
            'height',
            'mime',
            'tags',
            'namespaces',
            'random'
          ]
        ).withMessage('InvalidSortParameterError'),
      sanitizeQuery('direction').trim(),
github mserajnik / hyve / services / server / src / middleware / files.js View on Github external
.exists().withMessage('MissingPageParameterError')
        .isInt({ min: 1 }).withMessage('InvalidPageParameterError'),
      sanitizeQuery('tags'),
      check('tags')
        .optional()
        .isArray({ min: 1 }).withMessage('InvalidTagsParameterError')
        .custom(tags => {
          for (const tag of tags) {
            if (['*', '**', '-', '-*', '-**'].includes(tag)) {
              return false
            }
          }

          return true
        }).withMessage('InvalidTagsParameterError'),
      sanitizeQuery('constraints'),
      check('constraints')
        .optional()
        .isArray({ min: 1 }).withMessage('InvalidConstraintsParameterError')
        .custom(constraints => {
          for (const constraint of constraints) {
            if (!constraintsHelper.isValidConstraint(constraint)) {
              return false
            }
          }

          return true
        }).withMessage('InvalidConstraintsParameterError'),
      sanitizeQuery('sort').trim(),
      check('sort')
        .optional({ nullable: true, checkFalsy: true })
        .isString().withMessage('InvalidSortParameterError')
github mserajnik / hyve / services / server / src / middleware / files.js View on Github external
check,
  validationResult,
  sanitizeParam,
  sanitizeQuery
} = require('express-validator')

const constraintsHelper = require('../util/constraints')

module.exports = {
  get: {
    inputValidationConfig: [
      sanitizeQuery('page').trim(),
      check('page')
        .exists().withMessage('MissingPageParameterError')
        .isInt({ min: 1 }).withMessage('InvalidPageParameterError'),
      sanitizeQuery('tags'),
      check('tags')
        .optional()
        .isArray({ min: 1 }).withMessage('InvalidTagsParameterError')
        .custom(tags => {
          for (const tag of tags) {
            if (['*', '**', '-', '-*', '-**'].includes(tag)) {
              return false
            }
          }

          return true
        }).withMessage('InvalidTagsParameterError'),
      sanitizeQuery('constraints'),
      check('constraints')
        .optional()
        .isArray({ min: 1 }).withMessage('InvalidConstraintsParameterError')
github mserajnik / hyve / services / server / src / middleware / files.js View on Github external
check('sort')
        .optional({ nullable: true, checkFalsy: true })
        .isString().withMessage('InvalidSortParameterError')
        .isIn(
          [
            'id',
            'size',
            'width',
            'height',
            'mime',
            'tags',
            'namespaces',
            'random'
          ]
        ).withMessage('InvalidSortParameterError'),
      sanitizeQuery('direction').trim(),
      check('direction')
        .optional({ nullable: true, checkFalsy: true })
        .isString().withMessage('InvalidDirectionParameterError')
        .isIn(['asc', 'desc']).withMessage('InvalidDirectionParameterError'),
      sanitizeQuery('namespaces'),
      check('namespaces')
        .optional()
        .isArray({ min: 1 }).withMessage('InvalidNamespacesParameterError')
    ],
    validateInput: (req, res, next) => {
      const err = validationResult(req)

      if (!err.isEmpty()) {
        return next({
          customStatus: 400,
          customName: err.array()[0].msg