Skip to content

Fixes #36762: filter metric relation fields and memberships by viewer permission - #36764

Merged
yan-3005 merged 5 commits into
mainfrom
agent/ant-2026-2mc20zfu-medium-cwe
Nov 4, 2026
Merged

yan-3005 merged 5 commits into
mainfrom
agent/ant-2026-2mc20zfu-medium-cwe

Conversation

@harshach

@harshach harshach commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

Fixes #36762

A metric's relation fields (parent, children, childrenCount, relatedMetrics, metricGroup), a metric group's member list and metricCount, and the stored change descriptions that quote those references were returned to any caller who could view the carrying entity, without a ViewBasic check on the referenced entities. A user denied ViewBasic on metrics or groups (e.g. via the shipped DomainOnlyAccessRole) could therefore read the id, name, display name and description of hidden entities through three routes: the generic metric reads and write responses, the metric and metric group version histories, and the changeDescription / incrementalChangeDescription recorded on reparenting, regrouping and membership edits — the last one also inside the otherwise filtered hierarchy payloads. relatedMetrics had no write-time check at all, so a restricted user could name a hidden metric there and read its description back.

This PR applies the per-reference ViewBasic check the hierarchy endpoints already use to every Metric and MetricGroup response:

  • MetricRepository.sanitizeMetricRelations filters the reference fields, recounts childrenCount with the visible children, and drops stored change entries for parent, relatedMetrics and metricGroup that name an entity the caller may not view; sanitizeHierarchyMetric (used by the hierarchy endpoints and the members API) now also filters children/relatedMetrics and those change entries.
  • MetricGroupRepository.sanitizeMembership filters the metrics members, drops membership change entries, and recounts metricCount with visibleMetricCount like the hierarchy endpoints; the group objects embedded in metric hierarchy payloads go through it.
  • MetricResource and MetricGroupResource pass list, get, getByName and all write responses (POST/PUT/PATCH/delete/restore/vote) through these sanitizers, with the hasUnconditionalView short-circuit and per-request decision caching the hierarchy endpoints use. Version histories are redacted through the existing snapshotRedaction hook, so callers with unconditional access get byte-identical responses.

Behavior changes accepted: restricted callers see only viewable relations and counts; listVersions re-serializes versions through the POJO for those callers; change events caused by a restricted writer lack the relations that writer cannot see. Not changed: relatedMetrics is still accepted at write time without a check on the named metric (the link is stored but no longer readable back), and the inherited /metrics/history and /metricGroups/history endpoints still lack a per-entity or domain filter (a separate, broader issue).

Type of change:

  • Bug fix

High-level design:

Approach: one sanitizer per entity type, applied at the resource boundary to every response that carries the entity, reusing the exact predicates and short-circuit the hierarchy endpoints established (MetricResource.java:171 hasUnconditionalView, canAccessEntity with MetadataOperation.VIEW_BASIC).

  • jdbi3/MetricRepository.java — sanitizeHierarchyMetric extended (filters children/relatedMetrics, strips invisible-quoting change entries); new sanitizeMetricRelations recounts childrenCount via the existing visibleChildCount; referencesOnlyVisibleEntities parses the JSON-encoded reference payloads stored in FieldChange values. The hierarchy loaders apply MetricGroupRepository.sanitizeMembership to embedded group objects.
  • jdbi3/MetricGroupRepository.java — new sanitizeMembership (member filter, membership-change filter, metricCount recount via the existing visibleMetricCount).
  • resources/metrics/MetricResource.java / MetricGroupResource.java — per-request RelationVisibility/MembershipVisibility (unconditional short-circuit + per-entity decision cache, shared as MetricResource.cachedDecisions); reads, writes and version snapshots (snapshotRedaction override) pass through the sanitizers; PATCH covered by overriding patchInternal (id and fqn overloads), following the existing ServiceEntityResource pattern; group writes keep their withoutMembers step on top. List pages recount the visible childrenCount/metricCount in one batched relationship query per page (sanitizeMetricRelations/sanitizeMembership list variants) so restricted callers don't pay a per-row scan.

Alternatives considered: filtering inside setFields was rejected because the repository layer has no caller context and the same loaded entity serves callers with different permissions; filtering only the REST reads was rejected because version snapshots bypass them. No migration or backward-compatibility concern: the gap exists only on the unreleased hierarchy commit e4e88a41f268, and unrestricted callers see identical payloads.

Tests:

Use cases covered

  • User with a domain-restricted role gets 403 on hidden metrics/groups, and the hierarchy endpoints name none of them (pre-existing, pinned).
  • The same user's generic metric read with ?fields=parent,children,childrenCount,relatedMetrics,metricGroup now returns only viewable references, a visible childrenCount, and no hidden names anywhere in the payload.
  • The same user's metric and metric group version listings and single versions carry no hidden references.
  • After an admin reparents a visible metric below a hidden one (or shrinks a group), the restricted user reads no hidden name in the entity, its hierarchy payload, or its stored change descriptions.

Unit tests

  • I added unit tests for the new/changed logic.
  • Files added/updated: MetricRepositoryTest, MetricGroupRepositoryTest, MetricResourceTest, MetricGroupResourceTest (relation/membership filtering, change-entry parsing, count recounts, conditional vs unconditional resource paths, snapshotRedaction presence/absence, PATCH response sanitization).
  • Coverage % (jacoco, whole class): MetricRepository 30% (33% branches), MetricGroupRepository 42% (40% branches), MetricResource 46% (58% branches), MetricGroupResource 68% (71% branches). The changed classes are large and mostly pre-existing; the new sanitizer methods (sanitizeMetricRelations, sanitizeMembership, referencesOnlyVisibleEntities, change filtering) and the conditional resource paths are exercised by the new unit tests, and the end-to-end routes by the integration test below.

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/ for new/changed API endpoints.
  • Files added/updated: MetricResourceIT (extended hierarchyEndpointsFilterAndSanitizeEveryRestrictedMetricReference with the generic reads, the version histories, and the change-description routes for metrics and groups).

PASSED on 06f08ec8125 (final HEAD).

  • Unit — mvn -B package -pl openmetadata-service -Dtest=MetricGroupRepositoryTest,MetricGroupResourceTest,MetricObservabilityBuilderTest,MetricRepositoryTest,MetricResourceTest,PersonaContextBuilderTest: 126 tests, 0 failures. Amended commit re-run of the four metric classes: 79 tests, 0 failures.
  • Integration, parallel lane (MySQL 8.3 + Elasticsearch 9.3, Testcontainers) — mvn -B verify -pl openmetadata-integration-tests -Pmysql-elasticsearch -DintegrationTests.lane=parallel -Dit.test=ConfigResourceIT,DatabaseSmokeIT,GlossaryTermRelationUsageIT,GlossaryTermResourceIT,MetricAssetsIT,MetricGroupResourceIT,MetricResourceIT,QueryCostRecordResourceIT,QueryResourceIT,QueryVisibilityPolicyIT,SeedDataPresenceIT,TableResourceIT,UsageResourceIT,UserResourceIT: 1588 tests, 0 failures, 0 errors (108 skipped). Includes MetricResourceIT with the extended hierarchyEndpointsFilterAndSanitizeEveryRestrictedMetricReference and all of MetricGroupResourceIT.
  • Integration, targeted — MetricResourceIT#hierarchyEndpointsFilterAndSanitizeEveryRestrictedMetricReference re-run on the amended HEAD: 1/1 passed.
  • Integration, isolated lane — mvn -B verify -pl openmetadata-integration-tests -Pmysql-elasticsearch -DintegrationTests.lane=global-state -Dit.test=MetricMigrationIT,UserMetricsResourceIT: 11 tests, 0 failures.
  • Review round (review comments, HEAD 7f5947da2d4): unit — the four metric classes 81 tests, 0 failures; integration — MetricResourceIT,MetricGroupResourceIT re-run against the new build (list paths now batch the visible count recount per page): 0 failures.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

The integration test above is the reproducer scenario, run locally against MySQL 8.3 + Elasticsearch 9.3 containers: a DomainOnlyAccessRole user confined to Marketing is denied four Finance entities (403), sees none of them in the hierarchy response, and gets no hidden id/name/displayName/description from the generic fields= read, the version histories, or the change descriptions after an admin reparents a visible metric and shrinks a visible group.

UI screen recording:

Not applicable — backend-only authorization fix, no UI impact.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed. — not needed, no schema change.
  • For a UI feature or feature task: as part of PR creation, I ran the PR build in Docker with sample data and embedded a verified GitHub-hosted recording plus build/health evidence above (or explained why this requirement is not applicable). — N/A, backend-only.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.
    • Reviewed SHA 06f08ec8125 (fresh-eyes subagent). 🟡 duplicated decision-cache predicate between MetricResource and MetricGroupResource — fixed by sharing MetricResource.cachedDecisions.
    • 🔴 answered: stored assets change-description entries can likewise quote hidden data-asset references on PUT /metrics (MetricUpdater.linkRequestedAssets). Not filtered here by design: it is the separately tracked related finding of the same report, and its fix is write-side (linkRequestedAssets + MetricIndex stop recording assets in change descriptions and search documents), which a read-side filter in this PR would conflict with.
  • Decision check: if this PR decides something the next contributor could undo — a schema field, REST path or format another component or repo must agree with, a new default or limit, an ordering that must hold, or a rule stated only in this description — it adds a record under docs/decisions/ (see its README.md). This description is gone from git log after the squash-merge. — recorded as ADR:2026-10-31-metric-and-metric-group-responses-hide-relations-the-viewer-cannot-see (docs/decisions/2026-10-31-metric-and-metric-group-responses-hide-relations-the-viewer-cannot-see.md), including the change-event consequence and the relatedMetrics write-time gap as follow-ups.

Bug fix

  • I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.

Summary by Gitar

  • MCP entity reads:
    • get_entity_details now filters metric relations and group member counts through MetricRelationVisibility
    • Added McpMetricRelationVisibilityIT to verify restricted callers get no hidden relations via MCP

This will update automatically on new commits.

@harshach
harshach requested a review from a team as a code owner October 31, 2026 21:33
@harshach
harshach requested a review from TeddyCr October 31, 2026 21:33
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Oct 31, 2026
@harshach

Copy link
Copy Markdown
Collaborator Author

Local Java test results (HEAD 06f08ec8125)

Selected by .github/java-tests/impact-map.json (make java_affected). All runs local; PR CI does not run the integration tests.

Unit — openmetadata-service — mvn -B package -pl openmetadata-service -Dspring-boot.repackage.skip=true -Dtest=MetricGroupRepositoryTest,MetricGroupResourceTest,MetricObservabilityBuilderTest,MetricRepositoryTest,MetricResourceTest,PersonaContextBuilderTest -Dsurefire.failIfNoSpecifiedTests=false

  • MetricGroupRepositoryTest 17, MetricGroupResourceTest 16, MetricObservabilityBuilderTest 22, MetricRepositoryTest 27, MetricResourceTest 19, PersonaContextBuilderTest 25 — 126 tests, 0 failures.
  • After the self-review amendment, the four metric classes re-run: 79 tests, 0 failures.

Integration — mysql-elasticsearch, parallel lane — mvn -B verify -pl openmetadata-integration-tests -Pmysql-elasticsearch -DintegrationTests.lane=parallel -Dit.test=ConfigResourceIT,DatabaseSmokeIT,GlossaryTermRelationUsageIT,GlossaryTermResourceIT,MetricAssetsIT,MetricGroupResourceIT,MetricResourceIT,QueryCostRecordResourceIT,QueryResourceIT,QueryVisibilityPolicyIT,SeedDataPresenceIT,TableResourceIT,UsageResourceIT,UserResourceIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false

  • 1588 tests, 0 failures, 0 errors (108 skipped), BUILD SUCCESS. Includes the full MetricGroupResourceIT (142) and MetricResourceIT with the extended hierarchyEndpointsFilterAndSanitizeEveryRestrictedMetricReference.
  • Note: the async SearchIndexHandler logged "Failed to update search index for entity metricGroup …" a few times during the run; the handler catches, logs and enqueues a retry, and no test failed. The diff does not touch search indexing.

Integration — targeted, final HEAD — MetricResourceIT#hierarchyEndpointsFilterAndSanitizeEveryRestrictedMetricReference (re-run after the self-review amendment): 1/1 passed.

Integration — mysql-elasticsearch, isolated (global-state) lane — mvn -B verify -pl openmetadata-integration-tests -Pmysql-elasticsearch -DintegrationTests.lane=global-state -Dit.test=MetricMigrationIT,UserMetricsResourceIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false

  • UserMetricsResourceIT 7, MetricMigrationIT 4 — 11 tests, 0 failures, BUILD SUCCESS.

Coverage (jacoco, mvn test -Pstatic-code-analysis + mvn jacoco:report, whole class): MetricRepository 30% lines / 33% branches, MetricGroupRepository 42% / 40%, MetricResource 46% / 58%, MetricGroupResource 68% / 71%. The classes are large and mostly pre-existing; the new sanitizer methods and conditional resource paths are covered by the new unit tests, the end-to-end routes by the integration test above.

Self-review: fresh-eyes review of 06f08ec8125 against REVIEW.md. 🟡 duplicated decision-cache predicate — fixed (MetricResource.cachedDecisions shared by both resources). 🔴 answered: stored assets change-description entries can quote hidden data-asset references on PUT /metrics; out of scope here by design of the source finding — it is the separately tracked related finding, fixed write-side in MetricUpdater.linkRequestedAssets/MetricIndex.

@harshach
harshach force-pushed the agent/ant-2026-2mc20zfu-medium-cwe branch from 06f08ec to 7f5947d Compare October 31, 2026 22:08
@harshach
harshach force-pushed the agent/ant-2026-2mc20zfu-medium-cwe branch from 7f5947d to a34c28c Compare October 31, 2026 22:20
A metric's relation fields (parent, children, childrenCount, relatedMetrics,
metricGroup), a metric group's member list and metricCount, and the stored
change descriptions that quote those references reached any caller who could
view the carrying entity, without a ViewBasic check on the referenced
entities. Three routes leaked the id, name, displayName and description of
metrics and groups the caller was denied: the generic metric GET/list and
write responses, the metric and metric group version histories, and the
changeDescription / incrementalChangeDescription recorded on reparenting,
regrouping and membership edits - the last one also inside the otherwise
filtered hierarchy payloads.

Apply the per-reference check the hierarchy endpoints already use to every
Metric and MetricGroup response. MetricRepository.sanitizeMetricRelations
filters the reference fields, recounts childrenCount with the visible
children, and drops stored change entries for parent, relatedMetrics and
metricGroup that name an entity the caller may not view; the group payloads
go through MetricGroupRepository.sanitizeMembership, which filters members,
recounts metricCount like the hierarchy endpoints, and drops membership
change entries. Both resources resolve the caller permissions once per
request, short-circuit on unconditional view, and cache per-entity
decisions. Version histories are redacted through the existing
snapshotRedaction hook, so unrestricted responses are unchanged. List pages
recount the visible counts with one batched relationship query per page
instead of a scan per row.

The viewer-scoped rule and its consequences (restricted writers' change
events carry only what the writer could see; relatedMetrics stays
unvalidated at write time; /history endpoints stay unfiltered) are recorded
in docs/decisions/2026-10-31-metric-and-metric-group-responses-hide-
relations-the-viewer-cannot-see.md.

Not changed: relatedMetrics is still accepted at write time without a check
on the named metric, and the inherited /metrics/history and
/metricGroups/history endpoints still lack a per-entity or domain filter.
@harshach
harshach force-pushed the agent/ant-2026-2mc20zfu-medium-cwe branch from 098e3ea to 2060ed3 Compare November 1, 2026 00:01
get_entity_details returns a metric's parent, children, related metrics
and group, and a metric group's member count. Run them through the
sanitizers the metric REST reads use, with the same ViewBasic check and
unconditional-view short-circuit.

Adds McpMetricRelationVisibilityIT.
Copilot AI balanced review requested due to automatic review settings November 3, 2026 13:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Hidden-group references still leak through metric member listings and MCP write responses, and authorization failures can allow reference-bearing change entries without a successful permission check.

3 open issues
What changed in this PR

This PR addresses #36762 by applying per-reference ViewBasic checks to metric relations and metric-group memberships, extending the filtering already used by hierarchy endpoints.

Changes:

  • Filters relation fields, counts, and stored change descriptions across REST responses and version histories.
  • Adds metric relation filtering to MCP entity reads and batches count recalculation for list pages.
  • Adds unit and integration coverage and records the visibility contract in a decision record.
File Description
openmetadata-service/​src/​test/​java/​org/​openmetadata/​service/​resources/​metrics/​MetricResourceTest.java Tests conditional read, PATCH, and snapshot sanitization.
openmetadata-service/​src/​test/​java/​org/​openmetadata/​service/​resources/​metrics/​MetricGroupResourceTest.java Tests membership sanitization in resource responses.
openmetadata-service/​src/​test/​java/​org/​openmetadata/​service/​jdbi3/​MetricRepositoryTest.java Tests relation filtering, stored changes, and visible child counts.
openmetadata-service/​src/​test/​java/​org/​openmetadata/​service/​jdbi3/​MetricGroupRepositoryTest.java Tests member filtering, batched counts, and scan limits.
openmetadata-service/​src/​main/​java/​org/​openmetadata/​service/​resources/​metrics/​MetricResource.java Applies relation sanitizers to reads, writes, and snapshots.
openmetadata-service/​src/​main/​java/​org/​openmetadata/​service/​resources/​metrics/​MetricGroupResource.java Applies membership sanitizers to reads, writes, and snapshots.
openmetadata-service/​src/​main/​java/​org/​openmetadata/​service/​jdbi3/​MetricRepository.java Filters metric references and changes; recalculates visible counts.
openmetadata-service/​src/​main/​java/​org/​openmetadata/​service/​jdbi3/​MetricGroupRepository.java Filters memberships and changes; batches visible member counts.
openmetadata-mcp/​src/​main/​java/​org/​openmetadata/​mcp/​tools/​MetricRelationVisibility.java Adds permission-aware metric sanitization for MCP.
openmetadata-mcp/​src/​main/​java/​org/​openmetadata/​mcp/​tools/​GetEntityTool.java Sanitizes metric relations before returning entity details.
openmetadata-integration-tests/​src/​test/​java/​org/​openmetadata/​it/​tests/​MetricResourceIT.java Extends restricted-reader coverage to reads, versions, and changes.
openmetadata-integration-tests/​src/​test/​java/​org/​openmetadata/​it/​tests/​mcp/​McpMetricRelationVisibilityIT.java Tests hidden relations and visible counts through MCP reads.
docs/​decisions/​2026-10-31-metric-and-metric-group-responses-hide-relations-the-viewer-cannot-see.md Records the visibility contract and deferred concerns.

Review effort: Balanced

