Add opt-out for cookie and session persistence in Language::setLang#30
Open
kloostermanw wants to merge 1 commit into
Open
Add opt-out for cookie and session persistence in Language::setLang#30kloostermanw wants to merge 1 commit into
kloostermanw wants to merge 1 commit into
Conversation
REST APIs resolve language statelessly from the Accept-Language header, but setLang() always wrote a 30-day language cookie and $_SESSION['language']. That cookie then replayed on every later request from the same client, leaking one endpoint's language choice across the whole API. setLang() now takes a second $blnPersist argument (default true, so all existing callers are unchanged). Passing false loads the language file in-process only, skipping both the cookie and the session write. The cookie write moves into a protected writeCookie() method so stateless callers can bypass it. references neverwoods#29
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.
Summary
Language::setLang()gains an optional second argument,$blnPersist(defaulttrue). Passingfalseloads the languagefile in-process only, without writing the
languagecookie or$_SESSION['language'].Motivation and Context
REST APIs resolve language statelessly from the
Accept-Languageheader, but
setLang()unconditionally wrote a 30-day cookie and asession value. That cookie then replayed on every subsequent request
from the same client, so a single endpoint's
?language=choiceleaked across the whole API. The Celery web API needs a way to load a
language in-process without any cookie or session side effects.
The default
truepreserves today's behavior for every existingcaller; only callers that pass
falseopt into the stateless path.The cookie write is extracted into a
protected writeCookie()methodso stateless callers can bypass it (and so it is observable in tests,
since the CLI SAPI sends no real headers).
closes #29
How Has This Been Tested
LanguageTestcover the three acceptancecases: no-persist writes neither cookie nor session but still loads
the language file; the default still writes both.
phpstan analyse(level 6,classes/) reports no errors.Types of Changes
Checklist