Download the PHP package evanschleret/laravel-cors-resolver without Composer

On this page you can find all versions of the php package evanschleret/laravel-cors-resolver. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-cors-resolver

Laravel CORS Resolver

Dynamic, request-aware CORS policies for Laravel applications.

Status: stable.

evanschleret/laravel-cors-resolver is designed for multi-tenant and multi-site applications where the allowed origins, methods, and headers depend on the current request. It supports the Laravel 12 and 13 major versions that are currently within Laravel's official support window.

The package does not modify config('cors') and does not depend on fruitcake/laravel-cors, spatie/laravel-cors, or another abandoned CORS package.

Installation

Laravel package discovery registers the service provider and the cors.resolve middleware alias.

Use this middleware instead of Laravel's Illuminate\Http\Middleware\HandleCors for the paths handled by this package. Do not run both middleware for the same request.

Other packages by Evan Schleret

Configuration

deny returns 403 for an invalid or unresolved preflight and omits CORS headers from actual responses. passthrough lets an invalid preflight reach the application without adding CORS headers. Both modes fail closed from the browser's point of view.

Configuration is validated while the service provider registers. Invalid paths, resolver declarations, failure modes, cache settings, namespaces, versions, and lock durations fail startup with a CorsConfigurationException instead of being silently coerced.

Resolver exceptions use resolver_exception_mode. The default deny mode returns 503 Service Unavailable, adds only the appropriate Vary headers, does not invoke the application, and does not expose the exception. throw rethrows the original exception to Laravel's exception handler. Cache failures are not treated as resolver failures and are allowed to propagate.

Failure responses can be customized with a class implementing CorsFailureResponse or with a closure accepting (Request $request, CorsFailure $failure) and returning a Symfony Response. The package always adds the required Vary headers after the custom response. If the custom responder throws, the package falls back to the default fail-closed response.

The package dispatches three events when observability is enabled:

Register listeners with Laravel's event system. Set observability.enabled to false when the application does not need these events. Event listener failures are isolated from the CORS response.

Caching is disabled by default. Enable it only when the resolver's result is stable for the request fingerprint and invalidate entries when external tenant configuration changes. namespace and version isolate this package's keys from other applications and provide a simple cache migration mechanism. Set tenant_parameter to a route parameter name when policies are tenant-specific, for example tenant or account.

When caching is enabled, supported Laravel lock stores protect cache misses from concurrent recomputation. lock.ttl must exceed the expected resolver duration, and lock.wait controls how long another request waits for the lock. If the store does not support locks or the lock times out, the resolver runs normally and the request is not failed because caching is only an optimization. Set lock.enabled to false to disable this protection.

A simple resolver

The package does not type the route value as an Eloquent model. The example works with Eloquent route model binding, but the same resolver can use a DTO, an API response, a configuration service, or a tenant registry.

Closure and route parameter resolvers

A closure can also be set directly as cors-resolver.resolver. A resolver configured as a class should implement CorsResolver and be resolvable by Laravel's container.

Middleware registration

Laravel 12 and 13

For a global resolver, remove HandleCors from the global stack and add the package middleware in bootstrap/app.php:

Route middleware

Route middleware is useful when the resolver needs route model binding. Ensure the route accepts OPTIONS before authentication middleware if your application uses route-scoped preflight handling. Global registration is usually preferable for automatic preflight handling.

Laravel 12 and 13 applications configure middleware in bootstrap/app.php. The package does not change the application file automatically.

Security model

Cache safety

The cache key includes the resolver class, configured paths, method, scheme and host, path, query parameters, all request headers, and a hash of the request body. This prevents a cached result for one tenant or origin from being reused for a different request context. Header and body values are hashed into the key and are not stored as cache metadata.

Invalidate a known context explicitly after changing external CORS configuration:

Invalidate every cached policy for a resolver or tenant when its CORS configuration changes:

Resolver and tenant invalidation uses persistent generation keys, so it works with cache stores that do not support tags. Existing policy entries become unreachable immediately and expire normally according to their configured TTL.

Do not cache policies that depend on mutable state not represented by the request fingerprint unless your application invalidates the entry when that state changes.

forget and invalidateContext invalidate one known request context. invalidateResolver invalidates all contexts for a resolver, while invalidateTenant invalidates all contexts for a tenant, optionally limited to one resolver. These methods are safe for application-level configuration change handlers and do not require cache tags.

Known limitations

Compatibility

Laravel PHP Testbench
12 8.3–8.5 10
13 8.3–8.5 11

The package requires PHP 8.3 or newer. Laravel 13 officially supports PHP 8.3 through 8.5.

See Laravel's Laravel 12 support policy and Laravel 13 release notes for the framework's current support window.

Development

See SECURITY.md for private vulnerability reporting.

License

The MIT License. See LICENSE.


All versions of laravel-cors-resolver with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/contracts Version ^12.0 || ^13.0
illuminate/http Version ^12.0 || ^13.0
illuminate/support Version ^12.0 || ^13.0
symfony/http-foundation Version ^6.2 || ^7.0 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package evanschleret/laravel-cors-resolver contains the following files

Loading the files please wait ...