Comment on lines +270 to +274
MetricRelationVisibility.visibleTo(
CommonUtils.withVisibleEvidence(
CommonUtils.readEntityForCaller(entityType, fqn, "*", null, securityContext),
authorizer,
securityContext),
Comment on lines +1446 to +1448
sanitizeRelationChanges(sanitized.getChangeDescription(), canViewMetric, canViewGroup);
sanitizeRelationChanges(
sanitized.getIncrementalChangeDescription(), canViewMetric, canViewGroup);
Metric and metric group relations are filtered where every MCP tool
builds the entity it answers with, so get, patch and create apply the
same per-reference ViewBasic check. The group members list checks the
groups its members' stored change entries name. Change-value parsing
tolerates malformed payloads only; a failed visibility check propagates.

Adds MCP patch and create regressions, a members-list regression for
callers with conditional and unconditional metric access, and a unit
test for a failing visibility check.
Copilot AI balanced review requested due to automatic review settings November 3, 2026 13:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the metric and metric-group relation visibility changes.

2 open issues
1 resolved since last review

Review effort: Balanced

@yan-3005
yan-3005 added this pull request to the merge queue Nov 3, 2026
…fu-medium-cwe

# Conflicts:
#	openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricResource.java
#	openmetadata-service/src/test/java/org/openmetadata/service/resources/metrics/MetricResourceTest.java
Copilot AI balanced review requested due to automatic review settings November 4, 2026 06:58
@gitar-bot

gitar-bot Bot commented Nov 4, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 4 closed / 4 findings

🔴 High risk · Applying ViewBasic filtering to metric relations, memberships, and histories affects authorization-sensitive disclosure; faulty decisions could expose hidden entity details.

Filters metric relation fields, group member lists, and stored change descriptions by the viewer's ViewBasic permission across metric and metric group reads, writes, version histories, and MCP entity details, so restricted callers no longer see hidden entity ids or names. Resolved the per-row child/member scan on generic list pages by batching the visible count recount per page and removed the per-group scan cap from the batch metricCount recount. No open issues remain; the change events permanently lacking relations from restricted writers is a disclosed accepted consequence tracked in the ADR.

✅ 4 closed
✅ Performance: Generic list now runs a per-row child/member scan for restricted users

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricRepository.java:1465-1467 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricRepository.java:1541-1555 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricGroupRepository.java:472-474 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricResource.java:241-254 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricGroupResource.java:137-147
For any caller without unconditional view, GET /v1/metrics?fields=childrenCount calls sanitizeMetricRelations on every row. For each row, visibleChildCount pages through listChildIds in batches of 200, loads the child references and checks permission on each one (MetricRepository.java:1541-1558). GET /v1/metricGroups?fields=metricCount does the same through visibleMetricCount, which scans up to 10,000 member JSONs per group. Before this change these lists used the bulk count hydration. Now a page of up to 1,000 rows costs at least one query per row, plus the child loads and policy checks, which is an N+1 on a common list path (DomainOnlyAccessRole users, i.e. most non-admins). Batch the recount across the page: one grouped child-id or member query for all ids on the page, then the cached predicate. Or skip the recount when the bulk count already equals the visible children that were loaded.

✅ Quality: Viewer-scoped relation and change-event rule is not recorded

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricRepository.java:1454-1468 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricGroupRepository.java:455-469
This PR decides a cross-component contract and no record in docs/decisions/ states it. The PR body says: "restricted callers see only viewable relations and counts; listVersions re-serializes versions through the POJO for those callers; change events caused by a restricted writer lack the relations that writer cannot see." It also says: "relatedMetrics is still accepted at write time without a check on the named metric." The record would say: every Metric and MetricGroup response, including write responses, version snapshots and the change events built from them, drops any parent/children/relatedMetrics/metricGroup/metrics reference and any stored change entry naming an entity the caller lacks ViewBasic on, and recounts childrenCount/metricCount over the visible references. The PR's decision-check box is unchecked with "no durable decision", but the change-event consequence and the write-time gap on relatedMetrics exist only in the description, which the squash-merge drops. Add a record under docs/decisions/ stating this rule.

✅ Performance: Batch metricCount recount drops the per-group scan cap

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricGroupRepository.java:523-537
The single-group visibleMetricCount stops after MAX_PERMISSION_FILTER_SCAN_SIZE (10,000) members. Its comment explains why: without a cap, one oversized group could take down the listing for a permission-filtered user. The new page-level visibleMetricCounts has no cap. It loads every HAS relationship for every group on the page, loads a reference for each member, and runs a permission check on each one. A page of large groups now costs an unbounded number of reference loads and conditional policy evaluations, which is the failure the cap was added to prevent. It also means GET /metricGroups/{id} and the list endpoint can report different metricCount values for the same group once it has more than 10,000 members.

Fix: apply the same cap in the batch path. For example, stop counting a group's members after MAX_PERMISSION_FILTER_SCAN_SIZE of them, ideally before loading references (truncate each group's member id list first).

