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. Against da1325c: 6 fails
(the findings); every inline/cache/access check passes on both.

(cherry picked from commit 14ecb75c88)
This commit is contained in:
2026-10-02 13:52:43 -07:00
parent d962ab2381
commit f4d74879cc
3 changed files with 121 additions and 6 deletions

View File

@@ -27,7 +27,7 @@ from sqlalchemy.orm import Session
from starlette.middleware.sessions import SessionMiddleware
from .db import Base, engine, get_db
from . import models, auth, notify, assets_db, okta_auth, okta_fake
from . import models, auth, notify, assets_db, okta_auth, okta_fake, files_http
log = logging.getLogger("wpsuite.app")
@@ -2910,10 +2910,9 @@ def get_wp_file(file_id: str, user: models.User = Depends(auth.get_current_user)
if not row:
raise HTTPException(status_code=404, detail="File not found")
require_project_access(db, user, row.project_id)
return Response(content=row.data, media_type=row.mime or "application/octet-stream",
headers={"Content-Disposition":
f'inline; filename="{(row.name or "file").replace(chr(34), "")}"',
"Cache-Control": "private, max-age=86400"})
# D19: PDF and raster images inline as before; anything else (SVG included)
# downloads as a sandboxed attachment, and every name is a valid header.
return files_http.file_response(row)
@app.patch("/api/files/{file_id}")