Disable browser cookie fallback for local X auth

Prefer injected AUTH_TOKEN/CT0 for bundled Bird, disable browser-cookie probing in repo-invoked subprocesses, and keep repo-invoked yt-dlp from inheriting browser-cookie settings.

Validation: uv run python -m unittest tests.test_bird_x tests.test_youtube_yt
This commit is contained in:
Jeffrey Sperling
2026-03-12 21:07:04 -07:00
parent e568ef8af9
commit dd9a3f1482
5 changed files with 115 additions and 2 deletions
+13 -1
View File
@@ -36,10 +36,19 @@ def set_credentials(auth_token: Optional[str], ct0: Optional[str]):
_credentials['CT0'] = ct0
def _has_injected_credentials() -> bool:
"""Return True when both X session cookies were injected from config."""
return bool(_credentials.get('AUTH_TOKEN') and _credentials.get('CT0'))
def _subprocess_env() -> Dict[str, str]:
"""Build env dict for Node subprocesses, merging injected credentials."""
env = os.environ.copy()
env.update(_credentials)
# When repo config already provides cookies, disable browser-cookie fallback
# so vendored Bird never hits Safari/Chrome keychain during automation.
if _has_injected_credentials():
env.setdefault("BIRD_DISABLE_BROWSER_COOKIES", "1")
return env
@@ -126,6 +135,9 @@ def is_bird_authenticated() -> Optional[str]:
if not is_bird_installed():
return None
if _has_injected_credentials():
return "env AUTH_TOKEN"
try:
result = subprocess.run(
["node", str(_BIRD_SEARCH_MJS), "--whoami"],
@@ -473,4 +485,4 @@ def parse_bird_response(response: Dict[str, Any]) -> List[Dict[str, Any]]:
items.append(item)
return items
return items
+19 -1
View File
@@ -14,6 +14,13 @@ function normalizeValue(value) {
const trimmed = value.trim();
return trimmed.length > 0 ? trimmed : null;
}
function envFlagEnabled(name) {
const value = normalizeValue(process.env[name]);
if (!value) {
return false;
}
return ['1', 'true', 'yes', 'on'].includes(value.toLowerCase());
}
function cookieHeader(authToken, ct0) {
return `auth_token=${authToken}; ct0=${ct0}`;
}
@@ -123,6 +130,8 @@ export async function extractCookiesFromFirefox(profile) {
export async function resolveCredentials(options) {
const warnings = [];
const cookies = buildEmpty();
const disableBrowserCookies = envFlagEnabled('BIRD_DISABLE_BROWSER_COOKIES') ||
envFlagEnabled('LAST30DAYS_DISABLE_BROWSER_COOKIES');
const cookieTimeoutMs = typeof options.cookieTimeoutMs === 'number' &&
Number.isFinite(options.cookieTimeoutMs) &&
options.cookieTimeoutMs > 0
@@ -146,6 +155,15 @@ export async function resolveCredentials(options) {
cookies.cookieHeader = cookieHeader(cookies.authToken, cookies.ct0);
return { cookies, warnings };
}
if (disableBrowserCookies) {
if (!cookies.authToken) {
warnings.push('Missing auth_token - provide via --auth-token, AUTH_TOKEN env var, or disable BIRD_DISABLE_BROWSER_COOKIES to allow browser cookie lookup');
}
if (!cookies.ct0) {
warnings.push('Missing ct0 - provide via --ct0, CT0 env var, or disable BIRD_DISABLE_BROWSER_COOKIES to allow browser cookie lookup');
}
return { cookies, warnings };
}
const sourcesToTry = resolveSources(options.cookieSource);
for (const source of sourcesToTry) {
const res = await readTwitterCookiesFromBrowser({
@@ -170,4 +188,4 @@ export async function resolveCredentials(options) {
}
return { cookies, warnings };
}
//# sourceMappingURL=cookies.js.map
//# sourceMappingURL=cookies.js.map
+4
View File
@@ -176,6 +176,8 @@ def search_youtube(
# filtering returns 0 for evergreen topics like "thumbnail tips".
cmd = [
"yt-dlp",
"--ignore-config",
"--no-cookies-from-browser",
f"ytsearch{count}:{core_topic}",
"--dump-json",
"--no-warnings",
@@ -295,6 +297,8 @@ def fetch_transcript(video_id: str, temp_dir: str) -> Optional[str]:
"""
cmd = [
"yt-dlp",
"--ignore-config",
"--no-cookies-from-browser",
"--write-auto-subs",
"--sub-lang", "en",
"--sub-format", "vtt",