Repository navigation
fix: ignore client patches of server-only control fields - #7119
Open
joaoaracheski wants to merge 2 commits into
Open
joaoaracheski wants to merge 2 commits into
joaoaracheski wants to merge 2 commits into
Conversation
Session.apply_patch() passed the props sent by the client straight to patch_dataclass(), so a client could overwrite `data` (and other `skip` fields), private `_` attributes and event handlers. It now drops those keys and logs a warning. `_selected_index` and `_dismissed`, which the Flutter client sends on purpose, are still applied.
This branch has not been deployed
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.
Description
Follow-up to my email with @FeodorFitsner.
Session.apply_patch()applies the props the client sends inUPDATE_CONTROL_PROPS(andapply_page_patch()the page props on register). It passed them straight topatch_dataclass(), so the client could also set fields the server never sends to it:data, on the page or any control. It's askip_field(), so it never goes to the client, but it was accepted when it came back;skipmetadata;_names (patch_dataclass()sets them even when they're not declared);on_change.An app that keeps the signed in user or their permissions in
page.datacould have them changed from the browser.Now
apply_patch()drops those keys before patching and logs a warning for each one._selected_index(AutoComplete.selected_index) and_dismissed(Banner,SnackBar) are the only_props the Flutter client sends back to Python, so they're kept inCLIENT_PRIVATE_PROPS.The filter only looks at top level keys. Nested objects like
page.windoware still patched as before. If you'd rather have the check insidepatch_dataclass(), I can move it.Test code
Before:
{'user': 'alice', 'groups': ['admins']}.After:
{'user': 'alice', 'groups': ['operators']}.New
tests/test_session_apply_patch.pyhas 9 tests: the client can't changedata(page and control),_names oron_change, while regular props, the page route and width,selected_indexand_dismissedstill go through. 5 of them fail without the fix. flet: 625 passed.Type of change
Checklist
website/sidebars.ymlfor breaking changes, removals, and deprecations, if applicable.Additional details
Found it in an internal tool at work that runs on Flet web and keeps the user's groups in
page.data. I've been running a similar filter there.Summary by Sourcery
Restrict client property patches to writable fields so server-managed application state cannot be modified from the browser.
Bug Fixes:
Enhancements:
Tests: