Saving user preferences should validate keys
Currently, there's a risk of other GET params being saved into the user's preferences, like:
debug: true
save:
has_fulltext: true
Related to #740 feature
@mekarpeles Is this still an issue? The reference issue is closed but obviously this one isn't. It's a high priority so it should be scheduled if it isn't already.
FWIW, I was able to reproduce this.
Hi @mekarpeles — I can confirm this is still live on master, and I'd like to take it since the previous volunteer went quiet.
Both account_privacy.POST and account_notifications.POST in openlibrary/plugins/upstream/account.py hand the whole web.input() to user.save_preferences(), so any extra form/query param (save, debug, has_fulltext, …) ends up persisted in the user's preferences doc — the classic mass-assignment shape.
Plan: in each handler, build an explicit dict with only the keys that form owns — {"updates"} for notifications, {"public_readlog", "safe_mode"} for privacy — and pass that to save_preferences. I'd leave save_preferences itself untouched: other callers (yrg_banner_pref, pda, rpd) rely on it accepting arbitrary keys, and narrowing it would widen the blast radius of this fix. Two unit tests in test_account.py assert stray params are dropped. It's ~7 lines plus tests, already green locally, so I can open the PR the moment it's assigned.
Any reason not to go with the handler-level fix rather than a global whitelist in save_preferences?
(Full disclosure: I used an AI assistant to help trace the call sites; the analysis, patch and tests are mine and I've read every line.)
It looks like @jabrailkhalil may already have a PR for this?
You're right, #13598 (opened Sept 10) covers it and I missed it when I asked — withdrawing. Happy to review it if that helps.