You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling res.redirect(undefined) currently sends a 302 response with the header Location: undefined. While there is a deprecation warning printed to the console ("Provide a url argument"), the actual HTTP response is malformed because undefined is not a valid URL.
While it’s not a valid URL, we convert any argument to a string, which is why passing undefined is valid and will trigger a 302.
With the new deprecation, Express v6 is expected to throw an error based on the data type, although it’s still the developer’s responsibility to perform validations for their redirect.
Submitted a fix for this in PR #7103. The res.redirect() function now throws a TypeError immediately when called with missing or invalid arguments instead of sending a malformed Location header.
For context: the 5.x deprecation warnings for invalid res.redirect() arguments (added in #6405) had no test coverage, so I opened #7590 to add tests for them. It doesn't change any behavior and doesn't close this issue. Making res.redirect() throw for invalid arguments is still the semver-major change tracked in #6404 for 6.x.
For context: the 5.x deprecation warnings for invalid res.redirect() arguments (added in #6405) had no test coverage, so I opened #7590 to add tests for them. It doesn't change any behavior and doesn't close this issue.
You and other LLM users and bots have opened PRs adding tests checking the deprecation warning. Please don't.
Please don’t open PRs to address that deprecation.
Activity
fix: throw TypeError for invalid url in res.redirect
BOXER78 commentedon Dec 5, 2025
@efekrskl Please review my PR for this issue.
test: add failing test case for res.redirect(undefined) ref expressjs…
bjohansebas commentedon Dec 11, 2025
While it’s not a valid URL, we convert any argument to a string, which is why passing
undefinedis valid and will trigger a 302.With the new deprecation, Express v6 is expected to throw an error based on the data type, although it’s still the developer’s responsibility to perform validations for their redirect.
Ref: #6391
vishalgupta-02 commentedon Dec 19, 2025
@BOXER78 I would like to work on this issue. Please assign this to me
/assign
esat54 commentedon Jan 8, 2026
This looks like an edge case. Maybe additional validation could help here.
fix: throw TypeError for invalid arguments in res.redirect()
fix: throw TypeError for invalid arguments in res.redirect()
fix: throw TypeError when url is undefined in res.redirect()
jonchurch commentedon Feb 25, 2026
Location: undefinedis absolutely a valid Location header.Whether or not it is intuitive, or should behave this way, is another issue. But it is not correct to say that it is a malformed HTTP
Locationheader.Even
Location:is a valid Location header per the spec.fix(redirect): throw TypeError instead of deprecating on missing/inva…
zakiscoding commentedon Mar 12, 2026
Submitted a fix for this in PR #7103. The res.redirect() function now throws a TypeError immediately when called with missing or invalid arguments instead of sending a malformed Location header.
fix: throw TypeError when redirect URL is not provided
fix(redirect): throw TypeError for missing/invalid url or status
Gustavo-Luiz2304 commentedon Nov 8, 2026
For context: the 5.x deprecation warnings for invalid
res.redirect()arguments (added in #6405) had no test coverage, so I opened #7590 to add tests for them. It doesn't change any behavior and doesn't close this issue. Makingres.redirect()throw for invalid arguments is still the semver-major change tracked in #6404 for 6.x.krzysdz commentedon Nov 8, 2026
You and other LLM users and bots have opened PRs adding tests checking the deprecation warning. Please don't.