Skip to content

The open alternative to Salesforce, designed for AI.

642 B
Raw Blame
// Any new pattern must be reviewed for SQL injection before being allowlisted
const ALLOWED_INDEX_WHERE_CLAUSES = new Set([
  '"deletedAt" IS NULL',
  '"_isPrivate"',
]);

export const validateAndReturnIndexWhereClause = (
  clause: string | null | undefined,
): string | undefined => {
  if (!clause) {
    return undefined;
  }

  if (ALLOWED_INDEX_WHERE_CLAUSES.has(clause)) {
    return clause;
  }

  throw new Error(
    `Unsupported index WHERE clause: "${clause}". ` +
      'Only allowlisted patterns are permitted to prevent SQL injection. ' +
      'Add the pattern to ALLOWED_INDEX_WHERE_CLAUSES after security review.',
  );
};