Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

req.url protocol and host are incorrect when used behind AWS ALB with SSL termination #54748

Closed
1 task done
andycansdale opened this issue Aug 30, 2023 · 10 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template. locked

Comments

@andycansdale
Copy link

andycansdale commented Aug 30, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:22 PDT 2023; root:xnu-8796.121.3~7/RELEASE_X86_64
    Binaries:
      Node: 20.2.0
      npm: 9.6.6
      Yarn: 1.22.19
      pnpm: 8.6.1
    Relevant Packages:
      next: 13.4.12
      eslint-config-next: 13.4.9
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 4.9.5
    Next.js Config:
      output: standalone

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue or a replay of the bug

None

To Reproduce

You would need to replicate the infrastructure as mentioned in the bug report. Or perhaps another infrastructure with SSL termination before reaching the NextJS app, but where the original request was made via https.

Describe the Bug

We deploy NextJS behind an AWS Application Load Balancer which terminates SSL. After upgrading from 13.4.12, the protocol and host value in our middleware is different.

Before
req.url: http://ip-10-x-x-x.ec2.internal:5000/dashboard
req.NextUrl.host: ip-10-x-x-x.ec2.internal:5000
req.NextUrl.protocol: http

After
req.url https://10.x.x.x:5000/dashboard
req.NextUrl.host 10.x.x.x:5000
req.NextUrl.protocol https

Not only has the hostname changed to an IP address, the protocol is now shown as https when in fact the request from our ALB uses http.

I believe the issue started with 13.4.13-canary.0, but I can't confirm as that release also broke our healthcheck endpoint! I can confirm it is still an issue in the latest canary release at the time of writing this.

The req.url and req.nextUrl values are logged to the console at the very beggining of our middleware before any other changes are made.

Expected Behavior

Expected behaviour is for the protocol to be correct for req.url in middleware.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

AWS, ALB + ECS

@andycansdale andycansdale added the bug Issue was opened via the bug report template. label Aug 30, 2023
@andycansdale andycansdale changed the title req.url protocol and host are incorrect when used behing AWS ALB with SSL termination req.url protocol and host are incorrect when used behind AWS ALB with SSL termination Aug 30, 2023
@andycansdale
Copy link
Author

By the way, the issue that this causes is that it completely breaks our NextResponse rewrites which now have the wrong protocol & host values after updating just the path from the original req.url.

@crathor
Copy link

crathor commented Aug 30, 2023

13.4.13 works for me but as soon as I upgrade to 13.4.15 or higher it fails the same as above

@phev8
Copy link

phev8 commented Aug 31, 2023

Might we have missed some config where this behaviour can be changed?

Just wondering, because this issue makes the newer releases of NextJS unusable in this setup, but there are not many responses (either by the dev team or others). Maybe not so many people use NextJS with "self-hosting" on a cluster (e.g. AWS, GCP, Azure, OpenShift)... In our case, we had to downgrade NextJS and are stuck at the moment with an earlier release until this is fixed. (I refer to the other issue raised ca. a week ago as well)

(I love NextJS and huge respect to the team building it - just to clarify :-) )

@deflomu
Copy link

deflomu commented Sep 13, 2023

We face the same issue. This prevents us from updating to nextjs 13. We can also not set a hostname via env or config because our application servers multiple hostnames.

@andycansdale
Copy link
Author

@deflomu I haven't tested in production yet, but this is supposed to be fixed by this PR #54813 which is available on the latest canary release. The PR by @DuCanhGH was closed in preference to the previous one. Let's hope it works because this blocked a lot of projects.

@florianmutter
Copy link

We face the same issue. This prevents us from updating to nextjs 13. We can also not set a hostname via env or config because our application servers multiple hostnames.

Works as expected for us with latest canary build.

@phev8
Copy link

phev8 commented Sep 20, 2023

For me, the issue seems to be still present in v13.5.1, when using my reproduction steps from here: #54450

@phev8
Copy link

phev8 commented Sep 20, 2023

Works as expected for us with latest canary build.

The changes from that PR were reverted in the next canary, weren't they?

@andycansdale
Copy link
Author

We're running 13.5.1 with no issues now. Our middleware redirects have the correct protocol and host.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 5, 2023

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Oct 5, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants