Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

1.0 KB
Raw Blame
import { logger } from '@librechat/data-schemas';

const TRUTHY = new Set(['true', '1', 'yes', 'on', 'enabled']);
const FALSY = new Set(['false', '0', 'no', 'off', 'disabled', 'none']);

export function normalizeEnvValue(value: string | undefined): string {
  return value == null ? '' : value.trim().toLowerCase();
}

export function isFalsyEnvValue(value: string): boolean {
  return FALSY.has(value);
}

/**
 * Resolves a security toggle. Unrecognized values warn and fall back rather than
 * being treated as the opposite of the default, so a typo cannot silently flip a
 * deployment into the riskier setting.
 */
export function parseEnvSwitch(
  name: string,
  value: string | undefined,
  fallback: boolean,
): boolean {
  const normalized = normalizeEnvValue(value);
  if (normalized === '') {
    return fallback;
  }
  if (TRUTHY.has(normalized)) {
    return true;
  }
  if (FALSY.has(normalized)) {
    return false;
  }
  logger.warn(`[SecurityHeaders] Ignoring invalid ${name}="${value}"; using ${fallback}.`);
  return fallback;
}