From 12c1b8e1d517e1bc87e4fd2423dc0a0648983df9 Mon Sep 17 00:00:00 2001 From: "juancarlos.cavero" Date: Wed, 6 May 2026 11:55:12 +0200 Subject: [PATCH] feat: Require ownership attestation before processing a video - MediaInput shows a checkbox the user must tick before Generate enables - Frontend sends acknowledged=true alongside URL/file payload - /api/process rejects with 400 if attestation is missing, and records IP/UA/timestamp/source on the job for legal record-keeping Defensive posture for the public deployment: shifts responsibility to the user via an explicit affirmative act, even without login. Co-Authored-By: Claude Opus 4.7 (1M context) --- app.py | 42 +++++++++++++++++++------ dashboard/src/App.jsx | 3 +- dashboard/src/components/MediaInput.jsx | 22 ++++++++++--- 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/app.py b/app.py index e3c3c8d..0da7234 100644 --- a/app.py +++ b/app.py @@ -317,43 +317,64 @@ async def get_config(): async def process_endpoint( request: Request, file: Optional[UploadFile] = File(None), - url: Optional[str] = Form(None) + url: Optional[str] = Form(None), + acknowledged: Optional[str] = Form(None) ): api_key = request.headers.get("X-Gemini-Key") if not api_key: raise HTTPException(status_code=400, detail="Missing X-Gemini-Key header") + ack_flag = str(acknowledged).lower() in ("1", "true", "yes") + # Handle JSON body manually for URL payload content_type = request.headers.get("content-type", "") if "application/json" in content_type: body = await request.json() url = body.get("url") + ack_flag = bool(body.get("acknowledged")) if not url and not file: raise HTTPException(status_code=400, detail="Must provide URL or File") + if not ack_flag: + raise HTTPException(status_code=400, detail="You must confirm you own the content or have rights to process it.") + if url and DISABLE_YOUTUBE_URL: raise HTTPException(status_code=403, detail="YouTube URL ingest is disabled on this deployment. Please upload a file you own.") + # Capture attestation context for legal record (IP + timestamp + UA) + client_ip = request.client.host if request.client else "unknown" + fwd = request.headers.get("x-forwarded-for") + if fwd: + client_ip = fwd.split(",")[0].strip() + user_agent = request.headers.get("user-agent", "") + attestation = { + "acknowledged": True, + "ip": client_ip, + "user_agent": user_agent, + "timestamp": time.time(), + "source": "url" if url else "file", + } + job_id = str(uuid.uuid4()) job_output_dir = os.path.join(OUTPUT_DIR, job_id) os.makedirs(job_output_dir, exist_ok=True) - + # Prepare Command cmd = ["python", "-u", "main.py"] # -u for unbuffered env = os.environ.copy() env["GEMINI_API_KEY"] = api_key # Override with key from request - + if url: cmd.extend(["-u", url]) else: # Save uploaded file with size limit check input_path = os.path.join(UPLOAD_DIR, f"{job_id}_{file.filename}") - + # Read file in chunks to check size size = 0 limit_bytes = MAX_FILE_SIZE_MB * 1024 * 1024 - + with open(input_path, "wb") as buffer: while content := await file.read(1024 * 1024): # Read 1MB chunks size += len(content) @@ -362,22 +383,25 @@ async def process_endpoint( shutil.rmtree(job_output_dir) raise HTTPException(status_code=413, detail=f"File too large. Max size {MAX_FILE_SIZE_MB}MB") buffer.write(content) - + cmd.extend(["-i", input_path]) cmd.extend(["-o", job_output_dir]) + print(f"[attestation] job={job_id} ip={attestation['ip']} source={attestation['source']} ack=true") + # Enqueue Job jobs[job_id] = { 'status': 'queued', 'logs': [f"Job {job_id} queued."], 'cmd': cmd, 'env': env, - 'output_dir': job_output_dir + 'output_dir': job_output_dir, + 'attestation': attestation } - + await job_queue.put(job_id) - + return {"job_id": job_id, "status": "queued"} @app.get("/api/status/{job_id}") diff --git a/dashboard/src/App.jsx b/dashboard/src/App.jsx index 418ef80..f36c174 100644 --- a/dashboard/src/App.jsx +++ b/dashboard/src/App.jsx @@ -336,10 +336,11 @@ function App() { if (data.type === 'url') { headers['Content-Type'] = 'application/json'; - body = JSON.stringify({ url: data.payload }); + body = JSON.stringify({ url: data.payload, acknowledged: !!data.acknowledged }); } else { const formData = new FormData(); formData.append('file', data.payload); + formData.append('acknowledged', data.acknowledged ? 'true' : 'false'); body = formData; } diff --git a/dashboard/src/components/MediaInput.jsx b/dashboard/src/components/MediaInput.jsx index 4962bbd..1bfa9ed 100644 --- a/dashboard/src/components/MediaInput.jsx +++ b/dashboard/src/components/MediaInput.jsx @@ -7,6 +7,7 @@ export default function MediaInput({ onProcess, isProcessing }) { const [mode, setMode] = useState('url'); // 'url' | 'file' const [url, setUrl] = useState(''); const [file, setFile] = useState(null); + const [acknowledged, setAcknowledged] = useState(false); useEffect(() => { fetch(getApiUrl('/api/config')) @@ -22,10 +23,11 @@ export default function MediaInput({ onProcess, isProcessing }) { const handleSubmit = (e) => { e.preventDefault(); + if (!acknowledged) return; if (mode === 'url' && url) { - onProcess({ type: 'url', payload: url }); + onProcess({ type: 'url', payload: url, acknowledged: true }); } else if (mode === 'file' && file) { - onProcess({ type: 'file', payload: file }); + onProcess({ type: 'file', payload: file, acknowledged: true }); } }; @@ -111,10 +113,22 @@ export default function MediaInput({ onProcess, isProcessing }) { )} + +