Skip to content

Fixes #39142: Stop OperationContext reuse from bypassing conditional denies - #39179

Open
detail-app[bot] wants to merge 1 commit into
mainfrom
detail/bug-fix/fixes-39142-stop-operationcontext-reuse-from-bypas-e91ca0
Open

detail-app[bot] wants to merge 1 commit into
mainfrom
detail/bug-fix/fixes-39142-stop-operationcontext-reuse-from-bypas-e91ca0

Conversation

@detail-app

@detail-app detail-app Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Detail bug report: View on Detail

Describe your changes:

Fixes #39142

I worked on closing an authorization bypass on GET /v1/permissions/policies?ids= because PolicyEvaluator.hasPermission destructively drains the requested operations from the OperationContext as it grants them, and an empty list makes it skip the DENY pass and pass its final check vacuously. The endpoint reused one OperationContext across every policy id in the request, so once the first id was allowed, every later id was "authorized" without evaluating any deny rule — including the seeded !hasDomain() / !isOwner() conditional denies. Any authenticated user could read permission data derived from policies they should not be permitted to view by sending ?ids=<allowedId>,<deniedId1>,<deniedId2>,....

Type of change:

  • Bug fix

High-level design:

Two layers, since the root cause is the in-place drain:

  • OperationContext now keeps an immutable snapshot of the originally requested operations (requestedOperations) at construction (and at lazy patch resolution) and exposes a package-private resetOperations() that restores the working list. The live operations list still drains during a single decision, so the existing grant-tracking semantics are unchanged.
  • PolicyEvaluator.hasPermission calls operationContext.resetOperations() before every evaluation, so a reused context always evaluates against the full set. This closes the footgun for every current and future caller, not just the endpoint in the report.
  • PermissionsResource.getPermissionForPolicies builds a fresh OperationContext per policy id inside the loop, matching the "each decision needs its own" convention already documented in ViewPermissionFilter.

Tests:

Use cases covered

  • A non-admin user who is allowed to view one policy id but denied (by a conditional deny such as !isOwner()) on a second id is rejected with 403 when both ids are requested together via GET /v1/permissions/policies?ids=<allowedId>,<deniedId>.
  • A reused OperationContext no longer skips the DENY pass after the first successful allow — conditional denies are evaluated on every authorization decision.
  • Single-decision authorization with a fresh OperationContext behaves exactly as before (allow drains the list, deny throws, ungranted operations throw).

Unit tests

  • I added unit tests for the new/changed logic.
  • Files added/updated: openmetadata-service/src/test/java/org/openmetadata/service/security/policyevaluator/ContextReuseDenyBypassTest.java — regression guard proving a reused OperationContext enforces the conditional deny on every id and that resetOperations() restores the drained list. Verified the regression test fails without the resetOperations() call (with "Expected AuthorizationException to be thrown, but nothing was thrown") and passes with it.
  • Coverage on changed classes (mvn jacoco:report): OperationContext.resetOperations() 100% line coverage; PolicyEvaluator.hasPermission 76.9% (the reset, deny pass, allow pass and success path covered; the ungranted-throw path is covered by the existing CompiledRuleTest/ContextReuseDenyBypassTest deny cases). Class-level totals are lower because the Java IT/server suite — which the local bootstrap NPE blocked — supplies the rest of the coverage in normal CI.

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/ for new/changed API endpoints.
  • Not applicable (no backend API changes).

The endpoint already exists; its multi-id admin happy path is covered by PermissionsResourceIT.testGetPermissionsForMultiplePolicies. A non-admin multi-id IT proving the 403 on the denied id is the natural extension but could not be exercised locally (see Manual testing).

Impacted plan:

make java_affected ARGS="--scope focused"

→ planned unit tests ContextReuseDenyBypassTest, PolicyEvaluatorTest; both run green:

mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=ContextReuseDenyBypassTest,PolicyEvaluatorTest -Dsurefire.failIfNoSpecifiedTests=false

→ 11/11 pass, BUILD SUCCESS. PermissionsResource.java is listed under "Changed classes no unit test reference" and is now covered by ContextReuseDenyBypassTest.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  • Ran the impacted unit suite (340+ tests across the security/policyevaluator packages) plus the new regression test — all pass.
  • Ran mvn spotless:check -pl openmetadata-service (the CI "Java checkstyle" gate) exit 0, and mvn test-compile -pl openmetadata-service exit 0.
  • Attempted PermissionsResourceIT via the Testcontainers MySQL+ES stack (mvn -B verify -pl :openmetadata-integration-tests -am -Pmysql-elasticsearch -Dit.test=PermissionsResourceIT -Dtest=NoUnitTestsInThisRun). The MySQL 8.4.13 and Elasticsearch 9.3.0 containers started successfully, but the OpenMetadata application bootstrap failed in TestSuiteBootstrap.startApplication with java.lang.NullPointerException: ... Entity.getEntityRelationshipRepository() is null during migration seeding, before HTTP was served. I verified this NPE is pre-existing and unrelated to the change by stashing the fix and reproducing the identical failure on a clean tree; no fix-touched file appears in the stack trace. The end-to-end exploit reproduction (single-id 200 vs. multi-id 403, order-independence) consequently could not be exercised locally and is pending the bootstrap fix in this environment; the unit-level engine behavior is covered by ContextReuseDenyBypassTest.

UI screen recording:

Not applicable — backend-only authorization fix.

Checklist:

  • I have read CONTRIBUTING.md (the pre-review gate) and the contributor docs.
  • 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.
  • 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).
  • 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.
  • 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).
  • 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.

Automatic Fixes PRs can be configured here.

@detail-app
detail-app Bot requested a review from a team as a code owner November 28, 2026 03:18
@detail-app
detail-app Bot requested review from IceS2 and sureshms November 28, 2026 03:18

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Detail Bug] AuthZ: Multi-policy permissions API bypasses conditional denies when multiple ids are requested

2 participants