Skip to content

normancarcamo/joi-xss

Repository files navigation

joi-xss

Avoid XSS with the help of Joi validator

Example

const xss = require('@ncardez/joi-xss');
const Joi = require('joi').extend(xss('object'), xss('array'), xss('string'));
  
const input = { name: "<p>hola</p>" };

// Return result.
const { value } = Joi.object().unknown(true).xss().validate(input);
//  value.name === '&lt;p&gt;hola&lt;/p&gt;'

// You can also pass options.
const { value } = Joi.object().unknown(true).xss({ stripIgnoreTag: true }).validate(input);
//  value.name === 'hola'

About

Avoid XSS with the help of Joi validator

Resources

License

Stars

Watchers

Forks

Packages

No packages published