T16.2: D19 uploaded files download safely
New server/files_http.py; get_wp_file uses it. - PDF and raster images (png, jpeg, gif, webp, bmp, avif) open inline, as before; Cache-Control unchanged for the offline drawing cache. - Every other type, SVG included, downloads as an attachment with Content-Security-Policy: sandbox; default-src 'none'. - SVG uploads stay accepted (decided 2026-10-02: accept, download only). - Content-Disposition: ASCII fallback + RFC 5987 filename*, control characters and quotes replaced. nosniff from the API too. Security review SEC-01 (stored XSS through an SVG drawing) and SEC-15e (non-Latin-1 names gave 500; CR/LF reached the header). security_check.py D19: 20/20 total with D21. Againstda1325c: 6 fails (the findings); every inline/cache/access check passes on both. (cherry picked from commit14ecb75c88)
This commit is contained in:
@@ -118,7 +118,57 @@ def d21():
|
||||
pin.group(1) if pin else "no pin")
|
||||
|
||||
|
||||
SECTIONS = [d21]
|
||||
# ── D19: uploaded files download safely ──────────────────────────────────────
|
||||
def d19():
|
||||
print("\nD19 uploaded files download safely")
|
||||
r = as_member.post("/api/wps", json={"id": "wp_files", "project_id": "proj_a", "number": "F1"})
|
||||
assert r.status_code == 200, r.text
|
||||
|
||||
def upload(name, mime, data):
|
||||
r = as_member.post("/api/wps/wp_files/files", json={
|
||||
"name": name, "mime": mime, "data_base64": base64.b64encode(data).decode()})
|
||||
return r.status_code, (r.json().get("file") or {}).get("id")
|
||||
|
||||
code, svg = upload("route.svg", "image/svg+xml",
|
||||
b'<svg xmlns="http://www.w3.org/2000/svg"><script>alert(1)</script></svg>')
|
||||
check("D19", "an SVG upload is still accepted (decided: accept, download only)", code == 200, f"status {code}")
|
||||
r = as_member.get(f"/api/files/{svg}")
|
||||
disp, csp = r.headers.get("content-disposition", ""), r.headers.get("content-security-policy", "")
|
||||
check("D19", "an SVG downloads as an attachment, never inline", disp.startswith("attachment"), disp)
|
||||
check("D19", "an SVG download carries a sandbox CSP", "sandbox" in csp, csp or "no CSP")
|
||||
check("D19", "file responses carry nosniff", r.headers.get("x-content-type-options") == "nosniff")
|
||||
|
||||
for name, mime, data in (("plan.png", "image/png", b"\x89PNG\r\n\x1a\n"),
|
||||
("photo.jpg", "image/jpeg", b"\xff\xd8\xff"),
|
||||
("sheet.pdf", "application/pdf", b"%PDF-1.4")):
|
||||
_, fid = upload(name, mime, data)
|
||||
r = as_member.get(f"/api/files/{fid}")
|
||||
check("D19", f"{mime} still opens inline, no sandbox",
|
||||
r.status_code == 200 and r.headers.get("content-disposition", "").startswith("inline")
|
||||
and "content-security-policy" not in r.headers, r.headers.get("content-disposition", ""))
|
||||
check("D19", f"{mime} keeps the offline cache header",
|
||||
r.headers.get("cache-control") == "private, max-age=86400", r.headers.get("cache-control", ""))
|
||||
|
||||
_, fid = upload("Plan é – Nivel 2.pdf", "application/pdf", b"%PDF-1.4")
|
||||
r = as_member.get(f"/api/files/{fid}")
|
||||
check("D19", "a drawing with a non-Latin-1 name downloads (was 500)", r.status_code == 200,
|
||||
f"status {r.status_code}")
|
||||
check("D19", "the real name rides in filename*",
|
||||
"filename*=UTF-8''Plan%20%C3%A9" in r.headers.get("content-disposition", ""),
|
||||
r.headers.get("content-disposition", ""))
|
||||
|
||||
_, fid = upload('a\r\nSet-Cookie: x=1;".pdf', "application/pdf", b"%PDF-1.4")
|
||||
r = as_member.get(f"/api/files/{fid}")
|
||||
disp = r.headers.get("content-disposition", "")
|
||||
check("D19", "CR/LF and quotes in a name cannot reach the header",
|
||||
r.status_code == 200 and "\r" not in disp and "\n" not in disp and "set-cookie" not in r.headers,
|
||||
repr(disp))
|
||||
r = client(account("user_outsider")).get(f"/api/files/{svg}")
|
||||
check("D19", "a non-member still gets 403 (access check unchanged)", r.status_code == 403,
|
||||
f"status {r.status_code}")
|
||||
|
||||
|
||||
SECTIONS = [d21, d19]
|
||||
|
||||
|
||||
def main() -> int:
|
||||
|
||||
Reference in New Issue
Block a user