Closed: Bug: Sanitized write responses permanently strip relations from change events

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricResource.java:571 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricResource.java:595 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricResource.java:960-974 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricResource.java:1057 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricResource.java:1095-1097 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricResource.java:1134-1137 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricResource.java:1177-1179 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricResource.java:1200-1201 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricGroupResource.java:407-408 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricGroupResource.java:437-438 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricGroupResource.java:469-471 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricGroupResource.java:567 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricGroupResource.java:593 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricGroupResource.java:614-616
ChangeEventHandler builds and stores the change event from responseContext.getEntity() (ChangeEventHandler.java:44-101). Because POST/PUT/PATCH/delete/restore/vote responses now go through sanitizeRelations / sanitizeMembership, a write by a restricted user has its parent, relatedMetrics, metricGroup and metrics change entries removed from the persisted ChangeEvent. That event feeds the activity feed, alert subscriptions and webhooks that admins and other unrestricted consumers read, so the audit record of a real reparent or regroup is lost for good, not just hidden from the writer. The description lists this as an accepted behavior change, but it is data loss in the event stream, not just per-viewer redaction. Sanitize only the body the client receives: keep the unsanitized entity on the response context for the event filter, for example by redacting in a response writer or interceptor that runs after ChangeEventHandler. Alternatively, filter relations when events are read back, per subscriber, instead of when they are written.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@yan-3005
yan-3005 enabled auto-merge (squash) November 4, 2026 07:00
@yan-3005
yan-3005 merged commit 56444b6 into main Nov 4, 2026
63 of 65 checks passed
@yan-3005
yan-3005 deleted the agent/ant-2026-2mc20zfu-medium-cwe branch November 4, 2026 07:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical authorization bypass exposes hard-deleted related metrics’ stored names and descriptions through change and version history because missing-target resolution causes tag-based denials to stop matching.

3 open issues

Review effort: Balanced

Comment on lines +281 to +285
authorizer.authorize(
securityContext,
new OperationContext(reference.getType(), MetadataOperation.VIEW_BASIC),
new ResourceContext<>(
reference.getType(), reference.getId(), reference.getFullyQualifiedName()));
@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

manerow pushed a commit that referenced this pull request Nov 5, 2026
#37110)

MetricGroupResource.patch now loads the stored group with repository.get before
authorizing the patch (#36955). The test added in #36764 only stubbed
getWithMembers, so get returned null and applyPatch failed with
"Expected a JSON object or array", failing openmetadata-service unit tests on main.
BMJLearnToHelloWorld added a commit to BMJLearnToHelloWorld/SmartMetadata that referenced this pull request Nov 6, 2026
BMJLearnToHelloWorld added a commit to BMJLearnToHelloWorld/SmartMetadata that referenced this pull request Nov 6, 2026
BMJLearnToHelloWorld added a commit to BMJLearnToHelloWorld/SmartMetadata that referenced this pull request Nov 6, 2026
BMJLearnToHelloWorld added a commit to BMJLearnToHelloWorld/SmartMetadata that referenced this pull request Nov 7, 2026
…am PR open-metadata#36764 follow-up) (#154)

* feat: port MetricRelationVisibility + MCP withVisibleEvidence (upstream PR open-metadata#36764 follow-up)

* docs: add ADR record for Metric/MetricGroup relation visibility (2026-10-31)

The two files ported in this PR cite
ADR:2026-10-31-metric-and-metric-group-responses-hide-relations-the-viewer-cannot-see
in their Javadoc, but the record did not exist in this repo, so the
decision-records check in verify-rebuild failed with 2 problems. Add the
record (the decision behind #153's REST read-path port, implemented here
for the MCP path); the citation now resolves.

* test(ui): use last-match for UsersListView overflow View item
@yan-3005 yan-3005 self-assigned this Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metric relation fields leak metrics and metric groups the user cannot view

3 participants