fix(authz): a cross-tenant read in the error-pattern group handler

Read-side sibling of the two cross-tenant writes fixed in the previous commit, and
found the same way: scanning all of src for queries keyed on an entity id that carry
no project_id predicate, then checking each handler-reachable caller for a guard.

`errorGroupMembersGetH` verified the caller may access `pid`, then selected merge-group
members `WHERE canonical_id = #{eid}` with no tenant predicate. So a user on one project
could read another project's error types and messages — and the handler rendered an
unmerge link for each disclosed row under the *caller's* project path, i.e. it handed
out the ids for the write closed in the previous commit.

Both group-member queries are now scoped in-query, covering every caller:
  getErrorPatternGroupMembers :: ProjectId -> ErrorPatternId -> ...
  getLogPatternGroupMembers   :: ProjectId -> LogPatternId   -> ...

I first removed getLogPatternGroupMembers as dead code on the strength of a src-only
grep. That was wrong — LogPatternsSpec:540 asserts on it. Restored and scoped instead,
which is the better outcome: the assertion survives and the first production use is
safe by construction rather than a fresh copy of the error-pattern bug.

Of the 12 unscoped reads the scan surfaced, exactly one was real. The rest were safe by
design (userById, sessionByID — not project-scoped entities), already guarded (apiKeyGet
via ownedOr), or a substring false positive (Settings calls getConfigByProject pid cid,
not the unscoped getConfig). Verified rather than assumed.

VERIFICATION STATUS: library and test targets compile clean with the fix. The break-test
proving the new guard is non-vacuous did NOT complete — the run was cut short at 6
examples when the predicate was restored, and the test never executed. The round-14 pair
was proven this way (698 examples, 2 failures, exactly the two expected); this one has
not been. Outstanding.
This commit is contained in:
Anthony Alaribe 2026-09-03 21:03:32 +02:00
commit f49798eaa0
4 changed files with 49 additions and 11 deletions