Skip to content

Cookies in header() are differently encoded in server action and server request.Β #77022

Open
@yongholeeme

Description

@yongholeeme

Link to the code that reproduces this issue

https://github.com/yongholeeme/reproduction-bug-cookies-encoding-in-server-action-and-server-reqeust

To Reproduce

In production

  1. Start the application in production (next build && next dev)
  2. Click redirect in server actions to /test
  3. In the third line, AAA value is encoded.

Current vs. Expected behavior

In server, there are two ways to get cookies. First, reading cookies from cookies() function. And another way is reading cookies in header from headers() function. But I found cookies in headers() work sort of differently between general server request and server action reqeust.

In general server request, headers().get('cookie') returns values barely regardless of whether each value is encoded or not. However in server action request, headers().get('cookie') returns all values as encoded. It's totally the same code but behave differently when it's be excuted.

This problem is only reproduced in production. cc #77010

production.mov

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:06:23 PDT 2024; root:xnu-11215.41.3~3/RELEASE_ARM64_T8132
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 22.11.0
  npm: 10.9.0
  Yarn: N/A
  pnpm: 9.15.4
Relevant Packages:
  next: 15.3.0-canary.1 // Latest available version is detected (15.3.0-canary.1).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.8.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Cookies, Headers, Server Actions

Which stage(s) are affected? (Select all that apply)

Vercel (Deployed), next start (local)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    CookiesRelated to the async cookies() function.HeadersRelated to the async headers() function.Server ActionsRelated to Server Actions.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions