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

[🐛 Bug]: Compat: Header values for x-vercel-ip-* headers are appended instead of replaced. #507

Closed
1 task done
rphsoftware opened this issue Oct 16, 2023 · 0 comments · Fixed by #508
Closed
1 task done
Labels
bug Something isn't working

Comments

@rphsoftware
Copy link
Contributor

next-on-pages environment related information

System:
Platform: linux
Arch: x64
Version: #1 SMP PREEMPT_DYNAMIC Sat, 23 Sep 2023 22:55:13 +0000
CPU: (20) x64 13th Gen Intel(R) Core(TM) i5-13600K
Memory: 63 GB
Shell: /usr/bin/zsh
Binaries:
Node: 18.12.0
Bun: 1.0.4
pnpm: 7.25.0
Yarn: 1.22.19
npm: 9.2.0
Package Manager Used: npm
Relevant Packages:
@cloudflare/next-on-pages: 1.6.3
vercel: N/A
next: 13.5.4

Description

The header rewrites produce different behavior from running the NextJS application on Vercel.
If a client sends a request with the header x-vercel-ip-city: Atlantis to a deployment hosted on Pages, the API route will see the following header: x-vercel-ip-city: Atlantis, London (assuming the user lives in London).
Meanwhile, the same application hosted on Vercel will see the header as x-vercel-ip-city: London.

Reproduction

Create a next API route with the following code:

export async function GET(request) {
    let headers =  Object.fromEntries(Array.from(request.headers.entries()));
    headers["x-vercel-sc-headers"] = "--redacted--"; // redact private info for deployments on vercel.
    return Response.json({ h: headers })
}

export const runtime = 'edge';

Deploy it to both Vercel and Pages, and send a request with the x-vercel-ip-city: Atlantis header set.

curl -H "x-vercel-ip-city: Atlantis" https://example.com/apiroute | jq '.h["x-vercel-ip-city"]'

Observe that the response differs between Vercel and Pages.

Pages Deployment Method

Pages CI (GitHub/GitLab integration)

Pages Deployment ID

https://0086b0c1.header-accuracy-test.pages.dev

Additional Information

Using set instead of append in https://github.com/cloudflare/next-on-pages/blob/main/packages/next-on-pages/templates/_worker.js/utils/request.ts should fix this problem and make the behavior inline with deployments on Vercel.

Would you like to help?

  • Would you like to help fixing this bug?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant