Skip to content

fix: prevent invalid Content-Type and Location headers - #7343

Closed
highoncomputers wants to merge 1 commit into
expressjs:masterfrom
highoncomputers:fix/content-type-false-redirect-undefined
Closed

highoncomputers wants to merge 1 commit into
expressjs:masterfrom
highoncomputers:fix/content-type-false-redirect-undefined

Conversation

@highoncomputers

Copy link
Copy Markdown

Two small fixes in lib/response.js:

  1. res.set('Content-Type', value) with an unrecognized type (fixes res.set('Content-Type') silently sets header to literal string 'false' for unknown types #7034)
    When mime.contentType(value) returns false for unknown types, the header was set to the literal string false. Added a fallback to the original value.

  2. res.redirect(undefined) sending malformed Location: undefined (fixes res.redirect(undefined) sends invalid Location: undefined header #6941)
    Added early return when address is falsy or not a string, preventing encodeUrl(undefined) from setting an invalid Location header.

Closes #7034
Closes #6941

- res.set('Content-Type', unrecognized) no longer sets header to
  literal 'false' when mime.contentType() returns false
- res.redirect(undefined) now returns early instead of sending a
  malformed Location: undefined header

Closes #7034
Closes #6941

Co-authored-by: dougwilson <dougwilson@users.noreply.github.com>
@krzysdz

krzysdz commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

@krzysdz krzysdz closed this Jul 1, 2026
@highoncomputers
highoncomputers deleted the fix/content-type-false-redirect-undefined branch July 1, 2026 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants