medz/cors
CORS middleware for Laravel that adds configurable Cross-Origin Resource Sharing headers, handles preflight OPTIONS requests, and supports allowed origins, methods, headers, credentials, and max-age settings. Easy to register and customize for APIs and web apps.
medz/cors is a thin cross-framework CORS middleware abstraction that normalizes request/response handling across Laravel, Lumen, Slim, PSR-15, Swoft, and ThinkPHP. Architecturally it sits at the HTTP kernel boundary, intercepting preflight OPTIONS requests and injecting Access-Control-* headers before the router or controller executes. That placement is correct and low-coupling, which is why the package was viable in 2018–2020. However, from a TPM standpoint the package is a commodity capability wrapped in an unmaintained distribution: the underlying problem (CORS header negotiation) is well-understood, spec-defined by the W3C/Fetch standard, and now solved natively in every framework it targets. The repository is archived, the final release dates to May 2020, and the star count (272) reflects historical adoption rather than present-day confidence.
Integration feasibility is high on paper — Composer install, register a service provider or push middleware into the stack, publish a config file — but the practical feasibility is poor because you are adding a dependency whose upstream will never patch a security or spec-compliance defect. CORS misconfiguration is a genuine security surface (wildcard origins combined with credentials, reflected Origin headers, overly permissive Access-Control-Allow-Headers), and an archived package offers no remediation channel. Technical risk is therefore asymmetric: the code is small enough to audit in an afternoon, but the organizational cost of owning a fork is real and permanent. The dominant risk is not that it breaks today; it is that it silently diverges from framework middleware conventions over the next 12–24 months and becomes a blocker during a Laravel major-version upgrade or a PHP runtime bump. Secondary risks include PSR-15 signature drift across psr/http-server-middleware versions and the absence of a published security policy.
Key questions to resolve before any decision: (1) Is this package already in the dependency tree, or is this a greenfield evaluation? If greenfield, the answer is almost certainly no. (2) Which framework and version is the actual target — if Laravel ≥ 9, fruitcake/php-cors or the built-in HandleCors middleware fully supersedes it. (3) Are there non-standard requirements (per-route origin allowlists, dynamic origin resolution, credential-bearing requests) that the native middleware cannot express? (4) Who owns the fork if we adopt, and what is the patch SLA? (5) Does the security review accept an archived dependency in the HTTP boundary layer, which is typically classified as high-blast-radius?
Stack fit is the package's strongest argument and its weakest: it fits many stacks shallowly rather than one stack deeply. The multi-framework support is a historical artifact of the 2017–2019 PHP middleware boom (Swoft, ThinkPHP, Slim), and several of those targets are themselves dormant or have reorganized their middleware contracts. For a contemporary Laravel or Symfony/PSR-15 estate, native middleware is a strictly better fit — it is versioned in lockstep with the framework, covered by the framework's own test matrix, and documented in the same place as the rest of the HTTP layer.
Migration path depends on the entry state. If the package is not yet installed, the recommendation is to not install it and instead configure the native equivalent: in Laravel 11+, config/cors.php plus the framework's HandleCors; in Laravel 9–10, fruitcake/laravel-cors (the package Laravel absorbed); in PSR-15 stacks, a maintained middleware such as neomerx/cors-psr7 or a hand-rolled 60-line middleware, which is genuinely the right size for this problem. If the package is installed, migrate by (a) capturing current behavior as a set of HTTP-level assertions — preflight response codes, allowed origins, exposed headers, Max-Age, credential handling — (b) swapping in the native middleware behind a feature flag, (c) running the assertions in CI against both implementations until parity is proven, then (d) removing the dependency. Budget one engineer-week including test harness work; the code change itself is hours.
Compatibility is the gating constraint. The last release predates PHP 8.1 enums, PHP 8.2 readonly classes, and the PSR-15 1.1 line; it almost certainly runs on PHP 8.x but has never been tested against it. Any adoption should be gated on a CI matrix proving the package against the exact PHP and framework versions in production, not on the README's version constraints. Sequencing should be: audit current CORS behavior and inventory every origin/header actually in use → confirm native middleware can express it → write parity tests → migrate in a low-traffic window → decommission. Do not sequence this alongside a framework upgrade; CORS regressions present as opaque browser-side failures that are expensive to debug when confounded with a major-version bump.
Maintenance is the decisive factor. The package is archived, meaning no issue triage, no CVE response, no PHP-version compatibility releases. Adopting it converts a solved commodity into an owned artifact; the true cost is not the license (MIT, zero) but the standing obligation to fork, patch, and re-publish. For a capability this small, that obligation is disproportionate — CORS middleware is one of the few components where writing 60 lines in-house is genuinely cheaper than consuming a dependency, because you control the spec compliance and can express only the policy you actually need.
Support is community-only and now effectively nonexistent. There is no vendor, no SLA, and the archived status means Stack Overflow answers and blog posts will decay as frameworks change. Internal support burden lands on whoever owns the HTTP layer, and the knowledge is non-transferable — debugging CORS through an abandoned abstraction is slower than debugging it through framework-native code with current documentation.
Scaling is a non-issue technically: CORS is a header-emission concern with negligible CPU cost and no state. It scales trivially. The scaling concern is organizational — the number of services or routes relying on the package grows, and each one inherits the unmaintained dependency. Concentrate the decision: either standardize on native middleware everywhere, or accept a fork with an explicit owner. Avoid a mixed estate where some services use the package and others do not, because divergent CORS policy across services is a common source of production-only, browser-specific incidents.
Failure modes to instrument for: silent preflight failure (browser blocks the request, server logs show only OPTIONS 200/204 with no error), wildcard-origin-plus-credentials misconfiguration (works in dev, rejected by browsers in prod), header allowlist drift when a new client header is introduced, Max-Age set too low causing preflight storms, and — specific to this package — an untested PHP/framework combination producing a fatal in the middleware constructor, which fails the entire request pipeline rather than degrading gracefully. Because CORS failures surface only in the browser, server-side observability is weak; add synthetic browser checks on preflight for each critical origin.
Ramp-up is low in absolute terms — a competent PHP engineer understands the code in under a day — but the ramp is deceptive because the policy is the hard part, not the middleware. New engineers will assume an installed CORS package implies a maintained one. Recommended position: do not adopt for greenfield; if already present, schedule migration to native middleware within one quarter, with parity tests as the exit criterion.
How can I help you explore Laravel packages today?