cakephp/authorization
CakePHP Authorization is a policy-based authorization plugin for CakePHP, offering middleware integration, request-level permission checks, and reusable policy classes. It helps centralize access rules and keep controllers clean, making role- and resource-based authorization easier to implement cons...
Architecture fit. Despite the "PSR7 Middleware" description, this is the CakePHP authorization plugin, not a framework-neutral authorization library. It ships PSR-15 middleware (AuthorizationMiddleware) and PSR-7 request policies, but its internals lean on CakePHP primitives: Cake\Core\InstanceConfigTrait, Cake\Http\ServerRequest, Cake's event manager, and the authentication request attribute convention used by cakephp/authentication. The core model is sound and easy to reason about — an AuthorizationService resolving PolicyInterface::can($identity, $resource, $action) and RequestPolicyInterface::canAccess($identity, $request), with middleware translating denials into 401/403. But "PSR-15 surface, CakePHP core" is the accurate framing. For a Laravel codebase this is a foreign object: Laravel already has Gate/Policies, an Illuminate\Http\Request-based middleware pipeline, and no PSR-15 kernel. Fit is therefore poor by default, workable only as an isolated authorization engine.
Integration feasibility. Three viable paths, in ascending cost:
Cake\Http\ServerRequest, attaches identity plus the authorization attribute, calls AuthorizationService, and maps ForbiddenException/MissingIdentityException to 403/401 JSON. Realistic effort: 1 sprint for a spike, 2–4 engineer-weeks for a hardened adapter with parity tests.Technical risk. Authorization is a security-critical path, and this package carries elevated risk for us: 74 stars indicates a small user base outside CakePHP, meaning edge cases are exercised mostly by one framework community; the maintainer pool is the CakePHP core team (competent, but no vendor SLA); and version coupling to CakePHP majors is a recurring upgrade obligation we would not otherwise carry. The sharpest functional risks are (a) default-allow misconfiguration — the deny semantics hinge on correct exception handling and authorization attribute wiring, and a missing policy must fail closed; (b) identity bridging — no Cake identity means either a 401 storm or, worse, an identity object that isn't what policies expect; and (c) request fidelity — route params, query strings, and headers must survive the Illuminate→Cake conversion, or a RequestPolicy will authorize against the wrong shape of request.
Key questions. Is any part of our stack CakePHP or PSR-15 (Slim, Mezzio)? Is cross-framework policy reuse an explicit roadmap requirement, or is "opportunity: 0.85" a proxy metric rather than a stated need? Do we have a compliance/audit requirement that Gate can't meet (this package gives no audit trail — we'd build it)? Who owns the adapter and the CVE patch SLA? What is the exit criterion if adoption proves non-idiomatic?
Stack fit. Laravel 10–12 on PHP 8.1+, package requiring cakephp/core ^5 and cakephp/http ^5 plus PSR-7/PSR-15 interfaces. Dependency conflict risk is low (Laravel ships no Cake packages), but we would run two HTTP abstractions and, likely, a second PSR-7 implementation (laminas-diactoros or nyholm/psr7) alongside Symfony's. Verify the transitive requirement on cakephp/authentication does not drag in additional identity plumbing we don't want.
Migration path. Do not migrate existing Gate policies. Introduce additively in exactly one bounded context — ideally a partner-facing or externally consumed API module where PSR-15 portability has actual future value. Wrap it behind:
CakeAuthorizationBridge middleware: build ServerRequest, seed identity + authorization attribute, delegate, map exceptions.Compatibility. Pin exact versions in composer.json, run the dependency solver against the full app before committing, and confirm PSR-7 implementation alignment with any existing HTTP client usage. Treat CakePHP major upgrades as scheduled work, not incidental.
Sequencing. (1) One-week spike proving identity bridging and correct 403 semantics on two routes. (2) Build-vs-buy-vs-Gate decision go/no-go. (3) Adapter plus a contract-test harness: table-driven policy tests and decision-parity tests against Gate. (4) Shadow rollout, two weeks of log review. (5) Enforce in the single module. (6) Publish a runbook and explicitly documented exit criteria (e.g., if >2 divergences per month, revert to Gate and retire the adapter).
Maintenance. We become the maintainers of the integration, not the package. The package itself needs version bumps roughly in step with CakePHP majors — infrequent but breaking. Budget ~2–4 engineer-days per upgrade cycle, plus ongoing ownership of the adapter, which is where our bugs will actually live.
Support. Community channels only (GitHub issues, CakePHP Slack); no vendor SLA. Security advisories arrive through CakePHP's disclosure process, so we must subscribe to that feed and apply a defined patch SLA — I'd propose 7 days for anything touching the authorization path, with a documented compensating control if a patch isn't available.
Scaling. Authorization itself is stateless and CPU-cheap; it scales horizontally with no shared state and no cache-coherency problem. The real scaling hazard is inside policies: lazy-loading relationships to evaluate can() produces N+1 queries on list endpoints. Enforce a policy rule — policies receive already-loaded resources, never query — and instrument decision latency. Do not cache policy decisions; invalidation risk outweighs the gain.
Failure modes. Misconfigured default-allow (silent privilege escalation); identity attribute absent, yielding 401s that look like auth outages; uncaught policy exceptions surfacing as 500s instead of 403s; request-conversion bugs granting access against the wrong route parameters; and decision divergence between Gate and Cake policies, which is the slow-burn risk — two systems that disagree until someone finds the gap in production. Each of these needs a named detection: parity tests in CI, deny-by-default assertions, and structured audit logging at the service boundary (which we build, since the package does not).
Ramp-up. Two authorization mental models in one codebase is the hidden tax. A senior Laravel engineer needs roughly 1–2 weeks to be productive with Cake policies and the authorization attribute convention; reviewers need to know which system governs which route. Mitigate with a policy template, a short ADR explaining why both exist, and onboarding docs that state the boundary explicitly. If we cannot justify that tax with a concrete multi-framework requirement in the next two quarters, the correct TPM recommendation is to extend Laravel Gate with a thin, portable policy layer and revisit this package only when a genuine PSR-15 service enters the estate.
How can I help you explore Laravel packages today?