Files
OmniRoute/src/shared/utils/envBoolean.ts
Ravi Tharuma 4fd1f0f15c fix(guardrails): align INPUT_SANITIZER request masking gate (#8093) (#8124)
Scoped to guardrails/security: dropped the unrelated js-yaml/tar/shell-quote/
brace-expansion override bumps, and isolated sanitizer-residual-policy.test.ts
to a tmp DATA_DIR so it no longer touches the real storage.sqlite.

Co-authored-by: RaviTharuma <RaviTharuma@users.noreply.github.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
Co-authored-by: rafaumeu <rafael.zendron22@gmail.com>
2026-07-23 04:50:43 -03:00

22 lines
655 B
TypeScript

/**
* Shared env/flag boolean parsing for security guards.
*
* Truthy: true / 1 / yes / on (case-insensitive, trimmed)
* Falsy: false / 0 / no / off
* Unset/empty/unknown → fallback
*
* @module shared/utils/envBoolean
*/
export function parseEnvBoolean(
value: string | undefined | null,
fallback: boolean
): boolean {
if (value === undefined || value === null) return fallback;
const normalized = String(value).trim().toLowerCase();
if (normalized === "") return fallback;
if (["1", "true", "yes", "on"].includes(normalized)) return true;
if (["0", "false", "no", "off"].includes(normalized)) return false;
return fallback;
}