security: never print cookie-file content; scrub credential URLs from worker-appended error log lines

This commit is contained in:
juancarlos.cavero 2026-07-18 02:38:16 +02:00
parent 6430819dac
commit b9aeaac692
2 changed files with 6 additions and 5 deletions

6
app.py
View file

@ -690,11 +690,13 @@ async def run_job(job_id, job_data):
jobs[job_id]['logs'].append("No metadata file generated.") jobs[job_id]['logs'].append("No metadata file generated.")
else: else:
jobs[job_id]['status'] = 'failed' jobs[job_id]['status'] = 'failed'
jobs[job_id]['logs'].append(f"Process failed with exit code {returncode}") jobs[job_id]['logs'].append(_scrub_secrets(f"Process failed with exit code {returncode}"))
except Exception as e: except Exception as e:
jobs[job_id]['status'] = 'failed' jobs[job_id]['status'] = 'failed'
jobs[job_id]['logs'].append(f"Execution error: {str(e)}") # Exception text can embed URLs with credentials (e.g. the proxy URL
# inside a yt-dlp/httpx error) — scrub before it reaches client logs.
jobs[job_id]['logs'].append(_scrub_secrets(f"Execution error: {str(e)}"))
@app.get("/health") @app.get("/health")
async def health(): async def health():

View file

@ -474,10 +474,9 @@ def download_youtube_video(url, output_dir="."):
with open(cookies_path, 'w') as f: with open(cookies_path, 'w') as f:
f.write(cookies_env) f.write(cookies_env)
if os.path.exists(cookies_path): if os.path.exists(cookies_path):
# Never print file CONTENT here: with a headerless cookies
# blob this would leak live YouTube session cookies to logs.
print(f" Debug: Cookies file created. Size: {os.path.getsize(cookies_path)} bytes") print(f" Debug: Cookies file created. Size: {os.path.getsize(cookies_path)} bytes")
with open(cookies_path, 'r') as f:
content = f.read(100)
print(f" Debug: First 100 chars of cookie file: {content}")
except Exception as e: except Exception as e:
print(f"⚠️ Failed to write cookies file: {e}") print(f"⚠️ Failed to write cookies file: {e}")
cookies_path = None cookies_path = None