Commit graph

4 commits

Author SHA1 Message Date
Jonas-PFX
7744cc91be
fix: handle multiple x-forwarded-proto headers (#58824)
### What?
This PR changes how protocol is determined.
A change was recently made (in [PR
57815](1caa58087a (diff-c49c4767e6ed8627e6e1b8f96b141ee13246153f5e9142e1da03450c8e81e96fR1744)))
that did not take into account cases where there are multiple
`x-forwarded-proto` headers. In such cases, the protocol becomes e.g
"https, https".

### Why?
An error will occur in parseUrl on line 1616, since its not a valid url
(e.g. `https, https://localhost:3000`).

### How?
Reverted part of the changes in [PR
57815](https://github.com/vercel/next.js/pull/57815).

Fixes #58764 and fixes #59031

Closes NEXT-2437

---------

Co-authored-by: Balázs Orbán <info@balazsorban.com>
2024-02-14 14:47:26 +01:00
Tom Milewski
c26c7713b5
fix: set x-forwarded-host based on request (#58500)
Co-authored-by: @BRKalow <bryce@clerk.dev>

### What?

A number of our customers have been experiencing issues stemming from an
`x-forwarded-host` header that doesn't match the `host` header.

### Why?

[This PR](https://github.com/vercel/next.js/pull/57815) removes
functionality which sets `x-forwarded-host` to `req.headers['host']` and
relies solely on the server's hostname and port.

This can be seen locally when visiting the app via a localhost
subdomain.

The `x-forwarded-host` header will remain as `localhost:${port}` while
the actual requested host will contain the subdomain.

### Related 

- https://github.com/vercel/next.js/pull/57815#issuecomment-1808496790

---------

Co-authored-by: BRKalow <bryce@clerk.dev>
Co-authored-by: Zack Tanner <zacktanner@gmail.com>
2023-11-16 12:00:41 +01:00
Balázs Orbán
1caa58087a
fix: correctly set x-forwarded-* in Middleware (#57815)
### What?

Follow-up of #56797

While working on this, I noticed that some logic around stripping internal headers was duplicated, so I did some cleanup too.

### Why?

In #56797 we set these headers, but it only affected Route Handlers, Middleware is still missing them, which is a regression introduced in #52492

(Related: https://github.com/vercel/next-learn/issues/252)

### How?

Move to set these headers up to `base-server.ts` so they are present in Middleware too.

> Note: All headers are set with `??=` to respect the original value if set (with other words, only add these headers if they aren't set yet)

Closes NEXT-
Fixes #52266
2023-11-01 04:36:50 +00:00
Balázs Orbán
fe0bfbf911
fix: add x-forwarded-* headers (#56797)
### What?

Adding back `x-forwarded-*` headers.


### Why?

Starting with #52492, these headers were lost.

### How?

We can populate these headers before executing a request.

Closes NEXT-1663
Fixes #55942
2023-10-13 17:58:33 +00:00