Hardening: ContentRewriter mangles //<configured-host> path segments; rewriter drops non-default ports #14
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type: hardening / correctness. Found by security audit run 3 (commit
01195c8) during URL-parser fuzzing (no redirect to an unconfigured host was found in 21k cases).What happens
ContentRewriterpattern (src/Rewrite/ContentRewriter.php:46) has no left boundary before the optional scheme and//host. A same-site link whose path contains//<configured-host>/, e.g.http://example.com//example.com/x, is rewritten tohttps://www.example.comhttps://www.example.com/x(a broken, non-resolvable host).UrlRewriter::buildTail(src/Rewrite/UrlRewriter.php:82-87) drops the port and userinfo, sohttps://example.com:8443/xbecomeshttps://<current>/x. It stays on a configured host, but configured hosts served on non-default ports break.Suggested fix
Anchor the content match with a lookbehind such as
(?<![\w.:/-])before the optional scheme group (or require a preceding quote,=, whitespace or start of string). Carry$parts['port']through only when the configured host entry declares a port. Regression case:rewrite('<a href="http://example.com//example.com/x">')keeps the path segment intact.