← Back to Pull requests

[14.0][FIX] dms: scope directory share tokens to the token's own subtree #511

Open
victoralmau opened this pull request with 490 lines diff across 6 files
View on GitHub
victoralmau victoralmau commented on Aug 24, 2026 07:25 UTC
Author

Backport from 15.0: https://github.com/OCA/dms/pull/509

check_access_token in dms/models/dms_file.py walks up the directory tree to decide whether the token's directory is the file's own directory or one of its ancestors — but both comparisons test the walker against itself rather than against the token's directory (item). On 18.0, L181 and L185:

directory_item = self.directory_id
while directory_item.parent_id:
    if directory_item.id == self.directory_id.id:   # true on the first iteration
        return True
    directory_item = directory_item.parent_id
# Fix last level
if directory_item.id == self.directory_id.id:       # also always true
    return True

On the first iteration directory_item is self.directory_id, so it returns immediately; and if the directory has no parent the loop body never runs, at which point the "fix last level" line makes the same always-true comparison. The whole if items: block reduces to return True — the token's own directory is never consulted. Stated once: the effect is that any valid directory share token authorises read of every dms.file in the database, irrespective of directory or group inheritance.

dms.directory.check_access_token (models/directory.py L241) does the same walk correctly, comparing against item.id at L251/L257/L261 — the intended logic is already in the tree next door.

The portal hunk is mandatory, not optional

_get_files (controllers/portal.py L162) calls check_access_token on an empty dms.file recordset at L187, where self.directory_id.id is False. The loop is skipped and the always-true False == False on the last-level line is currently what makes shared-folder listings work at all.

Fix the model alone and every shared folder renders empty: HTTP 200, no traceback, nothing in the log. So the two hunks have to land together. The token belongs to a directory, so it is validated against the directory being browsed — exactly what _get_directories (L193) already does. _get_files returns early when dms_directory_id is falsy, so the browse() is always on a real id.

Bounded walk

The ancestor walk is unbounded in both files. Before this fix the file-side loop always returned on iteration one, so it never actually

traversed; once it does, a parent_id cycle would spin indefinitely on a request that needs no authentication. _check_directory_recursion rejects cycles created through the ORM, so realistically only corrupted data reaches it, but the seen set costs nothing.

Tests

8 regression tests in dms/tests/test_access_token.py — unrelated trees, root-level files, descendant directories, a file's own token, and the shared-folder listing the portal hunk protects. Red before, green after.

Scope

This block is byte-identical on 12.0 through 18.0 and dates to the 13.0 migration, so the released branches carry it too. Landing it in https://github.com/OCA/dms/pull/475 means 19.0 never ships it. This PR is the 18.0 backport. The same change is going to 17.0, and to the 19.0 migration in https://github.com/OCA/dms/pull/475. 16.0 and older carry the same model defect but need a hand-port, since _get_files/_get_directories do not exist there — happy to send those on request rather than opening PRs unasked.

Disclosure

Being straightforward: the root cause and impact are already described in the commit body on our public fork. We found this auditing our own production instance and fixed it there before working out how to raise it upstream, and OCA/dms has private vulnerability reporting disabled — so by the time we got here there was no quiet route left. Flagging it rather than leaving you to find it. Our own instance had never created a share token, so we were never exposed.

Assisted-by: Claude Opus 5

Please @pedrobaeza and @carlos-lopez-tecnativa can you review it?

@Tecnativa

Diff: 490 lines (+367 / -123) across 6 files Reviewer: None requested Review duration: 145359m
All Vouch review confidence checks passed
Residual risk 0.52 = Change Risk (0.90) × (1 − Review Confidence (0.42)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.90 · 490 lines diff across 6 files
0.90
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: 10%
42%
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
Diff Size diff_size
0.371
Shallow Review Depth shallow_review_depth
0.344
No Reviewer Assigned no_reviewer_assigned
0.120
Sensitive Paths sensitive_paths
0.090
Real PR Conversation Timeline
1 comments
"Review active on #511"
general weight: 0.35
Reviewers
None requested
Assignees
victoralmau victoralmau
Labels
risk: medium confidence: 42.2% reviewed sensitive_module
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: 89.6% (HIGH) · Higher = larger blast radius
89.6%
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: 42.2% · Lower = rushed or shallow review
42.2%
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: 51.8% · Moderate risk
51.8%
Repository