Download the PHP package componenta/http-cors-middleware without Composer

On this page you can find all versions of the php package componenta/http-cors-middleware. 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 http-cors-middleware

Componenta HTTP CORS Middleware

PSR-15 CORS middleware for PHP 8.4+. The package implements the server side of the Fetch CORS protocol with a conservative, default-deny policy.

CORS controls whether browser JavaScript may read a cross-origin response. It is not an authentication, authorization, or CSRF mechanism. A disallowed simple cross-origin request can still reach the application; the browser only prevents the calling script from reading the response.

Installation

The package requires a PSR-17 ResponseFactoryInterface.

Secure configuration

No origin is allowed by default:

Opaque null origins are rejected in every mode. Sandboxed documents and other opaque-origin contexts can deliberately produce Origin: null, so it is not a trustworthy allowlist identity.

When allowCredentials is enabled, every allowed origin must be an explicit HTTP(S) origin. The configuration additionally rejects *.

This prevents an arbitrary origin from being reflected together with Access-Control-Allow-Credentials: true.

Without credentials, * is supported:

The wildcard intentionally does not match the opaque null origin, and null cannot be configured as an allowed origin.

Origin parsing

Origins are parsed as serialized origins, not generic URLs, and allowlists are exact. An origin must be exactly:

User information, paths, query strings, fragments, invalid hosts, and port zero are rejected. Scheme and host are normalized to lowercase and default ports 80/443 are removed.

Allowed private origins must be exact HTTP(S) origins. Subdomain wildcard patterns such as https://*.example.com are rejected in every mode because a single dangling or less-trusted sibling hostname can turn a wildcard policy into unintended cross-origin access. Use explicit origins instead. The only wildcard is the full * policy for deliberately public, non-credentialed resources.

v3.0 upgrade note: subdomain wildcard patterns were removed. Replace every https://*.example.com-style entry with an explicit list of trusted origins when upgrading from v2.

Preflight

A CORS preflight is intercepted only when the request contains:

The requested method and header names are validated using HTTP token/field-name grammar. HTTP method matching is case-sensitive as required by RFC 9110; custom method spelling is preserved exactly. Malformed or disallowed requests receive 403 and are not forwarded to the application.

Successful preflights receive 204 plus the configured CORS response fields.

Authorization is a CORS non-wildcard request header. Therefore, when allowedHeaders: ['*'] is used and the preflight requests Authorization, the middleware explicitly returns the requested header names instead of Access-Control-Allow-Headers: *.

Credentials

Credentialed CORS is deliberately explicit:

Access-Control-Expose-Headers: * is rejected with credentials because the Fetch Standard treats * literally in credential mode.

Wildcard methods or request headers may still be configured intentionally. In credential mode they are reflected as the concrete requested method/header names rather than emitted as *.

Legacy Private Network Access compatibility

allowPrivateNetwork implements the legacy Private Network Access (PNA) preflight headers for compatibility with clients that still send them:

Legacy PNA requires an explicit non-opaque origin. If a preflight sends Access-Control-Request-Private-Network: true while this compatibility mode is disabled, the middleware rejects it. Responses vary on Access-Control-Request-Private-Network whenever that request field can affect the result.

Current Local Network Access (LNA) replaces the old PNA preflight design with a browser permission model. Therefore allowPrivateNetwork is not a current LNA authorization or security boundary; application authorization and CSRF defenses remain mandatory.

Response ownership

The middleware owns all CORS response fields. After the application handler returns, existing downstream values such as:

are removed and rebuilt only from the configured policy.

This prevents a handler from bypassing the central CORS policy by adding a permissive header.

Cache correctness

Responses include Vary: Origin. Preflight responses also vary on:

An existing Vary: * remains Vary: *; field names are not appended to the wildcard.

Verification

The repository quality workflow verifies:

Standards

The normative CORS processing model is defined by the WHATWG Fetch Living Standard. HTTP field syntax and cache semantics follow RFC 9110. Origin semantics are based on RFC 6454.


All versions of http-cors-middleware with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
psr/http-message Version ^2.0
psr/http-server-middleware Version ^1.0
psr/http-factory Version ^1.1
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 componenta/http-cors-middleware contains the following files

Loading the files please wait ...