Skip to content

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

Open
baima365-web/express
#1

Description

@BOXER78

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.

Activity

  1. added theissue type on Dec 3, 2025
  2. added a commit that references this issue on Dec 3, 2025
    e6f1b1f
  3. BOXER78 commented on Dec 5, 2025

    @BOXER78
    Author

    @efekrskl Please review my PR for this issue.

  4. bjohansebas commented on Dec 11, 2025

    @bjohansebas
    Member

    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.

    Ref: #6391

  5. vishalgupta-02 commented on Dec 19, 2025

    @vishalgupta-02

    @BOXER78 I would like to work on this issue. Please assign this to me
    /assign

  6. esat54 commented on Jan 8, 2026

    @esat54

    This looks like an edge case. Maybe additional validation could help here.

  7. added 2 commits that reference this issue on Feb 21, 2026
    cd9b35c
    da201ec
  8. added a commit that references this issue on Feb 24, 2026
    e665835
  9. jonchurch commented on Feb 25, 2026

    @jonchurch
    Member

    Location: undefined is 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 Location header.

    Even Location: is a valid Location header per the spec.

  10. added a commit that references this issue on Mar 12, 2026
    3accb38
  11. zakiscoding commented on Mar 12, 2026

    @zakiscoding

    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.

  12. added a commit that references this issue on Mar 23, 2026
    4f2efb7
  13. added a commit that references this issue on Mar 26, 2026
    9cabf2c
  14. Gustavo-Luiz2304 commented on Nov 8, 2026

    @Gustavo-Luiz2304

    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.

  15. krzysdz commented on Nov 8, 2026

    @krzysdz
    Contributor

    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.

    Originally posted by @bjohansebas in #7571 (comment)

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions