镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

fix: throw TypeError when res.redirect() receives falsy or non-string URL - #7219

Closed
mixelburg wants to merge 1 commit into
expressjs:masterfrom
mixelburg:fix/redirect-undefined
Closed

mixelburg wants to merge 1 commit into
expressjs:masterfrom
mixelburg:fix/redirect-undefined

Conversation

@mixelburg

Copy link
Copy Markdown

Fixes #6941

Previously, res.redirect(undefined) would silently send a malformed Location: undefined header while only printing a deprecation warning. The HTTP response would contain an invalid Location header that clients cannot properly follow.

This change throws a TypeError for:

  • Falsy URL values (undefined, null, '')
  • Non-string URLs

This prevents invalid HTTP responses and surfaces bugs early during development instead of silently sending broken redirects.

… URL

Previously, res.redirect(undefined) would silently send a malformed
Location: undefined header while only printing a deprecation warning.
Now it throws a TypeError for falsy URL values (undefined, null, '')
and non-string URLs, preventing invalid HTTP responses.

Fixes expressjs#6941
@krzysdz

krzysdz commented May 6, 2026

Copy link
Copy Markdown
Contributor

Duplicate of #6404

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

res.redirect(undefined) sends invalid Location: undefined header

2 participants