Skip to content

[BUG] Cookies matcher doesn't work properly (cookies wrongly parsed it seems) #888

Closed
@lauri865

Description

@lauri865

Describe the bug

We have a missing cookie rewrite which doesn't work. After some debugging, it seems like the issue is in cookies being wrongly parsed.

Cookies passed to the matcher:
cookies { _ga: 'xxx; codeVariant' }

Cookies from the headers:
cookie: 'xxx; codeVariant=TS; codeStyling=none; _ga_XJ83JQEK7J=xxx; crisp-client%2Fsession%2Fd4cd5bac-6848-4f4d-9a7f-082f5b324b79=xxx; _octo=xxx; sidebar:state=false; cpu_bucket=xxx; preferred_color_mode=xxx; tz=xxx; test=xxx'

This implementation is wrong:

? cookies.split(/(?<!Expires=\w+),/i).map((c) => c.trim())

Cookies are semicolon-separated, not comma-separated.

Steps to reproduce

  1. Add a rewrite to next.config:
    async rewrites() { return { beforeFiles: [ { source: "/test", destination: "https://github.com", missing: [ { type: "cookie", key: "test", }, ], }, ], }; },

  2. Add a cookie test with any value.

  3. The rewrite will always pass.

Expected behavior

Rewrite should

@opennextjs/cloudflare version

1.0.4

Wrangler version

4.17.0

next info output

N/A

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions