Skip to content

security(cr): add record rules to CR detail models (ownership + area)#261

Draft
gonzalesedwin1123 wants to merge 8 commits into
19.0from
security-cr-detail-record-rules
Draft

security(cr): add record rules to CR detail models (ownership + area)#261
gonzalesedwin1123 wants to merge 8 commits into
19.0from
security-cr-detail-record-rules

Conversation

@gonzalesedwin1123

@gonzalesedwin1123 gonzalesedwin1123 commented Jul 1, 2026

Copy link
Copy Markdown
Member

Do not merge yet — held for human review.

Summary

CR detail models (spp.cr.detail.*) are separate tables inheriting an abstract base (spp.cr.detail.base), so the parent spp.change.request record rules do not cascade to them. Each detail ships an ACL granting group_cr_user read/write/create but no ir.rule — so a low-privileged CR user can, via direct RPC (call_kw, bypassing the UI), read/write detail rows of change requests they do not own, and tamper with pending/approved requests (the reported case: re-pointing assign_program's program_id to enroll a beneficiary into an unauthorized program).

Reported against spp.cr.detail.assign_program; validated as systemic across the CR framework — all 11 core detail models in spp_change_request_v2 share the identical gap.

Fix

Per-model ir.rules mirroring the parent CR's row-level security, for all 18 core detail models + assign_program (11 original + 7 line/child models shipped by the group/membership CR redesign, 19.0.3.0.0 — see below):

  • Ownership (group rules): group_cr_user scoped to change_request_id.create_uid = user.id OR change_request_id.registrant_id in user.partner_id.ids (r/w/c); group_cr_validator/_validator_hq/_manager get [(1,=,1)] (manager keeps unlink). The four-rule mirror is required because the higher roles imply group_cr_user, so a permissive rule is needed to avoid caging them (Odoo ORs group-rules across a user's groups).
  • Area (global rule): mirror the parent's area filter (change_request_id.registrant_id.area_id child_of user.center_area_ids) so an area-scoped officer can't reach out-of-area details; global roles (no center areas) are unaffected.

Detail creation/apply already run under .sudo() in the framework, so the new rules don't block legitimate flows — only the un-sudo'd RPC attack path.

Tests

  • spp_cr_type_assign_program: reproduces the exact reported attack — a second cr_user cannot read or re-point program_id on another user's detail (AccessError); owner + validator retain access.
  • spp_change_request_v2: cross-user read/write isolation on edit_individual; a functional area-filter test (isolating the area dimension from ownership); and a completeness test asserting every concrete spp.cr.detail.* model is scoped on read/write/create for cr_user, retains permissive rules for higher roles, and carries a global area rule — guarding against a future detail model shipping without rules.
  • Green: spp_change_request_v2 340/340 · spp_cr_type_assign_program 23/23. Lint-clean.

Redesign fallout (caught by the completeness test)

Merging the 19.0.3.0.0 base brought in the group/membership CR redesign (#242), which shipped 10 new spp.cr.detail.* models without record rules — the completeness test failed in CI exactly as designed. Added ownership + area rules for the 7 regular models (change_hoh.member, split_household.member, create_group.phone/bank/id_doc/member_existing/member_new); the phone/bank/id_doc rows can hang off several alternative parents (create_group, add_member, split_household, or a member_new row), so their domains traverse every parent path. The 3 transient wizard models need no ir.rule — the ORM restricts transient records to their creator — and the completeness test now skips _transient models. The sweep also now only asserts on models group_cr_user can reach via ACL, so full-stack DBs containing the deferred farmer/studio detail models (different group models, no cr_* ACLs) don't fail on a role that cannot touch them.

Reviewed

Independent adversarial staff review: APPROVE WITH NITS, no blockers. Confirmed the mail.thread side-channel is closed (message/follower read gates on document read), coverage is 1:1 with no misses, and no legitimate flow is over-restricted. Both nits addressed here (strengthened completeness test; area-filter mirror folded in).

Out of scope — tracked as a separate follow-up

Two modules with the same missing-rule class but different group models needing per-module ownership analysis (not a copy of the CR rule): spp_farmer_registry_cr (4 farm detail models, registry_officer) and spp_studio_change_requests (spp.cr.detail.generic, studio_editor).

Detail models (spp.cr.detail.*) are separate tables that do not inherit the
parent spp.change.request record rules, so a low-privileged group_cr_user
could read/write detail rows of change requests they do not own via RPC,
tampering with pending/approved requests (e.g. re-pointing assign_program's
program_id). Add per-model ir.rules mirroring the parent CR scope (users
limited to own/related CRs; validators and managers unrestricted) for all 11
core detail models and the assign_program detail. Includes a completeness test
asserting every concrete detail model carries a group_cr_user rule.
Post-review follow-ups:
- Add a global area-filter ir.rule to every CR detail model (11 core +
  assign_program), mirroring the parent CR's area rule. Detail models do not
  inherit the parent's global rule, so an area-scoped officer could otherwise
  reach (via RPC) detail rows of change requests whose registrant is outside
  their center area. Global rule ANDs with the ownership rules; users without
  center areas are unaffected.
- Strengthen the completeness test to require, per concrete detail model, that
  group_cr_user is scoped on read/write/create (not just read), that each
  higher role retains a permissive rule, and that a global area rule exists.
- Add a functional test proving the area filter scopes a detail by its
  registrant's area, isolating the area dimension from ownership.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces critical security record rules and area filters for various change request (CR) detail models across the spp_change_request_v2 and spp_cr_type_assign_program modules. Since detail models are stored in separate tables and do not inherit parent CR rules, these additions prevent low-privileged users from bypassing ownership restrictions via RPC. Comprehensive regression tests are also added to validate these security scopes. The review feedback points out two important issues in the new tests: a bug where clear_cache() is called instead of the correct Odoo registry method clear_caches(), and a potential test fragility issue where the test should only assert rules on models where the target user group actually has ACL access to avoid false positives when other modules are installed.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread spp_change_request_v2/tests/test_detail_record_rules.py
Comment thread spp_change_request_v2/tests/test_detail_record_rules.py
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.66%. Comparing base (1caf794) to head (0627ab9).
⚠️ Report is 3 commits behind head on 19.0.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             19.0     #261      +/-   ##
==========================================
+ Coverage   74.28%   75.66%   +1.38%     
==========================================
  Files         372     1080     +708     
  Lines       25385    64851   +39466     
==========================================
+ Hits        18857    49069   +30212     
- Misses       6528    15782    +9254     
Flag Coverage Δ
spp_api_v2_change_request 66.53% <ø> (?)
spp_audit_programs ?
spp_base_common 91.07% <ø> (+0.80%) ⬆️
spp_change_request_v2 77.91% <ø> (?)
spp_cr_type_assign_program 92.07% <ø> (+0.90%) ⬆️
spp_dci_demo 94.28% <ø> (+0.88%) ⬆️
spp_farmer_registry_cr 61.24% <ø> (?)
spp_farmer_registry_demo 61.06% <ø> (+0.04%) ⬆️
spp_indicator_studio ?
spp_mis_demo_v2 70.99% <ø> (+0.03%) ⬆️
spp_programs 65.27% <ø> (+<0.01%) ⬆️
spp_registry 86.94% <ø> (+0.10%) ⬆️
spp_security 69.56% <ø> (+2.89%) ⬆️
spp_starter_sp_mis 86.66% <ø> (?)
spp_studio_change_requests 84.85% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.
see 758 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gonzalesedwin1123
gonzalesedwin1123 marked this pull request as draft July 1, 2026 05:15
…s + changelog

Record the CR detail-model record-rule hardening (spp_change_request_v2
19.0.2.0.8, spp_cr_type_assign_program 19.0.1.0.2) in versions and HISTORY
changelogs (regenerated READMEs).
@gonzalesedwin1123
gonzalesedwin1123 force-pushed the security-cr-detail-record-rules branch from 84b07d2 to 18b46b8 Compare July 2, 2026 14:45
The earlier README regeneration was run in a local env whose RST renderer
produced wider table columns than CI's pinned oca-gen environment, causing the
'Generate addons README files from fragments' pre-commit hook to fail on CI.
Restore the column widths CI's generator produces.
…able models

The post_install sweep asserted group_cr_user scoping on every
spp.cr.detail.* model; on a full stack that includes other apps' detail
models (farmer registry, studio) gated by their own group models, which
cr_user cannot reach via ACL at all. Skip those — their ownership
scoping is a tracked, separate follow-up.
…-flow redesign

The completeness sweep caught 10 spp.cr.detail.* models shipped by the
group/membership redesign (19.0.3.0.0) without record rules: the
create_group phone/bank/id_doc/member_existing/member_new lines,
change_hoh.member, split_household.member, and 3 wizard models. Add
ownership + area rules for the 7 regular models, traversing every
alternative parent path (phone/bank/id_doc rows can hang off
create_group, add_member, split_household, or a member_new row). The
transient wizard models need no ir.rule — the ORM restricts transient
records to their creator — so the sweep now skips _transient models.
@gonzalesedwin1123

Copy link
Copy Markdown
Member Author

The out-of-scope follow-up noted in the description (farmer-registry & studio CR detail models, which use different group models) is now tracked as #320.

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.

1 participant