Repository navigation
Resolve relative links in fetched pages against the page URL - #5
sharmis-tp wants to merge 2 commits into
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
| Err(e) => return soft_or_hard(&e), | ||
| }; | ||
| let base_url = final_url.to_string(); | ||
| let base_url = final_url.clone(); |
There was a problem hiding this comment.
is this making a copy of the buffer or just incrementing an Arc?
|
Looks good in principle. Is it possible that this could leak internal network details? Are there security issues? |
|
Leaks: no. The change only rewrites text in the result, so it sends no request and fetches no link. Links resolve against the final URL, which already passed the address policy and is printed on the url: line. The policy refuses userinfo on the request and on every redirect, so no credentials can end up in a link. A page can point its links at an internal address with , but it could already write those as absolute links, and any fetch of one goes through the full address policy. Security: yes, one, now fixed. Resolving makes each link as long as the base URL, and the page chooses the base with . Many short links under a long base grew the HTML 127x to 1,538x before rendering, enough at the 8 MiB body cap to exhaust memory. The new commit leaves a link as written when its absolute form would be over MAX_URL_CHARS, which a fetch would refuse anyway, and stops resolving once it has added as many bytes as the page holds. Growth is now at most ~2x, and there are two tests for it. |
|
Merged as part of #6. |
web/fetch returned links and image sources as the page wrote them, so
/learncame back as[Learn](/learn), which a model cannot fetch. readabilityrs takes the base URL but itsfix_relative_urls_in_htmlignores it, and htmd never resolves links.Before either renderer runs, every relative
a hrefandimg srcis now resolved against the page's final URL, or its first<base href>when that is http or https. Fragments, absolute URLs, and references that resolve to another scheme stay as written. The walk is iterative, so deep nesting cannot overflow the stack.html5everandmarkup5ever_rcdomare the crates htmd already builds on, at its versions, so the lockfile gains no crate.Tested: six new tests in
response.rs(readability mode, raw mode,<base>, a non-http<base>, links left as written, no base URL), and the release library fetching https://www.rust-lang.org/ returns no relative links.