mirror of
https://github.com/FlashML-org/FreeToken.git
synced 2026-11-25 12:42:56 +08:00
fix(server): accept localhost authority in local file URIs (#758)
Resolve the parsed URI path without prepending localhost, while rejecting non-local authorities and retaining the media root check. Add regression cases for localhost authority spellings and remote hosts. Refs FlashML-org/FreeToken#757
This commit is contained in:
@@ -66,7 +66,10 @@ def _load_local_media(url: str, config: ServerArgs) -> bytes:
|
||||
if not root:
|
||||
raise ValueError("cannot load local files without --allowed-local-media-path")
|
||||
spec = urlparse(url)
|
||||
filepath = Path(url2pathname((spec.netloc or "") + (spec.path or "")))
|
||||
# RFC 8089: empty authority and localhost identify the local machine.
|
||||
if spec.netloc and spec.netloc.lower().rstrip(".") != "localhost":
|
||||
raise ValueError("file:// URLs must have no host or use localhost")
|
||||
filepath = Path(url2pathname(spec.path or ""))
|
||||
# resolve() follows symlinks, so a link inside the root escaping it is rejected too
|
||||
resolved = filepath.resolve()
|
||||
if Path(root).resolve() not in resolved.parents:
|
||||
|
||||
Reference in New Issue
Block a user