dev mode ignoring `X-Forwarded-Proto` and `X-Forwarded-Host` headers
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Discussed in https://github.com/sveltejs/kit/discussions/11900
Originally posted by yannishin February 26, 2024
I expected the return from the Hook to be event.url.host=ui.foo.com, event.url.protocol=https:, but it is returning event.url.host=ui_server/ui, event.url.protocol=http:.
How should I solve this issue?
Given that event.request.headers.get("X-Forwarded-Host") and event.request.headers.get("X-Forwarded-Proto") are returning null, it seems that the node server(adapter-node.) is not recognizing the X-Forwarded-??? headers.
For reference, the API Server developed with spring boot is correctly returning ui.foo.com, https:.
This is Nginx Config
upstream ui_server {
ip_hash;
ui.foo.com:17001;
keepalive 100;
}
location /ui {
proxy_pass http://ui_server/ui;
proxy_http_version 1.1;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Forwarded "for=$proxy_add_x_forwarded_for; host=$host; proto=$scheme";
charset utf-8;
access_log /opt/naon/app/nginx/logs/ui-access.log postdata;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue in the adapter-node dev server with the supplied Nginx configuration and forwarded headers. Inspect how the server derives event.url from the request, and consider the work done when event.url.host and event.url.protocol reflect X-Forwarded-Host and X-Forwarded-Proto.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100