|
6 | 6 | import pathlib |
7 | 7 | import traceback |
8 | 8 | from datetime import datetime, timedelta |
9 | | -from mimetypes import guess_type |
10 | 9 | from typing import Any, Callable, TypeVar, Union |
11 | 10 |
|
12 | 11 | import argon2.exceptions |
|
18 | 17 | from ...bus import BusData |
19 | 18 | from ...minecraft import McServersModules |
20 | 19 | from ...utils.hash import hash_string, verify_hash |
21 | | -from ...utils.misc import str2bool, time_from_now |
| 20 | +from ...utils.misc import str2bool, time_from_now, guess_type |
22 | 21 | from ...utils.regex import RE_MC_SERVER_NAME |
23 | 22 | from ..Base_interface import BaseInterface |
24 | 23 | from ..database.types import AccessLevel |
@@ -180,14 +179,8 @@ def static_proxy(path : str): |
180 | 179 | Logger.trace(f"Serving file: {full_path}") |
181 | 180 |
|
182 | 181 | content = pathlib.Path(full_path).read_bytes() |
183 | | - mimetype = guess_type(path)[0] or 'text/html' |
| 182 | + mimetype = guess_type(full_path) |
184 | 183 | # Only allow known-safe mimetypes |
185 | | - allowed_mimetypes = ( |
186 | | - 'text/html', 'text/css', 'text/javascript', 'text/json', 'image/png', 'image/jpeg', 'image/gif', 'image/svg+xml', 'image/webp', 'font/woff', 'font/woff2', 'font/ttf', 'font/otf' |
187 | | - ) |
188 | | - if mimetype not in allowed_mimetypes: |
189 | | - Logger.warning(f"Unknown mimetype {mimetype} for file {path}, defaulting to application/octet-stream") |
190 | | - mimetype = 'application/octet-stream' |
191 | 184 | Logger.trace(f"Serving {STATIC_PATH}/{path} ({len(content)} bytes) with mimetype {mimetype})") |
192 | 185 | return content, HTTP.OK, {'Content-Type': mimetype} |
193 | 186 | except Exception as e: |
|
0 commit comments