Skip to content

Deny resources without roles in RoleBased - #33

Merged
ievgeniiskliarenko merged 2 commits into
masterfrom
access/role-based-deny-unconfigured
Oct 2, 2026
Merged

ievgeniiskliarenko merged 2 commits into
masterfrom
access/role-based-deny-unconfigured

Conversation

@ievgeniiskliarenko

Copy link
Copy Markdown
Contributor

RoleBased granted every resource without configured roles, because Identity::hasRole([]) is true. It now denies them; configured resources behave as before.

Behaviour change, to be released as virtue-access 0.7.0. Payments, croupier and customer each work around this with their own RoleBased

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 review overview

🟢 Approval recommended

The implementation matches the stated behavior and is adequately tested.

Review effort: Balanced
Findings: None

What changed in this PR

Updates role-based access control to deny resources with no configured roles.

Changes:

  • Requires a non-empty role list before granting access.
  • Adds coverage for users and root identities.
File Description
src/​Access/​GrantsAccess/​RoleBased.php Enforces denial for missing or empty role mappings.
tests/​Access/​GrantsAccess/​RoleBasedTest.php Tests denial behavior and configured root access.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ievgeniiskliarenko
ievgeniiskliarenko marked this pull request as ready for review October 2, 2026 11:05
Comment on lines +25 to +27
$roles = $this->roles[$resource] ?? [];

return $roles !== [] && $this->identity->hasRole($roles);

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.

I would suggest additionally to define a "catch all" resource like *, this way the consumer could pick the default behavior. with "deny all" the absolute default case

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Please check https://github.com/vicephp/Virtue/pull/33/changes#diff-7b8998cf9407aa93e6e2be4ef74b93c0975fa919ac1a04db8a503d7ebfb1c59bR38

We can't really restore the old behaviour (it was quite dangerous), but we can have ANY fallback.

@ievgeniiskliarenko
ievgeniiskliarenko merged commit cd0233f into master Oct 2, 2026
3 checks passed
@ievgeniiskliarenko
ievgeniiskliarenko deleted the access/role-based-deny-unconfigured branch October 2, 2026 12:44
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.

4 participants