[boring] Check initial https scheme and catch invalid redirect locations
diff --git a/pkgs/boring/lib/src/hook_helpers/fetch.dart b/pkgs/boring/lib/src/hook_helpers/fetch.dart index e297d4a..a179b1d 100644 --- a/pkgs/boring/lib/src/hook_helpers/fetch.dart +++ b/pkgs/boring/lib/src/hook_helpers/fetch.dart
@@ -151,12 +151,20 @@ /// `https` URLs, so that the request never leaves TLS, unlike [HttpClient]'s /// own redirect handling, which also follows redirects to `http` URLs. /// -/// Throws a [BuildError] for a redirect to another scheme or for too many -/// redirects. +/// Throws a [BuildError] if [url] is not an `https` URL, for a redirect to +/// another scheme or an invalid redirect location, or for too many redirects. Future<HttpClientResponse> _getFollowingHttpsRedirects( HttpClient client, Uri url, ) async { + if (url.scheme != 'https') { + throw BuildError( + message: + 'Refusing to download the prebuilt boring binary from $url, which ' + 'is not an https URL.\n' + '$_checkoutHint', + ); + } var currentUrl = url; for (var redirects = 0; ; redirects++) { final request = await client.getUrl(currentUrl).timeout(_connectionTimeout); @@ -165,7 +173,17 @@ final location = response.headers.value(HttpHeaders.locationHeader); if (!response.isRedirect || location == null) return response; await response.drain<void>().timeout(_connectionTimeout); - final nextUrl = currentUrl.resolve(location); + final Uri nextUrl; + try { + nextUrl = currentUrl.resolve(location); + } on FormatException catch (e) { + throw BuildError( + message: + 'Received invalid redirect location "$location" from $currentUrl ' + 'while downloading the prebuilt boring binary from $url: $e\n' + '$_checkoutHint', + ); + } if (nextUrl.scheme != 'https') { throw BuildError( message: