Url::origin() overflows the stack on a URL with nested blob: prefixes
Description
For a blob: URL, Url::origin() parses the path as a URL and calls itself on the result. It does so for any inner scheme, blob included, so each blob: prefix costs one stack frame, with no limit.
let text = format!("{}https://example.com/", "blob:".repeat(10_000));
let url = Url::parse(&text).unwrap(); // 50,020 bytes, parses fine
// A spawned thread has the default 2 MiB stack.
std::thread::spawn(move || url.origin()).join().unwrap(); // stack overflow, the process abortsA server that wraps each request in catch_unwind still goes down as a whole: a stack overflow aborts the process. url::quirks::origin, hidden from the docs and used by Servo, calls Url::origin() and is affected too. The URL Standard takes the inner URL's origin only when its scheme is http, https, or file, and returns an opaque origin otherwise; it never recurses.
Impact
Any program that calls origin() on a URL from untrusted input can be made to abort. url 2.5.8 and earlier are affected.
Servo's DOM getter URL.origin calls url::quirks::origin, so page script can trigger it.
Firefox calls it through MozURL::Origin() in the parent process, in ClientSourceParent::RecvExecutionReady, on a URL that a content process sends, so a compromised content process can make the parent process abort.
Patches
Fixed in github.com/
This is shipped in url 2.5.9.
Workarounds
Compute the origin of a blob: URL as the standard does: parse its path, and take that URL's origin only when its scheme is http, https, or file; otherwise treat the origin as opaque.
Note to maintainers: the bug is already public and fixed; please publish this advisory and request a CVE for it.