Four findings in one diff, ranked
builds on: String-built SQL, shell commands and HTML, Secrets in code, logs and commits, Security checks switched off to make it work, Endpoints that authenticate but don't authorize, Vetting a dependency the agent added, Limiting what the agent can break
**1** f-string SQL: `n` comes from the URL, so any logged-in user can pull rows from any table into the PDF, and with some database drivers change data too. **2** No owner check: any user can fetch any invoice by counting ids. **3** `pdfgen-fast`: unpinned and unvetted, and its install already ran in the session. If it turns out malicious, it jumps to first. **4** `verify=False`: only someone on the network path can swap the logo. Fixes: parameterise, filter by owner, vet and pin, restore verification.
// Python
+++ b/requirements.txt
+pdfgen-fast
+++ b/api/invoices.py
+import pdfgen_fast
+@app.get("/invoices/<n>/pdf")
+@login_required
+def invoice_pdf(n):
+ sql = f"SELECT * FROM inv WHERE id={n}"
+ row = db.execute(sql).fetchone()
+ logo = requests.get(row["logo_url"],
+ verify=False)
+ return pdfgen_fast.render(row,
+ logo.content)