/** * FHIRPath Sandbox (P-3) * * Static safety pre-flight for user-defined FHIRPath expressions * (Custom Rules). fhirpath.js is synchronous and cannot be hard-timed * out from the calling thread without a worker, so the only reliable * defence against a pathological customer-supplied expression is to * reject it before it runs. * * The sandbox enforces three bounds: * * - **expressionLength**: total characters. Defaults to 4096. * - **functionCallCount**: total `name(...)` invocations. Defaults * to 64. * - **nestingDepth**: maximum parenthesis depth. Defaults to 16. * * The bounds are deliberately generous for legitimate validation * expressions (the largest core constraints in HL7's FHIR shipped * package — `dom-2`/`dom-3`/`dom-4`/`dom-5`/`dom-6` plus the * `compliesWith` family — sit comfortably under all three limits) but * tight enough to reject the common DoS shapes: unbounded `repeat()` * recursion, deeply-nested `where(where(where(...)))`, and * megabyte-sized regex strings inside `matches()`. * * Runs in microseconds — single linear pass over the expression * string, no fhirpath parser involvement, no `eval`. */ export interface SandboxLimits { /** Maximum total characters in the expression. */ expressionLength?: number; /** Maximum number of `name(...)` function calls. */ functionCallCount?: number; /** Maximum parenthesis nesting depth. */ nestingDepth?: number; } export interface SandboxResult { /** True when every limit was respected. */ ok: boolean; /** Human-readable rejection reason when `ok` is false. */ reason?: string; /** Measured metrics — exposed for ops dashboards / logging. */ metrics: { expressionLength: number; functionCallCount: number; nestingDepth: number; }; } /** * Statically analyse a FHIRPath expression string against the * configured limits. * * The function-call detector counts identifiers immediately followed * by `(`. This catches both built-ins (`where(`, `exists(`, * `iif(`, `repeat(`) and user-defined names — the customer's intent * doesn't matter; what matters is that an expression with hundreds of * `where(...)` calls is treated as suspicious regardless. * * Identifiers inside string literals are not counted. The walk skips * single- and double-quoted spans (with backslash escape handling) * because a regex argument like `matches('a(b|c)+d')` should not * inflate the function-call count. */ export declare function checkFhirpathSandbox(expression: string, limits?: SandboxLimits): SandboxResult; //# sourceMappingURL=fhirpath-sandbox.d.ts.map