Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.4 KB
Raw Blame
/**
 * Providers/hosts excluded from Chrome TLS impersonation (#13445, restored in #14062).
 * Cloudflare answers the spoofed Groq fingerprint with 1010 browser_signature_banned, so Groq
 * stays on the plain dispatcher even when TLS_FINGERPRINT_PROVIDERS lists it.
 */
function isGroqTlsFingerprintHost(url: string | null | undefined): boolean {
  if (!url) return false;
  try {
    const host = new URL(url).hostname.toLowerCase();
    return host === "api.groq.com" || host.endsWith(".groq.com");
  } catch {
    return /(?:^|[./])api\.groq\.com(?:[:/?]|$)/i.test(String(url));
  }
}

function isGroqTlsFingerprintExcluded(
  provider: string | null | undefined,
  url?: string | null
): boolean {
  return provider?.trim().toLowerCase() === "groq" || isGroqTlsFingerprintHost(url);
}

export function tlsFingerprintProviderAllowed(
  provider: string | null | undefined,
  proxied: boolean,
  url?: string | null
): boolean {
  if (isGroqTlsFingerprintExcluded(provider, url)) return false;
  const configured = process.env.TLS_FINGERPRINT_PROVIDERS?.trim();
  // Preserve the legacy direct-only opt-in. The new proxied transport requires
  // an explicit allowlist so enabling TLS cannot silently change proxy traffic.
  if (!configured) return !proxied;
  if (!provider) return false;
  const normalizedProvider = provider.trim().toLowerCase();
  return configured
    .split(",")
    .some((candidate) => candidate.trim().toLowerCase() === normalizedProvider);
}