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) <noreply@anthropic.com>
This commit is contained in:
juancarlos.cavero 2026-05-06 11:55:12 +02:00
parent 3f4c814e22
commit 12c1b8e1d5
3 changed files with 53 additions and 14 deletions

42
app.py
View file

@ -317,43 +317,64 @@ async def get_config():
async def process_endpoint( async def process_endpoint(
request: Request, request: Request,
file: Optional[UploadFile] = File(None), 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") api_key = request.headers.get("X-Gemini-Key")
if not api_key: if not api_key:
raise HTTPException(status_code=400, detail="Missing X-Gemini-Key header") 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 # Handle JSON body manually for URL payload
content_type = request.headers.get("content-type", "") content_type = request.headers.get("content-type", "")
if "application/json" in content_type: if "application/json" in content_type:
body = await request.json() body = await request.json()
url = body.get("url") url = body.get("url")
ack_flag = bool(body.get("acknowledged"))
if not url and not file: if not url and not file:
raise HTTPException(status_code=400, detail="Must provide URL or 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: 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.") 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_id = str(uuid.uuid4())
job_output_dir = os.path.join(OUTPUT_DIR, job_id) job_output_dir = os.path.join(OUTPUT_DIR, job_id)
os.makedirs(job_output_dir, exist_ok=True) os.makedirs(job_output_dir, exist_ok=True)
# Prepare Command # Prepare Command
cmd = ["python", "-u", "main.py"] # -u for unbuffered cmd = ["python", "-u", "main.py"] # -u for unbuffered
env = os.environ.copy() env = os.environ.copy()
env["GEMINI_API_KEY"] = api_key # Override with key from request env["GEMINI_API_KEY"] = api_key # Override with key from request
if url: if url:
cmd.extend(["-u", url]) cmd.extend(["-u", url])
else: else:
# Save uploaded file with size limit check # Save uploaded file with size limit check
input_path = os.path.join(UPLOAD_DIR, f"{job_id}_{file.filename}") input_path = os.path.join(UPLOAD_DIR, f"{job_id}_{file.filename}")
# Read file in chunks to check size # Read file in chunks to check size
size = 0 size = 0
limit_bytes = MAX_FILE_SIZE_MB * 1024 * 1024 limit_bytes = MAX_FILE_SIZE_MB * 1024 * 1024
with open(input_path, "wb") as buffer: with open(input_path, "wb") as buffer:
while content := await file.read(1024 * 1024): # Read 1MB chunks while content := await file.read(1024 * 1024): # Read 1MB chunks
size += len(content) size += len(content)
@ -362,22 +383,25 @@ async def process_endpoint(
shutil.rmtree(job_output_dir) shutil.rmtree(job_output_dir)
raise HTTPException(status_code=413, detail=f"File too large. Max size {MAX_FILE_SIZE_MB}MB") raise HTTPException(status_code=413, detail=f"File too large. Max size {MAX_FILE_SIZE_MB}MB")
buffer.write(content) buffer.write(content)
cmd.extend(["-i", input_path]) cmd.extend(["-i", input_path])
cmd.extend(["-o", job_output_dir]) cmd.extend(["-o", job_output_dir])
print(f"[attestation] job={job_id} ip={attestation['ip']} source={attestation['source']} ack=true")
# Enqueue Job # Enqueue Job
jobs[job_id] = { jobs[job_id] = {
'status': 'queued', 'status': 'queued',
'logs': [f"Job {job_id} queued."], 'logs': [f"Job {job_id} queued."],
'cmd': cmd, 'cmd': cmd,
'env': env, 'env': env,
'output_dir': job_output_dir 'output_dir': job_output_dir,
'attestation': attestation
} }
await job_queue.put(job_id) await job_queue.put(job_id)
return {"job_id": job_id, "status": "queued"} return {"job_id": job_id, "status": "queued"}
@app.get("/api/status/{job_id}") @app.get("/api/status/{job_id}")

View file

@ -336,10 +336,11 @@ function App() {
if (data.type === 'url') { if (data.type === 'url') {
headers['Content-Type'] = 'application/json'; headers['Content-Type'] = 'application/json';
body = JSON.stringify({ url: data.payload }); body = JSON.stringify({ url: data.payload, acknowledged: !!data.acknowledged });
} else { } else {
const formData = new FormData(); const formData = new FormData();
formData.append('file', data.payload); formData.append('file', data.payload);
formData.append('acknowledged', data.acknowledged ? 'true' : 'false');
body = formData; body = formData;
} }

View file

@ -7,6 +7,7 @@ export default function MediaInput({ onProcess, isProcessing }) {
const [mode, setMode] = useState('url'); // 'url' | 'file' const [mode, setMode] = useState('url'); // 'url' | 'file'
const [url, setUrl] = useState(''); const [url, setUrl] = useState('');
const [file, setFile] = useState(null); const [file, setFile] = useState(null);
const [acknowledged, setAcknowledged] = useState(false);
useEffect(() => { useEffect(() => {
fetch(getApiUrl('/api/config')) fetch(getApiUrl('/api/config'))
@ -22,10 +23,11 @@ export default function MediaInput({ onProcess, isProcessing }) {
const handleSubmit = (e) => { const handleSubmit = (e) => {
e.preventDefault(); e.preventDefault();
if (!acknowledged) return;
if (mode === 'url' && url) { if (mode === 'url' && url) {
onProcess({ type: 'url', payload: url }); onProcess({ type: 'url', payload: url, acknowledged: true });
} else if (mode === 'file' && file) { } 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 }) {
</div> </div>
)} )}
<label className="flex items-start gap-2 mt-5 text-xs text-zinc-400 cursor-pointer select-none">
<input
type="checkbox"
checked={acknowledged}
onChange={(e) => setAcknowledged(e.target.checked)}
className="mt-0.5 accent-primary cursor-pointer"
/>
<span>
I confirm I own this content or have the rights to process it. I am responsible for any content I submit.
</span>
</label>
<button <button
type="submit" type="submit"
disabled={isProcessing || (mode === 'url' && !url) || (mode === 'file' && !file)} disabled={isProcessing || !acknowledged || (mode === 'url' && !url) || (mode === 'file' && !file)}
className="w-full btn-primary mt-6 flex items-center justify-center gap-2" className="w-full btn-primary mt-4 flex items-center justify-center gap-2"
> >
{isProcessing ? ( {isProcessing ? (
<> <>