Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multilevel permissions in can() method #1229

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

bgeneto
Copy link
Contributor

@bgeneto bgeneto commented Nov 13, 2024

Refactor authorization checks to support nested permissions in can() method.
Fixes #1224

Description

Changes

  • Enhanced permission wildcard matching to properly handle nested levels
  • Ensure wildcard behavior to prevent unintended parent/sibling permission access

Example

Given permission admin.settings.theme.*:

  • ✅ WILL match: admin.settings.theme, admin.settings.theme.color, admin.settings.theme.layout.dark
  • ❌ WON'T match: admin.settings, admin.*

Benefits

  • More granular permission control
  • Prevents privilege escalation through parent levels
  • Maintains backward compatibility with existing permission structure
  • Better alignment with hierarchical permission management

Testing

Added comprehensive test cases covering:

  • Nested permission levels
  • Parent/child permission relationships
  • Cross-branch permission validation
  • Edge cases and boundary scenarios

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

bgeneto and others added 2 commits November 13, 2024 14:05
refactor authorization checks to support nested permissions in can()
added !empty() so it returns bool and passes phpstan
Copy link
Contributor Author

@bgeneto bgeneto left a comment

Choose a reason for hiding this comment

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

Correction: The array_intersect() returns an array, not a boolean, which causes the type warning.

bgeneto and others added 2 commits November 13, 2024 18:55
added space after !
refactor authorization checks to support nested permissions in can()
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.

Bug: authorization using asterisk (*) only works one level
1 participant