// engine/sandbox/env-sanitizer.ts — Strip dangerous env vars before exec (SPEC-742)
/**
 * Environment variables that can be used for library injection / exfiltration.
 * These are stripped from the child environment before spawning in the sandbox.
 */
const DANGEROUS_ENV_VARS = [
    'LD_PRELOAD',
    'LD_LIBRARY_PATH',
    'DYLD_INSERT_LIBRARIES',
    'DYLD_LIBRARY_PATH',
    'DYLD_FORCE_FLAT_NAMESPACE',
    'LD_AUDIT',
    'LD_DEBUG',
    'LD_DEBUG_OUTPUT',
];
/**
 * Strip dangerous environment variables from a process.env-like object.
 * Returns a new object with the dangerous vars removed.
 * Never mutates the input.
 */
export function sanitizeEnv(env) {
    const dangerousSet = new Set(DANGEROUS_ENV_VARS);
    const result = {};
    for (const [key, value] of Object.entries(env)) {
        if (dangerousSet.has(key)) {
            continue;
        }
        if (value !== undefined) {
            result[key] = value;
        }
    }
    return result;
}
/**
 * Returns true if the env contains any dangerous vars.
 * Used for detection/logging.
 */
export function hasDangerousEnvVars(env) {
    const dangerousSet = new Set(DANGEROUS_ENV_VARS);
    return Object.keys(env).some((k) => dangerousSet.has(k));
}
//# sourceMappingURL=env-sanitizer.js.map