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:
Your Open Source Tooling Specialist
2026-10-19 21:40:55 -07:00
committed by GitHub
parent 70550f8f9e
commit bb15d1d387
2 changed files with 14 additions and 1 deletions
+4 -1
View File
@@ -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: