Keep guests from changing family configuration through the API and imports
Merged
GF
2mo ago+855+855+012345678901234567890123456789-240-240-012345678901234567890123456789
Problem
#4004 added require_non_guest! to the web controllers for categories, tags, merchants and rules. Guests can still change family configuration through other paths:
- the API: with an API key they created themselves, a guest can create, update and delete tags, create categories and import merchants;
- imports: a guest can create and publish category, merchant, rule and Sure imports (in the web UI and through the API), and revert, cancel or delete ones someone else published. Reverting or deleting an import destroys the accounts and entries it created. Transaction-style imports also create a new category or tag for every unmapped value on publish;
- the UI still offers guests the controls for these actions, which now only lead to an alert, and the "create a rule for this category?" prompt.
What changes
- The API returns 403
forbiddenfor guest-owned credentials on tag create/update/destroy, category create and merchant create. ImportsControllerrejects guests on every action that changes a category, merchant, rule or Sure import (create,update,publish,revert,cancel,apply_template,destroy).- A guest can't publish an import while any category or tag mapping would create a new record; mapping to an existing one or leaving it empty still works.
- The API rejects guest credentials for category, merchant, rule and Sure imports and for import sessions, and refuses auto-publish of a guest import that would create categories or tags.
- The import steps (upload, configuration, QIF categories, rows, mappings) only let a guest edit an import that doesn't write family configuration, and only while it is pending or failed, so a guest can't swap another member's configuration file or switch a mapping to "add as new" after publishing.
- The assistant (chat and MCP) leaves the create/update category and tag tools out of a guest's tool list.
destroynow requires write access to the import's accounts, likepublishandrevertalready do. A guest may revert or delete an import only if they can also write every account it created.- Guests no longer see New, Edit, Delete, Merge, Delete all, Apply all, Import and Enhance on these pages; the rule on/off toggle is shown disabled. This also covers the category dropdown on a transaction, the "New rule" item in the transactions menu, the budget page's "no categories" buttons, the configuration import options and the revert/delete buttons for configuration imports.
- Guests no longer get the "create a rule?" prompt, since they couldn't save the rule.
- Index pages and API reads stay available to guests. Members and admins are not affected, except that deleting an import now needs write access to its accounts.
How
- Reuses
require_non_guest!from #4004. - New
Api::V1::BaseController#reject_guest_writes!, after the existing scope checks. Import::FAMILY_CONFIG_TYPES,Import#family_config?andImport#creates_categories_or_tags?decide which imports change family configuration. The import guards redirect HTML requests and answer other formats with 403, likerequire_non_guest!.- Views wrap the write controls in
unless Current.user&.guest?, like the existingCurrent.user&.admin?checks. - English and German strings for the alerts; the rswag specs document the new 403 responses and
docs/api/openapi.yamlis regenerated.
No migration, no data changes. Syncs, balances, budgets and reports are untouched.
Tests
test/integration/guest_read_only_config_test.rb(web, including import create/publish/revert/cancel/delete and hidden controls) andtest/controllers/api/v1/guest_config_writes_test.rb(API).- Guest publish of an import with new categories, guest API imports of configuration types and import sessions, and a 403 for non-HTML requests.
test/controllers/imports_controller_test.rb: a member cannot delete an import whose entries are in a read-only shared account.test/controllers/transaction_categories_controller_test.rb: no rule prompt for guests.bin/rails test: 10812 runs, 0 failures, 0 errors; rubocop, erb_lint and Brakeman clean.
Screenshots
Summary by CodeRabbit
- Access and Permissions
- Guest accounts can view shared categories, tags, rules, merchants, and imports, and map items to existing categories. They cannot change family configuration or manage related imports; unauthorized changes are blocked in the app and API.
- Guest-facing pages hide controls for managing categories, tags, rules, merchants, and imports.
- Guests cannot publish imports that create categories or tags, or use family-configuration import options.
- Guests cannot use assistant actions to create or update categories and tags.
- Bug Fixes
- Guests can change a transaction’s category without seeing a prompt to create a category rule.
- Import deletion is restricted when its entries belong to an account the user cannot edit.