Repository navigation
Conversation
|
AI review of |
| String url, { | ||
| ProxyConfig? proxyConfig, | ||
| int maxBytes = maxDownloadedImageBytes, | ||
| @visibleForTesting ImageSender send = sendImageRequest, |
There was a problem hiding this comment.
Public image URLs with Unicode hostnames now fail before DNS. Both download functions reject https://bücher.de/image.png because Dart exposes the host as b%C3%BCcher.de, while the equivalent xn--bcher-kva.de passes validation. The previous rhttp path applied IDNA normalization. Normalize the host to ASCII before applying the public-address checks, and use that same normalized URL for the request.
There was a problem hiding this comment.
Recorded as a known limit (see "Known limits" in the description of #2146). bücher.de and other names in the accepted scripts pass now. Names in other scripts are still rejected, because Dart has no IDNA to check the name that the native client will use.
| }) async { | ||
| final resolved = Uri.base.resolve(url); | ||
| final response = await _sendImageRequest(resolved, proxyConfig); | ||
| final response = await send(resolved, proxyConfig: proxyConfig); |
There was a problem hiding this comment.
The shared helper changes the request target when a redirect contains percent-encoded unreserved characters. In a mock download, Location: /image%7E.png?key=token%41 produced /image~.png?key=tokenA, which can invalidate signatures that cover the raw path or query. Resolve and send each redirect with its escaped path and query preserved, while still validating every destination.
There was a problem hiding this comment.
Not changed. Dart's Uri rewrites percent-encoded unreserved characters, which RFC 3986 (sections 2.3 and 6.2.2.2) defines as equivalent. On main, the first request already goes through this rewrite: with the native client, /image%7E.png?key=token%41&sig=a%2Fb%3D is requested as /image~.png?key=tokenA&sig=a%2Fb%3D. Only redirect targets kept the original spelling there. Reserved escapes such as %2F and %3D stay as they are, before and after this change. To keep the raw text, the string that is sent would have to differ from the URL that is checked.
| }) async { | ||
| final resolved = Uri.base.resolve(url); | ||
| final response = await _sendImageRequest(resolved, proxyConfig); | ||
| final response = await send(resolved, proxyConfig: proxyConfig); |
There was a problem hiding this comment.
The Unicode hostname regression is still present for decomposed spellings. The validator accepts bücher.de but rejects bu%CC%88cher.de before DNS, even though both map to xn--bcher-kva.de under IDNA. Normalize hostnames with IDNA before applying the public-address checks, and send the request using the same normalized hostname.
There was a problem hiding this comment.
Confirmed: bu%CC%88cher.de loaded on main (requested as xn--bcher-kva.de) and is now rejected. Not changed in this PR. It is part of the stated limit that other non-ASCII characters are rejected. Accepting decomposed spellings needs the IDNA mapping itself, because IDNA drops some combining characters, so a longer list of accepted characters is not reliable. Leaving this open for a 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). Decomposed spellings are still rejected. Accepting them needs the IDNA mapping itself, because IDNA drops some combining characters.
There was a problem hiding this comment.
AI review · GPT · fc135bc
Needs fixes. flutter analyze --no-pub passed for the four affected files and both git diff --check comparisons passed. The two focused Flutter test invocations did not complete within the 120-second timeout, so their results could not be independently verified here.
| await request.response.close(); | ||
| }); | ||
| addTearDown(subscription.cancel); | ||
| final client = IOClient(); |
There was a problem hiding this comment.
This test constructs a plain IOClient, whose underlying HttpClient can still honor the process http_proxy/https_proxy settings. Clearing imageEnvironment only affects sendImageRequest's resolver, so on a machine with a proxy and no loopback bypass the request can fail with Connection refused before the local server sends the oversized response. Configure the test client to bypass the proxy for loopback, or use a client/transport whose proxy behavior is controlled by the test.
There was a problem hiding this comment.
Not changed. With HTTP_PROXY set and no loopback bypass, flutter test cannot load any test file, because its own local connection goes to the proxy. This also happens with test/utils/number_test.dart, which makes no request, so the test body is not reached. With a loopback bypass, IOClient connects directly, and the image tests pass with a proxy set.
Summary
Stacked on #2146, which adds
sendImageRequest.downloadImageFileanddownloadImageBytesdownload an image by URL, for example to send it. They now use the same request function as images that are shown. Its rules for host names and theReferercome from #2146.Evidence
test/utils/image_test.dart. With the old request function, both "does not request a local address" cases fail. With the change, they pass. The size limit tests still run against a local server.flutter analyze: no issues.flutter test: 545 passed, 13 skipped.Merge Danger
Door: two-way
Blast Radius: images downloaded by URL. An image on a LAN or
.localhost can no longer be sent by URL, nor can one on a host name that #2146 rejects.