n8n/packages/cli/src/databases/utils/customValidators.ts
Milorad FIlipović 2064f7f251
fix(editor): Validate user info before submiting (#7608)
Validate first and last names before saving them to database. This
should prevent security issue with un-sanitized data that ends up in
emails.

---------

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
2023-11-22 12:14:44 +01:00

20 lines
517 B
TypeScript

/* eslint-disable @typescript-eslint/naming-convention */
import { registerDecorator } from 'class-validator';
export function NoXss() {
return (object: object, propertyName: string): void => {
registerDecorator({
name: 'NoXss',
target: object.constructor,
propertyName,
constraints: [propertyName],
options: { message: `Malicious ${propertyName}` },
validator: {
validate(value: string) {
return !/(^http|^www)|<(\s*)?(script|a)|(\.[\p{L}\d-]+)/u.test(value);
},
},
});
};
}