PHPackages                             componenta/http-csrf-middleware - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. componenta/http-csrf-middleware

ActiveLibrary[HTTP &amp; Networking](/categories/http)

componenta/http-csrf-middleware
===============================

CSRF token managers and PSR-15 middleware for Componenta

v1.0.0(1mo ago)00MITPHPPHP ^8.4

Since Jun 16Pushed 1mo agoCompare

[ Source](https://github.com/componenta/http-csrf-middleware)[ Packagist](https://packagist.org/packages/componenta/http-csrf-middleware)[ RSS](/packages/componenta-http-csrf-middleware/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Componenta HTTP CSRF Middleware
===============================

[](#componenta-http-csrf-middleware)

CSRF token managers and PSR-15 middleware for Componenta HTTP applications. The middleware checks unsafe methods with token validation and optional Origin/Referer verification.

Installation
------------

[](#installation)

```
composer require componenta/http-csrf-middleware
```

This package has no config provider. Configure the token manager and middleware explicitly.

Token Managers
--------------

[](#token-managers)

ClassStorage`SessionCsrfTokenManager`PHP `$_SESSION`; starts the session when needed and stores the token under `_csrf_token` by default.`CookieCsrfTokenManager`Cookie value written through `setcookie()`.`HmacCsrfTokenManager`Stateless HMAC token with a secret and optional active token source.All managers implement `CsrfTokenManagerInterface`.

Middleware
----------

[](#middleware)

```
use Componenta\Http\Middleware\Csrf\CsrfMiddleware;
use Componenta\Http\Middleware\Csrf\SessionCsrfTokenManager;

$middleware = new CsrfMiddleware(
    tokenManager: new SessionCsrfTokenManager(),
    responseFactory: $responseFactory,
    excludedPaths: ['/webhook'],
);
```

Safe methods (`GET`, `HEAD`, `OPTIONS`, `TRACE`) are not validated. Unsafe methods read the token from the `X-CSRF-Token` header first and then from the parsed body field `_csrf_token`.

The active token and manager are added to request attributes `csrf_token` and `csrf_token_manager`.

`InvalidCsrfTokenException` is converted by the middleware into a generic 403 response.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance91

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

44d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20490712?v=4)[Andrey Shelamkoff](/maintainers/Shelamkoff)[@Shelamkoff](https://github.com/Shelamkoff)

---

Top Contributors

[![Shelamkoff](https://avatars.githubusercontent.com/u/20490712?v=4)](https://github.com/Shelamkoff "Shelamkoff (1 commits)")

### Embed Badge

![Health badge](/badges/componenta-http-csrf-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/componenta-http-csrf-middleware/health.svg)](https://phpackages.com/packages/componenta-http-csrf-middleware)
```

###  Alternatives

[mezzio/mezzio

PSR-15 Middleware Microframework

3923.8M126](/packages/mezzio-mezzio)[hyperf/hyperf

A coroutine framework that focuses on hyperspeed and flexibility. Building microservice or middleware with ease.

6.9k3.3k2](/packages/hyperf-hyperf)[sunrise/http-router

A powerful solution as the foundation of your project.

17451.8k11](/packages/sunrise-http-router)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28591.3k3](/packages/mezzio-mezzio-authentication-oauth2)[mimmi20/browser-detector

Library to detect Browsers and Devices

48157.6k5](/packages/mimmi20-browser-detector)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
