Search by

qiick / laravel-access

LucaGiardi20

Shared authorization core for qiick Laravel products: Gate::before, effective permissions, actor context, and enforced 2FA.

Package info

github.com/qiick-io/laravel-access

pkg:composer/qiick/laravel-access

Statistics

Installs: 8 993

Dependents: 1

Suggesters: 3

Stars: 0

Open Issues: 10

v0.1.0-beta.3 2026-11-27 13:57 UTC

This package is auto-updated.

Last update: 2026-12-04 20:40:20 UTC


README

laravel-access: Authorization core for Laravel products

qiick/laravel-access

OpenSSF Scorecard

PHPStan at max and the existing CI checks cover PHP. CodeQL covers GitHub Actions and JavaScript/TypeScript.

Pre-1.0 (0.x): public APIs may change in any minor. Not on Packagist yet.

Shared authorization core for qiick Laravel products: one Gate::before, the effective-permission resolver (direct ∪ group roles, soft-deleted groups excluded), a typed actor context so API actors never get the super-admin pass, enforced 2FA middleware, the EnsureUserHasPermissionMiddleware route middleware and the AuthorizesWithPermissionTrait FormRequest trait.

Part of the qiick fleet. Binding design: projects/qiick/packages/laravel-access-design.md in the knowledge base (overlays: decisions/2026-11-22-laravel-access-package.md, decisions/2026-11-22-mcp-oauth-and-access-design-answers.md, decisions/2026-11-20-core-hardening.md).

Status

0.1.0-beta.3 is the current tagged pre-release (the first was 0.1.0-beta.1), for beta adoption in the qiick products. Public APIs may change in any 0.x release; see UPGRADING.md. Packagist publishing waits for the maintainer's go; until then products install it from the tag.

Requirements

  • PHP ^8.4
  • Illuminate auth / contracts / database / http / support ^12.0 \|\| ^13.0 (never laravel/framework)
  • spatie/laravel-permission ^8.0
  • A database: SQLite, PostgreSQL, MySQL 8 or MariaDB 10.11 or later. CI tests SQLite, PostgreSQL 17, MySQL 8.4 and MariaDB 10.11 LTS and 11.4 LTS.

Install (when published)

composer require qiick/laravel-access
php artisan vendor:publish --tag=access-config

Products must bind RoleCatalogContract, TwoFactorPolicyContract, TwoFactorResponderContract and AuthorizationResponderContract, set permission.register_permission_check_method to false, and call AccessContext::enter() after verifying a credential. See docs/adoption.md and docs/reference-contracts.md.

Threat model (short)

Threat Mitigation
Super-admin elevation through a key, grant or public door Gate::before step 2 abstains for API actors; Spatie's permission callback off
Future model-less check on an API path Step 2 unconditional; permission: middleware and trait give API actors only scopes ∩ the owner ceiling (assigned permissions, the vocabulary for a super-admin owner), never the Gate bypass, and deny them when no ApiActorScopeCheckContract is bound; Policies use the resolver, never $actor->can(<permission>)
Forged actor kind Context bound only after verification; resolver never reads request input; either-signal rule
Job escaping the key's limits CarriesActorContext job middleware
Stale permissions after demotion shouldBypassCache use-time checks, event and lifecycle clears, scoped resolver
Soft-deleted group still grants SQL whereNull(deleted_at); C7
Organisation bleed Team id in the cache key; switchTo() clears; C29
A grant changed in the same request or job still counting, or a new one not counting yet The resolver caches per scope. Requests, jobs, Octane events, TeamContextContract::switchTo(), and fresh checks clear the cache. Spatie's role and permission attach and detach events clear it for the affected user. After writing user_group_user or user_group_role, soft-deleting or restoring a group, or changing a role's permissions, call EffectivePermissionResolver::forget($user) for each affected member or flush() for a group- or role-wide change. Use a fresh check when a membership starts or expires during a long-running job. Under Octane the Gate, these clears and switchTo() use the request's own container (#69).
Spatie's team filter seen off by another request The resolver turns PermissionRegistrar::$teams off while it builds one roles() relation and restores it in finally. On the standard Spatie Eloquent path that window runs no query and cannot yield; one process serves one request or job at a time (PHP-FPM, queue workers, Octane on Swoole, RoadRunner or FrankenPHP). Outside the model: a custom user whose roles() is not an Eloquent relation (its role names are then read inside the window), a roles() that queries while it is built, Swoole's preemptive coroutine scheduler, or any runtime that serves two requests at once in one process
Super-admin overriding a Policy Step 3 abstains when a Policy exists
2FA skipped API actors exempt but get no Gate pass; exempt list minimal
Missing binding failing open Boot check
Domain logic leaking into the package Arch test against App\; no domain hook
A deleted user keeping a principal, or erasure leaving a principal behind principals.user_id is ON DELETE RESTRICT, so the database refuses any hard delete of a user with principals; AccessEraser, run by the product's erasure orchestrator, erases and unlinks them before the user row goes; UserDeletionGuard turns an Eloquent hard delete into UserHasPrincipalsException (a soft delete keeps the row and passes)
A principal owned across organisations, or a deactivated owner still counting Owners must be active and in the same organisation; isActive() walks the owner chain uncached and counts a chain longer than eight (a cycle included) as inactive; deactivation cascades to every owned principal in one transaction and PrincipalDeactivatedEvent fires after commit
Two principals for one membership, two instance principals of one type, or an organisation-less member Membership unique index on every engine; with access.principals.organisation_required, the instance singleton index and the organisation CHECK (triggers on SQLite); race-safe forMember() and instance()
Principals config drifting from the schema Testing\AssertsPrincipalsSchema proves the refusals on the product's migrated database
Supply chain Pinned Actions, composer audit, no lockfile, weekly grouped Dependabot updates into develop (Composer and Actions)

Development

composer update
composer test      # Pest
composer lint      # Pint
composer analyse   # PHPStan level max

Every class in src/ runs mutation per class at MSI ≥ 95 via scripts/mutate-per-class.sh in CI (all classes on push and nightly, the changed ones on a pull request). Real-HTTP middleware tests use php -S (no shell wrapper; torn down in tearDown).

License

MIT. See LICENSE.