Repository navigation
Conversation
The account privacy and notifications forms POST the full web.input() payload into save_preferences, so arbitrary query/form params (like the submit button 'save', or 'debug'/'has_fulltext') were persisted to the user's preferences document. Whitelist the preference keys that are actually read or written by the codebase and drop everything else before merging into the stored preferences.
for more information, see https://pre-commit.ci
Contributor
Author
|
The CI workflows for the current head |
jimchamp
approved these changes
Sep 19, 2026
jimchamp
left a comment
Collaborator
There was a problem hiding this comment.
Thanks. @jabrailkhalil!
Noting that this will not remove any "junk" keys that may have been persisted prior to this change. Staff could potentially clean this up by updating preferences in the store and store_index tables directly (they should take care not to delete/modify the type, _key, and _rev fields in the record).
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.
Closes #832
Summary
account_privacyandaccount_notificationsPOST handlers saveweb.input()(the full form/query payload) into the user's preferences document viaUser.save_preferences. As #832 reports, that persists junk keys such as thesavesubmit button,debug, orhas_fulltextinto/people/{user}/preferences.This PR centralizes key validation in
User.save_preferences: only keys the codebase actually reads or writes are merged into stored preferences; everything else is dropped.Whitelist (from usages across the repo):
public_readlog,safe_mode- privacy formupdates,update,notify- notifications form and legacy defaultspda,rpd- print-disability helpers (OpenLibraryAccount.update_pd)yrg_banner_pref- banner dismissal persistencetypeis managed internally and is forced topreferencesafter the merge, so it is intentionally not in the whitelist.Behavior
Unchanged for all legitimate flows: both forms submit only whitelisted fields, and backend callers (
update_pd, hide-banner endpoint) use whitelisted keys. Unknown keys posted by clients are no longer persisted.Testing
openlibrary/plugins/upstream/tests/test_models.py:test_save_preferences_ignores_unknown_keys- reproduces the issue payload (save,debug,has_fulltext); fails without the fix, passes with it.test_save_preferences_keeps_known_keys- guards the whitelisted keys.pytest openlibrary/plugins/upstream/tests/test_models.py openlibrary/tests/fastapi/test_hide_banner.py openlibrary/tests/fastapi/test_account.py: my new tests plus all hide-banner/account endpoint tests pass (54 passed, 1 xfailed when run with the related fastapi files;test_models.pystandalone: 11 passed with 2 pre-existing ContextVar-ordering failures inTestModelsthat also fail on unmodified master in a standalone run).ruff check+ruff format,codespell,auto-walrus,mypyon the changed files: clean.Pre-commit hooks were not run as a whole (no Python 3.14 on PATH on this machine); equivalent individual hooks were run directly.