Spaces:
Paused
Paused
icebear0828 Claude Opus 4.6 commited on
Commit ·
38895cf
1
Parent(s): 6b3630b
fix: use known-profile list instead of runtime detection for TLS impersonation
Browse filesThe previous testProfile() approach using `curl -V` never validated
the --impersonate target. Worse, v1.5.x silently accepts unknown
profiles but applies NO impersonation (JA3 fingerprint = bare curl).
Replace runtime detection with a deterministic known-profile list.
Any configured chromeN is mapped to the nearest supported version
(e.g. chrome137 → chrome136). This works reliably across all
curl-impersonate versions.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
105 unmodified lines1061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431449 unmodified lines154155156157158159160161162163164165166105 unmodified linesreturn _resolved;}/** Test if a specific --impersonate profile is accepted by the binary. */function testProfile(binary: string, profile: string): boolean {try {execFileSync(binary, ["--impersonate", profile, "-V"], {encoding: "utf-8",timeout: 5000,stdio: ["ignore", "pipe", "pipe"],});return true;} catch {return false;}}/*** Find a working impersonate profile.* Tries the configured profile first, then descends Chrome versions.*/function resolveProfile(binary: string, configured: string): string | null {if (testProfile(binary, configured)) return configured;const match = configured.match(/^chrome(\d+)/);if (!match) return null;const ver = parseInt(match[1], 10);for (let v = ver - 1; v >= ver - 10 && v > 0; v--) {const candidate = `chrome${v}`;if (testProfile(binary, candidate)) {console.warn(`[TLS] Profile "${configured}" not supported, using "${candidate}"`);return candidate;}}return null;}/**9 unmodified lines});if (helpOutput.includes("--impersonate")) {const configured = getConfig().tls.impersonate_profile ?? "chrome136";const profile = resolveProfile(binary, configured);if (profile) {_resolvedProfile = profile;console.log(`[TLS] Using --impersonate ${profile}`);return ["--impersonate", profile];}console.warn("[TLS] No supported impersonate profile found, using manual TLS args");}} catch {// --help failed, fall back to manual args105 unmodified lines1061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381399 unmodified lines149150151152153154155156157158105 unmodified linesreturn _resolved;}/*** Chrome versions with distinct TLS fingerprints in curl-impersonate.* Only these versions are valid --impersonate targets.* Sorted ascending — update when curl-impersonate adds new profiles.*/const KNOWN_CHROME_PROFILES = [99, 100, 101, 104, 107, 110, 116, 119, 120, 123, 124, 131, 136];/*** Map a configured profile to the nearest known-supported version.* e.g. "chrome137" → "chrome136", "chrome125" → "chrome124"* Non-chrome profiles (e.g. "firefox") are passed through unchanged.*/function resolveProfile(configured: string): string {const match = configured.match(/^chrome(\d+)$/);if (!match) return configured;const ver = parseInt(match[1], 10);let best: number | undefined;for (const known of KNOWN_CHROME_PROFILES) {if (known <= ver) best = known;}if (!best) return configured;const resolved = `chrome${best}`;if (resolved !== configured) {console.warn(`[TLS] Profile "${configured}" not in known targets, using "${resolved}"`);}return resolved;}/**9 unmodified lines});if (helpOutput.includes("--impersonate")) {const configured = getConfig().tls.impersonate_profile ?? "chrome136";const profile = resolveProfile(configured);_resolvedProfile = profile;console.log(`[TLS] Using --impersonate ${profile}`);return ["--impersonate", profile];}} catch {// --help failed, fall back to manual args
src/tls/curl-binary.ts+26-34