Skip to content

fix(server): name the language cookie cook_lang so other apps can't shadow it - #800

Merged
LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:fix/lang-cookie-799
Oct 28, 2026
Merged

LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:fix/lang-cookie-799

Conversation

@LeMyst

@LeMyst LeMyst commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Fixes #799 (the language part; the download link lives in the cooklang.org guides).

Problem

Browsers share cookies between every port of a host. On a machine that runs other web apps (a Raspberry Pi kitchen display is the typical case), another app's own lang cookie on kitchen.local shadows CookCLI's:

Other app's lang cookie What happens to the picker
HttpOnly the page's document.cookie write is refused
Secure (set by an HTTPS app) same, from a plain-HTTP page
Domain=.kitchen.local both are sent, the older one first
longer path (/preferences) both are sent, the longer path first

In each case get_preferred_language reads the other app's value (or nothing) and the page reloads in English, whatever language was clicked. I reproduced all four with the 0.39.0 release and the reporter's flags in Chromium. A clean browser works fine, which is why this didn't show up before.

Fix

  • The picker writes cook_lang, named like cook_session.
  • The server reads cook_lang, then the old lang, so a language picked before keeps working.
  • It reads every Cookie header, not only the first one (HTTP/2 can split them).
  • The picker doesn't delete lang, since that cookie may belong to another app.

Tests

  • 5 unit tests in src/web/language.rs: cook_lang, cook_lang over a foreign lang, legacy lang, second Cookie header, unsupported value falls back to Accept-Language.
  • e2e Language picker › wins over a lang cookie set by another app on the same host: presets an HttpOnly lang=en-US, clicks Français. It fails on 0.39.0 (Received: "en-US") and passes here.
  • pantry_api_test and pantry-file.spec.ts now set cook_lang.
  • cargo fmt --check, cargo clippy --all-targets -D warnings clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MmrM92aXqXqbbFGZig3EK9

…hadow it

Browsers share cookies between every port of a host. When another app on
the same machine (a Raspberry Pi running several services, say) keeps its
own `lang` cookie, the picker on /preferences could not win: an HttpOnly
or Secure `lang` refuses the page's `document.cookie` write, and one with
a wider Domain or a longer path is sent first. The page reloaded in
English whatever language was clicked.

The picker now writes `cook_lang`, matching `cook_session`. The server
reads `cook_lang` first and the old `lang` second, so a language picked
before keeps working. It also reads every Cookie header, not only the
first one.

Fixes cooklang#799

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmrM92aXqXqbbFGZig3EK9
@LeMyst
LeMyst marked this pull request as ready for review October 28, 2026 07:10
@LeMyst
LeMyst merged commit af5410f into cooklang:main Oct 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot change language in served web app

1 participant