Prevent guests from mutating family configuration
Merged
RY
2mo ago+156+156+012345678901234567890123456789-0-0-0123456789
Problem
Guests are read-only by design (see the comment in ConnectorAuthorizable), but the controllers for family-wide configuration had no role check at all. A user with the guest role could:
- create, rename and delete categories, tags and merchants (including "delete all")
- create, edit and delete rules, and apply them to existing transactions (
apply,apply_all) — rewriting transactions across the whole family, including accounts shared read-only with the guest
Fixes #3992.
What changed
- Added
ApplicationController#require_non_guest!, following the existingrequire_admin!pattern (redirect + alert for HTML,head :forbiddenfor turbo_stream/json). Allows member, admin and super_admin; blocks guests. - Added
before_action :require_non_guest!, except: %i[index]toCategoriesController,TagsController,FamilyMerchantsControllerandRulesController, so read-onlyindexstays open to guests while every mutation action (includingapply/apply_all/confirm,merge,bootstrap,enhance,destroy_all) is gated. Usingexcept:keeps future actions deny-by-default for guests. - Also gated the nested
Category::DeletionsControllerandTag::DeletionsController. - Added
shared.require_non_guestlocale key ("Guests cannot perform this action") toen.yml; other locales fall back viaconfig.i18n.fallbacks.
Read-only views are unchanged; guests still see the pages but can no longer mutate anything through them.
Validation
- Ran the affected controller tests: 67 runs, 287 assertions, 0 failures, 0 errors. Includes 13 new tests: guest is redirected to the accounts page with no record created/destroyed and no job enqueued; member can still create (all four controllers).
- Ruby syntax checked on all changed files; YAML parses cleanly.
Possible follow-ups (out of scope): hiding the mutation buttons in views for guests, and auditing the api/v1 category/tag/rule endpoints against the guest role.
Summary by CodeRabbit
- Access Control
- Guests can continue viewing category, merchant, rule, and tag lists, but cannot create or delete these items. HTML requests redirect to accounts with an explanatory message; other request types receive a forbidden response.
- Family members retain the ability to manage these items.