handle invalid URL in Location header for fetch() (#9305)

This commit is contained in:
Meghan Denny
2024-03-07 17:32:05 -08:00
committed by GitHub
parent 3b13f7f998
commit ea5354fc85
3 changed files with 6 additions and 1 deletions

View File

@@ -1228,6 +1228,7 @@ pub const Fetch = struct {
error.FailedToOpenSocket => bun.String.static("Was there a typo in the url or port?"),
error.TooManyRedirects => bun.String.static("The response redirected too many times. For more information, pass `verbose: true` in the second argument to fetch()"),
error.ConnectionRefused => bun.String.static("Unable to connect. Is the computer able to access the url?"),
error.RedirectURLInvalid => bun.String.static("Redirect URL in Location header is invalid."),
error.UNABLE_TO_GET_ISSUER_CERT => bun.String.static("unable to get issuer certificate"),
error.UNABLE_TO_GET_CRL => bun.String.static("unable to get certificate CRL"),

View File

@@ -3568,6 +3568,10 @@ pub fn handleResponseMetadata(
const normalized_url = JSC.URL.hrefFromString(bun.String.fromBytes(string_builder.allocatedSlice()));
defer normalized_url.deref();
if (normalized_url.tag == .Dead) {
// URL__getHref failed, dont pass dead tagged string to toOwnedSlice.
return error.RedirectURLInvalid;
}
const normalized_url_str = try normalized_url.toOwnedSlice(bun.default_allocator);
const new_url = URL.parse(normalized_url_str);

View File

@@ -772,7 +772,7 @@ pub inline fn err(error_name: anytype, comptime fmt: []const u8, args: anytype)
}
// TODO: convert zig errors to errno for better searchability?
if (errors.len == 1) break :display_name .{ comptime @errorName(errors[0]), true };
if (errors.len == 1) break :display_name .{ errors[0].name, true };
}
break :display_name .{ @errorName(error_name), false };