Repository navigation
Conversation
|
AI review done for Quality: The updated tests cover the proxy exemption and IPv6 range changes. Redirect compatibility still needs work, as verified with mocked requests and inspection of the native client’s request-building path.
|
|
|
||
| // Rejects escaped and non-ASCII hosts, which the native client maps to | ||
| // other names, such as full-width digits to an IP address. | ||
| if (!_hostName.hasMatch(host)) return false; |
There was a problem hiding this comment.
The hostname regex rejects valid Unicode image URLs before rhttp can apply IDNA conversion. A focused check rejected bücher.example and accepted the equivalent xn--bcher-kva.example. Canonicalize HTTP(S) hostnames with the native client's URL rules before applying the address checks, and send the same canonical URL that passed validation.
There was a problem hiding this comment.
Fixed in 70d6019 for Latin-1, basic Cyrillic, kana, CJK ideographs and Hangul. Dart has no IDNA, so the URL is not rewritten: IDNA keeps each of these letters in a non-ASCII (xn--) label, so the ASCII checks still apply, and the native client converts the host. Other non-ASCII characters, such as full-width letters or Greek, are still rejected. In 41bc815, if a configured proxy has a name in another script or an xn-- name, image hosts of that kind are rejected, because the two spellings cannot be compared without IDNA.
There was a problem hiding this comment.
Recorded as a known limit (see "Known limits" in the description of #2146). Latin-1, basic Cyrillic, kana, CJK ideographs and Hangul pass. Other characters are still rejected. Dart has no IDNA, and a longer list of accepted characters is not reliable, because IDNA maps or drops some characters. A full fix needs an IDNA library, or these checks inside the native client, which is a larger change than this PR.
There was a problem hiding this comment.
AI review · GPT · 41bc815
Needs fixes before merge. Targeted Flutter analysis and both diff whitespace checks passed, as did all 48 existing tests across the image request, cache, and media suites. Four focused regression checks reproduced the findings below.
| // As the native client does when it follows redirects itself. | ||
| referer = target.isScheme('https') && next.isScheme('http') | ||
| ? null | ||
| : target.replace(userInfo: '').removeFragment().toString(); |
There was a problem hiding this comment.
Redirects from Unicode hosts send a Referer with a different hostname spelling from the request. A same-origin redirect sent https://b%C3%BCcher.example/a.png, while reqwest serializes the host as xn--bcher-kva.example. This can break servers that check the header hostname. Build the header from the previous URL after applying the same IDNA canonicalization as the request.
There was a problem hiding this comment.
Confirmed with the native client: main sends Referer: http://xn--bcher-kva.example/a.png, and this branch sends the percent-encoded host. Not changed in this PR. Writing the same spelling needs IDNA, which Dart does not have. This is now listed as a limit in the description, and stays open together with the decision on adding an IDNA library.
There was a problem hiding this comment.
Recorded as a known limit (see "Known limits" in the description of #2146). The Referer keeps the percent-encoded spelling of such a host. Writing the xn-- spelling needs IDNA, which Dart does not have. A full fix needs an IDNA library, or redirects handled inside the native client, which is a larger change than this PR.
… reject 3fff::/20
| // As the native client does when it follows redirects itself. | ||
| referer = target.isScheme('https') && next.isScheme('http') | ||
| ? null | ||
| : target.replace(userInfo: '').removeFragment().toString(); |
There was a problem hiding this comment.
The previous Referer issue persists. A redirect from bücher.example sends https://b%C3%BCcher.example/a.png, while reqwest sends requests to xn--bcher-kva.example. Servers that check the header hostname can reject the image. Build the header using the same IDNA canonicalization as the request URL.
There was a problem hiding this comment.
Confirmed. This is the same gap as the earlier Referer thread: the same spelling needs IDNA. Not changed. Both stay open.
There was a problem hiding this comment.
Recorded as a known limit (see "Known limits" in the description of #2146). Same gap and reason as in the earlier Referer thread: the xn-- spelling needs IDNA.
… let a URL name an HTTP proxy
| if (next.scheme == target.scheme && | ||
| next.host == target.host && | ||
| next.port == target.port) { | ||
| next = next.replace(userInfo: target.userInfo); |
There was a problem hiding this comment.
Strip credentials supplied by a cross-origin Location. The mocked second request retained test:placeholder from the redirect URL, and rhttp builds a fresh reqwest request that turns that user info into Basic auth. The previous automatic redirect sent no such header. Clear userInfo on cross-origin targets. https://raw.githubusercontent.com/seanmonstar/reqwest/v0.13.4/src/async_impl/request.rs
| ); | ||
| // As for the native client, the credentials of the URL stay on its origin. | ||
| if (next.scheme == target.scheme && | ||
| next.host == target.host && |
There was a problem hiding this comment.
Compare canonical hosts before deciding whether to keep credentials. A mocked redirect from [2606:4700:0:0:0:0:0:1] to [2606:4700::1] dropped user:pw, although both literals identify the same origin. Compare parsed IPv6 address bytes and retain the scheme and port checks.
| // As the native client does when it follows redirects itself. | ||
| referer = target.isScheme('https') && next.isScheme('http') | ||
| ? null | ||
| : target.replace(userInfo: '').removeFragment().toString(); |
There was a problem hiding this comment.
The previously reported Referer mismatch persists. A mocked redirect from bücher.example sent https://b%C3%BCcher.example/a.png, while the native client uses https://xn--bcher-kva.example/a.png. Servers that check the referrer hostname can reject the image. Serialize the header with the same IDNA canonicalization as the native request URL.
Summary
Image URLs come from message content. The client that loads remote images for display now requests them only from public addresses.
socks5://from the environment)socks5h://from the environmentlocalhostand.localnames.2001::/23(IETF protocol assignments), only the parts that the IANA registry marks as globally reachable are allowed. Teredo is marked N/A, so it is rejected.198.18.0.0/15stays allowed, because fake-IP proxies answer DNS queries with it. NAT64 addresses are checked by their IPv4 address.255.255.255.255, so the connection fails.As the native client does when it follows redirects itself:
Referer, without user info and fragment, and not from https to http.Locationwithout//, such ashttps:next.png, is relative.Known limits
Dart has no IDNA, so these differ from the native client:
Refererof such a host has the percent-encoded spelling, not thexn--one.xn--names) count as possibly the same proxy. Where proxy names are rejected, such a proxy name stops images on such hosts.Unusual
Locationforms, such as a:in the first relative segment, still fail to load.Evidence
test/utils/remote_image_request_test.dart: the checks were reverted one at a time, and a test failed each time.flutter analyze: no issues.flutter test: 543 passed, 13 skipped.xn--form.Merge Danger
Door: two-way
Blast Radius: all remote images. An image on a LAN or
.localhost no longer loads. Without a proxy, an image host that a local DNS server resolves only to a private address no longer loads either. A host name with other non-ASCII characters, for example Greek or Arabic letters, no longer loads.