mirror of
https://github.com/monoscope-tech/monoscope.git
synced 2026-11-16 10:18:01 +00:00
fix(authz): two cross-tenant writes reachable from web routes
Both are the same shape as the monitors bulk-action hole fixed in an earlier round:
the handler checks the caller may access `pid`, then mutates by entity id alone.
1. `alertSingleToggleActiveH` -> `monitorToggleActiveById` was
`UPDATE monitors.query_monitors ... WHERE id=#{mid}`. A user authorised on one
project could deactivate another project's monitor — silencing its alerting.
The API path was already safe (apiMonitorToggleActive goes through
withRefetch/apiMonitorGet/ownedOr); only the web route was not.
2. `errorUnmergePostH` -> `unmergeErrorPattern` was
`UPDATE apis.error_patterns SET merge_override = TRUE, canonical_id = NULL
WHERE id = #{pid}`. A user on one project could detach another project's error
pattern from its group and corrupt its error grouping. Its three sibling
handlers in the same module each guard with `err.projectId /= pid`; this one
did not.
Fixed structurally rather than at the callers: both queries now take a ProjectId
and filter on it, so the mistake is unrepresentable for every caller present and
future. `unmergeErrorPattern`'s parameter was also named `pid` while holding a
*pattern* id — which is what a project id is called everywhere else in this
codebase, and plausibly how the bug was written. Renamed to `epid`.
Found by scanning all of src for functions that UPDATE/DELETE, take no ProjectId
and carry no project_id predicate (46), filtering to those reachable from a
handler with a user-supplied id (15), then checking each caller for a guard.
Reading alone had already missed these: the bulk-action variant was fixed earlier
and these single-entity siblings survived that pass. The other 13 are genuinely
safe and were verified, not assumed — API keys guard via ownedKey from
projectApiKeysByProjectId, the sibling error-pattern handlers guard on
err.projectId, dashboards go through getDashAndVM pid, and the member-permission
list is derived from projMembers rather than user input.
Guards added, both siblings of the existing bulkAction_doesNotTouchAnotherProjects
Monitors test: singleToggleActive_doesNotTouchAnotherProjectsMonitor and
errorUnmerge_doesNotTouchAnotherProjectsPattern.
CAVEAT ON VERIFICATION: the break-test that would prove these two guards are
non-vacuous did not complete — the run was interrupted when the predicates were
restored. Library and test targets both compile clean with the fix in place, but
neither new test has yet been observed failing without it. Worth re-checking.
This commit is contained in:
parent
9f44ef5364
commit
0b42a201e4
8 changed files with 87 additions and 10 deletions
Loading…
Add table
Add a link
Reference in a new issue