Skip to content

[Bug]: Cookies unable to encode UTF-8 strings #1282

@shamsup

Description

@shamsup

Which Remix packages are impacted?

  • remix (Remix core)
  • create-remix
  • @remix-run/architect
  • @remix-run/cloudflare-workers
  • @remix-run/dev
  • @remix-run/express
  • @remix-run/netlify
  • @remix-run/node
  • @remix-run/react
  • @remix-run/serve
  • @remix-run/server-runtime
  • @remix-run/vercel

What version of Remix are you using?

any

What version of Node are you using? Minimum supported version is 14.

14+

Steps to Reproduce

from sergiodxa/remix-auth#115 (@thangngoc89)

Try to encode a cookie with a UTF-16 string - ie "Nguyễn Văn A"

Essentially btoa expects a string to be binary, so encountering characters that are UTF-16 encoded with more than 8 bits will throw an error. This is well-documented by Mozilla. In JSON and JavaScript, strings are UTF-16, so representing the characters is not an issue. However, this means that JSON.stringifying a string does not make it safe for btoa.

Expected Behavior

Cookie properly set 😎

Actual Behavior

Cookie is not set and error is swallowed

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions