@mitcsutt/kiln-forms
Version:
Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui
27 lines (26 loc) • 1.63 kB
TypeScript
/**
* Limits for schema `pattern` rules (§10.4). A pattern from untrusted JSON runs
* against user input on every keystroke and on the server, so a catastrophic-backtracking pattern
* (`^(a+)+$`) is a denial of service. `parseFormSchema` rejects long patterns, nested quantifiers,
* repeated alternations and more than `MAX_UNBOUNDED_QUANTIFIERS` unbounded quantifiers; the
* compiled rule only tests values up to `MAX_PATTERN_INPUT` characters. Schema patterns are for
* simple formats (postcodes, phone numbers, codes) — put anything richer in a registered validator.
*/
/** Longest `pattern` source `parseFormSchema` accepts. */
export declare const MAX_PATTERN_LENGTH = 200;
/** Longest value a `pattern` rule tests; a longer value fails the rule without running the regex. */
export declare const MAX_PATTERN_INPUT = 256;
/**
* Most unbounded quantifiers (`*`, `+`, `{n,}`) a schema pattern may use (`^a*a*a*b$` is polynomial
* blow-up). A bounded quantifier with a range over `WIDE_RANGE` (`{0,50}`) counts too.
*/
export declare const MAX_UNBOUNDED_QUANTIFIERS = 2;
/** A bounded quantifier whose `max - min` exceeds this counts as unbounded. */
export declare const WIDE_RANGE = 10;
/**
* True when a repeated group contains a variable quantifier (star height above 1, e.g. `(a+)+`,
* `(\w*\s?)*`, `(x+){10}`; not `(\d{3})+`): the classic catastrophic-backtracking shape.
*/
export declare function hasNestedQuantifier(source: string): boolean;
/** Why a schema `pattern` is unsafe to run on untrusted input, or `undefined`. */
export declare function unsafePatternReason(source: string): string | undefined;