Skip to content

fix: ignore client patches of server-only control fields - #7119

Open
joaoaracheski wants to merge 2 commits into
flet-dev:mainfrom
joaoaracheski:fix-apply-patch-client-writable
Open

joaoaracheski wants to merge 2 commits into
flet-dev:mainfrom
joaoaracheski:fix-apply-patch-client-writable

Conversation

@joaoaracheski

@joaoaracheski joaoaracheski commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

Follow-up to my email with @FeodorFitsner.

Session.apply_patch() applies the props the client sends in UPDATE_CONTROL_PROPS (and apply_page_patch() the page props on register). It passed them straight to patch_dataclass(), so the client could also set fields the server never sends to it:

  • data, on the page or any control. It's a skip_field(), so it never goes to the client, but it was accepted when it came back;
  • other fields with skip metadata;
  • private _ names (patch_dataclass() sets them even when they're not declared);
  • event handlers like on_change.

An app that keeps the signed in user or their permissions in page.data could 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 in CLIENT_PRIVATE_PROPS.

The filter only looks at top level keys. Nested objects like page.window are still patched as before. If you'd rather have the check inside patch_dataclass(), I can move it.

Test code

from flet.messaging.connection import Connection
from flet.messaging.session import Session
from flet.pubsub.pubsub_hub import PubSubHub

conn = Connection()
conn.pubsubhub = PubSubHub()
session = Session(conn)
page = session.page

page.data = {"user": "alice", "groups": ["operators"]}
session.apply_patch(page._i, {"data": {"user": "alice", "groups": ["admins"]}})
print(page.data)

Before: {'user': 'alice', 'groups': ['admins']}.
After: {'user': 'alice', 'groups': ['operators']}.

New tests/test_session_apply_patch.py has 9 tests: the client can't change data (page and control), _ names or on_change, while regular props, the page route and width, selected_index and _dismissed still go through. 5 of them fail without the fix. flet: 625 passed.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • I signed the CLA.
  • I have performed a self-review of my own code.
  • My code follows the style guidelines of this project.
  • I have commented my code, particularly in hard-to-understand areas.
  • My changes generate no new warnings.
  • New and existing tests pass locally with my changes.
  • I have made corresponding documentation changes, if applicable.
  • I have added changelog entries for user-facing changes, if applicable.
  • I have updated release guide pages and website/sidebars.yml for 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:

  • Prevent client-supplied patches from overwriting server-only control properties, private attributes, and event handlers while preserving supported client-reported state updates.

Enhancements:

  • Log warnings when unauthorized client patch fields are ignored.

Tests:

  • Add coverage for blocked server-only fields, allowed regular and client-specific properties, page patches, and warning logs.

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.
Copilot AI balanced review requested due to automatic review settings November 22, 2026 02:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants