Files
twenty/packages/twenty-server/src/engine/metadata-modules/remote-server/utils/validate-remote-server-input.utils.ts
T
Thomas TrompetteandGitHub a15884ea0a Add exceptions for metadata modules (#6070)
Class exception for each metadata module + handler to map on graphql
error

TODO left :
- find a way to call handler on auto-resolvers nestjs query (probably
interceptors)
- discuss what should be done for pre-hooks errors
- discuss what should be done for Unauthorized exception
2024-07-01 13:49:17 +02:00

33 lines
837 B
TypeScript

import { isDefined } from 'class-validator';
import {
RemoteServerException,
RemoteServerExceptionCode,
} from 'src/engine/metadata-modules/remote-server/remote-server.exception';
const INPUT_REGEX = /^([A-Za-z0-9\-_.@]+)$/;
export const validateObjectAgainstInjections = (input: object) => {
for (const [key, value] of Object.entries(input)) {
// Password are encrypted so we don't need to validate them
if (key === 'password') {
continue;
}
if (!isDefined(value)) {
continue;
}
validateStringAgainstInjections(value.toString());
}
};
export const validateStringAgainstInjections = (input: string) => {
if (!INPUT_REGEX.test(input)) {
throw new RemoteServerException(
'Invalid remote server input',
RemoteServerExceptionCode.INVALID_REMOTE_SERVER_INPUT,
);
}
};