Skip to content

Commit 9b5b8d7

Browse files
LiviaMedeirosdanielleadams
authored andcommitted
esm: throw on any non-2xx response
Treat redirects without Location and other 3xx responses as errors PR-URL: #43742 Refs: #43689 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me>
1 parent f28198c commit 9b5b8d7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/internal/modules/esm/fetch_module.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ function fetchWithRedirects(parsed) {
148148
err.message = `Cannot find module '${parsed.href}', HTTP 404`;
149149
throw err;
150150
}
151-
if (res.statusCode < 200 || res.statusCode >= 400) {
151+
// This condition catches all unsupported status codes, including
152+
// 3xx redirection codes without `Location` HTTP header.
153+
if (res.statusCode < 200 || res.statusCode >= 300) {
152154
throw new ERR_NETWORK_IMPORT_DISALLOWED(
153155
res.headers.location,
154156
parsed.href,

0 commit comments

Comments
 (0)