Repository navigation
Fix code audit findings: stale Gate memo in workers, model-backed writes, config validation - #1
Merged
Merged
Conversation
…g validation - Resolve the scoped Grant inside Gate callbacks and model listeners so queue workers and Octane never read a stale boot-time memo. - Return the required permission's denial response from #[Requires]. - Revoke and sync through the assignment model; sync keeps unchanged rows. - Validate grant.super_admin like the other config keys. - Flush the previous holder when an assignment changes user. - Show global and scoped roles separately in grant:show. - Drop the always-true Gate::has filter in grant:list. - Correct README and plan.md claims, and remove the missing Unit suite. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Li5c15yQmNGe1f2jZpMv5W
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Li5c15yQmNGe1f2jZpMv5W
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Li5c15yQmNGe1f2jZpMv5W
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR fixes 10 findings from a code-smell and architecture audit of the package. Each behaviour fix has a test that fails on
mainand passes here.P0: Stale permissions in queue workers and Octane
The service provider resolved the
scopedGrantonce at boot and kept it inside every Gate ability, the super-admin hook and thesaved/deletedlisteners. Workers callforgetScopedInstances()between jobs and requests, soHasRolesgot a fresh instance while the Gate kept reading the boot instance's memo for the life of the worker. After the first job, a revoked role still passedcan()until the worker restarted. The closures now resolveGrantat call time.P1: README invited unsupported usage
The README said
HasRolescould go on any Eloquent model. Assignments are keyed only byuser_id, so a second model would share roles with the user that has the same id. Both sentences now nameauth.providers.users.model.P2: Inconsistencies
#[Requires]denials now return the required permission'sdeniedMessage()instead of Laravel's generic message.revoke()andsyncRoles()now write through the assignment model, so a customgrant.modelsees the samedeletedevents it already sees ongrant().syncRoles()no longer deletes and re-inserts rows that didn't change, so their ids stay stable.grant.super_adminis validated like the other config keys. A value that isn't a case of the role enum now throws instead of silently turning the bypass off.grant:show --on=prints global roles and scoped roles as separate rows. Before, a user with only global roles showed "Roles: None" next to a non-empty permission list.P3 and tooling
Gate::hasfilter fromgrant:list.plan.md(column storage mode,make:*commands, "no cache") and a README sentence that contradicted the Caching section.Unittest suite fromphpunit.xml.dist. It points at atests/Unitdirectory that was never committed, which makescomposer test:unitandvendor/bin/peststop with "Test directory not found" onmaintoo.The bundled Boost skill now notes that
#[Requires]denials carry the permission's message.Type of change
Checklist
src/)composer lintpasses (Pint and Rector are clean undercomposer test:lint)composer testpasses: lint, PHPStan at max level, 100% type coverage, 26 tests / 101 assertions🤖 Generated with Claude Code
https://claude.ai/code/session_01Li5c15yQmNGe1f2jZpMv5W