Skip to content

fix(server-core): policy-check denial + typed descendant-tree loading - #3245

Merged
tada5hi merged 2 commits into
masterfrom
fix/policy-evaluation
Jul 13, 2026
Merged

tada5hi merged 2 commits into
masterfrom
fix/policy-evaluation

Conversation

@tada5hi

@tada5hi tada5hi commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Two independent fixes to the policy-evaluation path, found while working on the authorize flow. Both are pre-existing on master and unrelated to any feature.

1. PolicyCheckerService.check reported success on a denial

check() ran engine.evaluate(...) and discarded the result, so a policy that evaluated to { success: false } still resolved as success — POST /policies/:id/check reported a failing policy as passing, contradicting the method's @throws contract. Switched to engine.evaluateOrFail(...), which throws a PolicyError carrying the evaluation issues. Added a denial regression test to the checker spec (the existing suite only covered the pass and not-found cases).

2. findDescendantsTreeById built type-less policy trees

The method rooted the descendants tree on an id-only stub (this.create(); entity.id = id). EATreeRepository.findDescendantsTree() attaches children + extra-attributes but never populates base columns, so the returned root carried no type — every PolicyEngine consumer then failed closed with policy_evaluator_not_found. Now loads the row first (findOneBy({ id }), null on miss) and builds the tree on it.

Behavioral change worth calling out: this path is also used for Layer-2 junction-policy loading (bindings.ts). A grant restricted via role_permission.policy_id (etc.) previously always evaluated fail-closed deny because its tree was type-less — such policies now genuinely evaluate. No existing test pinned the broken behavior (full suite stays green), but any deployment relying on a junction policy_id restriction will see it start taking effect.

Verification

  • Full dependency-ordered build green (22 projects).
  • Full apps/server-core suite green.
  • New checker-denial regression test added.

tada5hi added 2 commits July 13, 2026 23:22
PolicyCheckerService.check ran engine.evaluate and discarded the result,
so a policy denial resolved as success and POST /policies/:id/check
reported success: true for a failing policy. Use evaluateOrFail, which
throws a PolicyError carrying the evaluation issues, matching the
documented check/safeCheck contract.
findDescendantsTreeById built the tree root from an id-only stub;
findDescendantsTree() attaches children + extra-attributes but never
populates base columns, so every returned tree was type-less and every
engine consumer failed closed (policy_evaluator_not_found). Load the row
first and return null for an unknown id.

Behavioral note: this also affects the Layer-2 junction policy loading
(bindings.ts) — a grant restricted via role_permission.policy_id etc.
previously always evaluated fail-closed deny; such policies now
genuinely evaluate.
Copilot AI review requested due to automatic review settings July 13, 2026 21:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@tada5hi, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 57 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 750fd07c-f64c-4e2c-bd62-8356f7e9a887

📥 Commits

Reviewing files that changed from the base of the PR and between 3756869 and 78dd697.

📒 Files selected for processing (3)
  • apps/server-core/src/adapters/database/domains/policy/repository.ts
  • apps/server-core/src/core/identity/policy/checker/service.ts
  • apps/server-core/test/unit/core/identity/policy/checker.spec.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/policy-evaluation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

authup

npm i https://pkg.pr.new/authup@3245

@authup/client-web

npm i https://pkg.pr.new/@authup/client-web@3245

@authup/server-core

npm i https://pkg.pr.new/@authup/server-core@3245

@authup/access

npm i https://pkg.pr.new/@authup/access@3245

@authup/client-web-kit

npm i https://pkg.pr.new/@authup/client-web-kit@3245

@authup/client-web-kit-theme

npm i https://pkg.pr.new/@authup/client-web-kit-theme@3245

@authup/client-web-nuxt

npm i https://pkg.pr.new/@authup/client-web-nuxt@3245

@authup/client-web-theme

npm i https://pkg.pr.new/@authup/client-web-theme@3245

@authup/core-http-kit

npm i https://pkg.pr.new/@authup/core-http-kit@3245

@authup/core-kit

npm i https://pkg.pr.new/@authup/core-kit@3245

@authup/core-realtime-kit

npm i https://pkg.pr.new/@authup/core-realtime-kit@3245

@authup/errors

npm i https://pkg.pr.new/@authup/errors@3245

@authup/i18n

npm i https://pkg.pr.new/@authup/i18n@3245

@authup/kit

npm i https://pkg.pr.new/@authup/kit@3245

@authup/server-adapter-kit

npm i https://pkg.pr.new/@authup/server-adapter-kit@3245

@authup/server-adapter-node

npm i https://pkg.pr.new/@authup/server-adapter-node@3245

@authup/server-adapter-socket-io

npm i https://pkg.pr.new/@authup/server-adapter-socket-io@3245

@authup/server-adapter-web

npm i https://pkg.pr.new/@authup/server-adapter-web@3245

@authup/server-kit

npm i https://pkg.pr.new/@authup/server-kit@3245

@authup/server-test-kit

npm i https://pkg.pr.new/@authup/server-test-kit@3245

@authup/specs

npm i https://pkg.pr.new/@authup/specs@3245

commit: 78dd697

@tada5hi
tada5hi merged commit e4c944a into master Jul 13, 2026
12 checks passed
@tada5hi
tada5hi deleted the fix/policy-evaluation branch July 13, 2026 22:01
@github-actions github-actions Bot mentioned this pull request Jul 13, 2026
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.

2 participants