defvalidate_temp_path(path:str)->str:abs_p=os.path.abspath(path)ifnotabs_p.startswith(tempfile.gettempdir())ornotos.path.isdir(abs_p):raiseHTTPException(403,"Zugriff nicht erlaubt")returnabs_pIMAGE_FORMATS={"upload":{".jpg",".jpeg",".png",".webp",".heic",".heif"},"preview":{".jpg",".jpeg",".png",".webp"},}
## Problem
`server.py` enthaelt 6x dieselbe tempdir-Pfad-Validation:
- Zeile 144, 179, 229, 333, 458, 518, 529
Extension-Whitelists sind doppelt:
- `UPLOAD_ALLOWED_EXTENSIONS` (Z.136), `_HEIC_EXTS` (Z.137), `PREVIEW_ALLOWED_EXTENSIONS` (Z.222 ff.)
## Fix
```python
def validate_temp_path(path: str) -> str:
abs_p = os.path.abspath(path)
if not abs_p.startswith(tempfile.gettempdir()) or not os.path.isdir(abs_p):
raise HTTPException(403, "Zugriff nicht erlaubt")
return abs_p
IMAGE_FORMATS = {
"upload": {".jpg", ".jpeg", ".png", ".webp", ".heic", ".heif"},
"preview": {".jpg", ".jpeg", ".png", ".webp"},
}
```
UPLOAD_ALLOWED_EXTENSIONS, _HEIC_EXTS, PREVIEW_ALLOWED_EXTENSIONS zeigen jetzt alle auf den Dict (Single Source of Truth).
Tempdir-Validation-Helper
def_require_tempdir_path(path:str,must_be:str)->str:abs_p=os.path.abspath(path)ifnotabs_p.startswith(tempfile.gettempdir()):raiseHTTPException(403,"Zugriff nicht erlaubt")ifmust_be=="dir"andnotos.path.isdir(abs_p):raiseHTTPException(404,"Ordner nicht gefunden")ifmust_be=="file"andnotos.path.isfile(abs_p):raiseHTTPException(404,"Datei nicht gefunden")returnabs_p
Verwendet jetzt in /download, /preview, /thumb, /uploads-DELETE, /move, /export, /exif, /detect-angle.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Problem
server.pyenthaelt 6x dieselbe tempdir-Pfad-Validation:Extension-Whitelists sind doppelt:
UPLOAD_ALLOWED_EXTENSIONS(Z.136),_HEIC_EXTS(Z.137),PREVIEW_ALLOWED_EXTENSIONS(Z.222 ff.)Fix
Fix umgesetzt in
server.py:Zentrale Extension-Listen
UPLOAD_ALLOWED_EXTENSIONS,_HEIC_EXTS,PREVIEW_ALLOWED_EXTENSIONSzeigen jetzt alle auf den Dict (Single Source of Truth).Tempdir-Validation-Helper
Verwendet jetzt in
/download,/preview,/thumb,/uploads-DELETE,/move,/export,/exif,/detect-angle.Status: Vorher 9 dupliziete Tempdir-Checks (Z.179, 229, 333, 458, 518, 529, 541, 715, 732). Nachher: 1 (im Helper).
Nebeneffekt (positiv): not-found-Verzeichnisse innerhalb tempdir geben jetzt 404 statt 403 - das ist genau, was #27 fordert.
Nicht angefasst: Z.218 und Z.709 sind opt-in-Logik (waehle existierenden Ordner falls er passt, sonst Default), kein 403-Validation - eigener Pattern.