diff options
| author | kj_sh604 | 2026-06-01 13:34:03 -0400 |
|---|---|---|
| committer | kj_sh604 | 2026-06-01 13:34:03 -0400 |
| commit | 97942ca6f1a38c133c5e1adb7b5ea10d84c81985 (patch) | |
| tree | dc9dc314ced42d9a1891a6b356b3235c6a489f9a | |
| parent | 6aea2bf6305e6d266f7ec7d54bd1966b050e7f79 (diff) | |
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | src/app.py | 7 | ||||
| -rw-r--r-- | src/uploads/.htaccess | 5 | ||||
| -rw-r--r-- | src/uploads/nyan.png (renamed from src/nyan.png) | bin | 901 -> 901 bytes |
4 files changed, 11 insertions, 3 deletions
@@ -1,5 +1,5 @@ src/uploads/* !src/uploads/.htaccess -!src/uploads/nyan_819cac51.png +!src/uploads/nyan.png __pycache__/ *.pyc
\ No newline at end of file @@ -5,6 +5,7 @@ import hashlib import os import re import secrets +import string import subprocess import time from pathlib import Path @@ -215,7 +216,7 @@ def favicon_svg(): @app.route("/nyan.png") def nyan_png(): - return send_from_directory(app.root_path, "nyan.png") + return send_from_directory(UPLOAD_DIR, "nyan.png") @app.route("/uploads/<filename>") @@ -244,7 +245,9 @@ def upload(): ext = ALLOWED_MIME[mime] basename = re.sub(r"[^a-zA-Z0-9_-]", "_", Path(f.filename).stem)[:64] or "image" - filename = f"{basename}_{secrets.token_hex(4)}.{ext}" + epoch = int(time.time()) + rand = "".join(secrets.choice(string.ascii_lowercase + string.digits) for _ in range(16)) + filename = f"{basename}_{epoch}-{rand}.{ext}" (UPLOAD_DIR / filename).write_bytes(data) diff --git a/src/uploads/.htaccess b/src/uploads/.htaccess new file mode 100644 index 0000000..c53904e --- /dev/null +++ b/src/uploads/.htaccess @@ -0,0 +1,5 @@ +# deny common executable/script payloads in uploads +<FilesMatch "\.(php|phtml|php[0-9]?|phar|cgi|pl|py|sh)$"> + Require all denied +</FilesMatch> +Options -ExecCGI diff --git a/src/nyan.png b/src/uploads/nyan.png Binary files differindex 377b9d0..377b9d0 100644 --- a/src/nyan.png +++ b/src/uploads/nyan.png |
