[14.0][FIX] dms: scope directory share tokens to the token's own subtree #511
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 10%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
victoralmau
Backport from 15.0: https://github.com/OCA/dms/pull/509
check_access_tokenindms/models/dms_file.pywalks 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:On the first iteration
directory_itemisself.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 toreturn True— the token's own directory is never consulted. Stated once: the effect is that any valid directory share token authorises read of everydms.filein the database, irrespective of directory or group inheritance.dms.directory.check_access_token(models/directory.pyL241) 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.pyL162) callscheck_access_tokenon an emptydms.filerecordset at L187, whereself.directory_id.idisFalse. The loop is skipped and the always-trueFalse == Falseon 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_filesreturns early whendms_directory_idis falsy, so thebrowse()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_idcycle would spin indefinitely on a request that needs no authentication._check_directory_recursionrejects cycles created through the ORM, so realistically only corrupted data reaches it, but the seen set costs nothing.Tests8 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