mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2026-08-27 22:10:26 +02:00
Co-authored-by: Tomi Turtiainen <10324676+tomi@users.noreply.github.com>
34 lines
798 B
TypeScript
34 lines
798 B
TypeScript
import xss from 'xss';
|
|
import type { ValidationOptions, ValidatorConstraintInterface } from 'class-validator';
|
|
import { registerDecorator, ValidatorConstraint } from 'class-validator';
|
|
|
|
@ValidatorConstraint({ name: 'NoXss', async: false })
|
|
class NoXssConstraint implements ValidatorConstraintInterface {
|
|
validate(value: unknown) {
|
|
if (typeof value !== 'string') return false;
|
|
|
|
return (
|
|
value ===
|
|
xss(value, {
|
|
whiteList: {}, // no tags are allowed
|
|
})
|
|
);
|
|
}
|
|
|
|
defaultMessage() {
|
|
return 'Potentially malicious string';
|
|
}
|
|
}
|
|
|
|
export function NoXss(options?: ValidationOptions) {
|
|
return function (object: object, propertyName: string) {
|
|
registerDecorator({
|
|
name: 'NoXss',
|
|
target: object.constructor,
|
|
propertyName,
|
|
options,
|
|
validator: NoXssConstraint,
|
|
});
|
|
};
|
|
}
|