← Back to Pull requests

[19.0][FIX] base_user_role_company: fix cross-company privilege escalation … #478

Open
unknown opened this pull request with 242 lines diff across 3 files
View on GitHub
unknown unknown commented on Sep 09, 2026 23:12 UTC
Author

…and migrate 'role_line.company_id' to 'company_ids'

Issue description
Formerly the res.users.group_ids was recomputed and written in DB when a user was browsing from a company to another. This implementation was letting a security risk:

  • a user could let a former browser tab opened with the previous company opened: when browsing this former tab, it was with former company BUT with the rights of the NEWLY opened company in the NEWER tab

  • by API, it was possible to authenticate a user on a Company A and then browse a Company B with the permissions of Company A
  • Fix
    Opportunity:
    Since v19.0, a new computed field all_group_ids exist on res.groups. This field is called by ir.model.access::_get_allowed_models and ir.rule::_compute_domain.

    Solution:
    The fix inherits
    _compute_all_group_ids to make it compatible with company-aware roles. It also adapts calls to @tool.ormcache, so the proper caches are used / unvalidated when self.env.companies changes.
    Note: there is nothing to do on
    ir.rule because the cache is already company-dependant.

    Necessary changes

  • Removal of ir.http::session_info, which was writing the res.users:group_ids: this is now obsolete, and only done at res.users::create/write for UI purpose (and only base on user's main company_id)

  • Controller web_load_menus: add the missing context key allowed_company_ids, needed to compute the proper environment var self.env.companies. If not done, the navbar menu is generated based on the user's default company_id groups (all_group_ids). In other word: the menu item were not dynamically changing when the user was browsing other companies.
  • Side changes / other improvements

  • Simplification of the code for INTERSECTION logic, when 2 or more companies are active

  • File renaming, to follow conventions

  • I also migrated role_line.company_id to a company_ids` fields, more convenient
  • Diff: 242 lines (+181 / -61) across 3 files Reviewer: dreispt Review duration: 105675m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.46) × (1 − Review Confidence (0.41)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 242 lines diff across 3 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    40%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.329
    Real PR Conversation Timeline
    1 comments
    "Review active on #478"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 40.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.8% (MEDIUM) · Higher = larger blast radius
    45.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 40.9% · Lower = rushed or shallow review
    40.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27% · Safe to merge
    27%