Repository navigation
fix(server): name the language cookie cook_lang so other apps can't shadow it - #800
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
langcookie onkitchen.localshadows CookCLI's:langcookieHttpOnlydocument.cookiewrite is refusedSecure(set by an HTTPS app)Domain=.kitchen.local/preferences)In each case
get_preferred_languagereads 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
cook_lang, named likecook_session.cook_lang, then the oldlang, so a language picked before keeps working.Cookieheader, not only the first one (HTTP/2 can split them).lang, since that cookie may belong to another app.Tests
src/web/language.rs:cook_lang,cook_langover a foreignlang, legacylang, second Cookie header, unsupported value falls back toAccept-Language.Language picker › wins over a lang cookie set by another app on the same host: presets an HttpOnlylang=en-US, clicks Français. It fails on 0.39.0 (Received: "en-US") and passes here.pantry_api_testandpantry-file.spec.tsnow setcook_lang.cargo fmt --check,cargo clippy --all-targets -D warningsclean.🤖 Generated with Claude Code
https://claude.ai/code/session_01MmrM92aXqXqbbFGZig3EK9