PHPackages                             phpolar/csrf-protection - 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. phpolar/csrf-protection

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

phpolar/csrf-protection
=======================

Provides request checking and response filtering to mitigate CSRF attacks

3.2.2(5mo ago)31.3k[1 issues](https://github.com/phpolar/csrf-protection/issues)2MITPHPPHP &gt;=8.3CI passing

Since Jan 17Pushed 5mo agoCompare

[ Source](https://github.com/phpolar/csrf-protection)[ Packagist](https://packagist.org/packages/phpolar/csrf-protection)[ RSS](/packages/phpolar-csrf-protection/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (13)Versions (36)Used By (2)

 [![](./phpolar.svg)](./phpolar.svg)

Csrf Protection
===============

[](#csrf-protection)

PSR-7 and PSR-15 based CSRF protection for HTTP requests

[![Coverage Status](https://camo.githubusercontent.com/fa0647f0d70871ae22b0f4335ca23af37dc4ea1ada120d2bbc79013f2f0289ad/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7068706f6c61722f637372662d70726f74656374696f6e2f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/phpolar/csrf-protection?branch=main) [![Latest Stable Version](https://camo.githubusercontent.com/023fe5a4de1bccef5c9929fac66f943f2a469b4973cc795357e55b65d74fe4e8/68747470733a2f2f706f7365722e707567782e6f72672f7068706f6c61722f637372662d70726f74656374696f6e2f76)](https://packagist.org/packages/phpolar/csrf-protection) [![Total Downloads](https://camo.githubusercontent.com/1b2e1e93b844b7d9492a16297cea938a08142041e58f24b5f73b9bff73fb33fe/68747470733a2f2f706f7365722e707567782e6f72672f7068706f6c61722f637372662d70726f74656374696f6e2f646f776e6c6f616473)](https://packagist.org/packages/phpolar/csrf-protection) [![PHP Version Require](https://camo.githubusercontent.com/47dbf1f997d4ee07f5585a4ad0cf582f9c4ec07b38f18c40d5897b5a94a34ff3/68747470733a2f2f706f7365722e707567782e6f72672f7068706f6c61722f637372662d70726f74656374696f6e2f726571756972652f706870)](https://packagist.org/packages/phpolar/csrf-protection) [![Weekly Check](https://github.com/phpolar/csrf-protection/actions/workflows/weekly.yml/badge.svg)](https://github.com/phpolar/csrf-protection/actions/workflows/weekly.yml)

Table of Contents
-----------------

[](#table-of-contents)

1. [Installation](#installation)
2. [Usage](#usage)
3. [Resources](#resources)
4. [API Documentation](#api-documentation)

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

[](#installation)

```
composer require phpolar/csrf-protection
```

Usage
-----

[](#usage)

```
$csrfChecking = $this->container->get(CsrfRequestCheckMiddleware::class);
$csrfFiltering = $this->container->get(CsrfResponseFilterMiddleware::class);

$app->use($csrfChecking);
$app->use($csrfFiltering);

// ...

$response = $csrfCheckMiddleware->process($request, $nextHandler);

// ...

$preparedResponse = $middleWare->process($request, $routingHandler);
```

Resources
---------

[](#resources)

1. [PSR-7](https://www.php-fig.org/psr/psr-7/)
2. [PSR-15](https://www.php-fig.org/psr/psr-15/)
3. [Example middleware setup](https://www.php-fig.org/psr/psr-15/meta/#63-example-interface-interactions)

[API Documentation](https://phpolar.github.io/csrf-protection/)
---------------------------------------------------------------

[](#api-documentation)

Thresholds
----------

[](#thresholds)

Source Code SizeMemory Usage4.3 kB108 kB[Back to top](#csrf-protection)

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance65

Regular maintenance activity

Popularity23

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 56.7% 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

Every ~33 days

Recently: every ~64 days

Total

33

Last Release

165d ago

Major Versions

0.4.4 → 1.0.02023-01-31

1.3.3 → 2.0.02023-02-26

2.1.0 → 3.0.02023-05-22

PHP version history (3 changes)0.1.1PHP &gt;=8.1

3.1.4PHP ^7.4 || ^8.0

3.1.5PHP &gt;=8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f34e51c09f71ccba1670d080b700e489cc2cffd43f4bed7684af4dff0195732?d=identicon)[phpolar](/maintainers/phpolar)

![](https://avatars.githubusercontent.com/u/40972462?v=4)[Eric Fortmeyer](/maintainers/ericfortmeyer)[@ericfortmeyer](https://github.com/ericfortmeyer)

---

Top Contributors

[![ericfortmeyer](https://avatars.githubusercontent.com/u/40972462?v=4)](https://github.com/ericfortmeyer "ericfortmeyer (187 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (97 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (46 commits)")

---

Tags

psr-7middlewarepsr-15csrfrequest handlers

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpolar-csrf-protection/health.svg)

```
[![Health](https://phpackages.com/badges/phpolar-csrf-protection/health.svg)](https://phpackages.com/packages/phpolar-csrf-protection)
```

###  Alternatives

[relay/relay

A PSR-15 server request handler.

3302.1M86](/packages/relay-relay)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

121.6M26](/packages/mezzio-mezzio-authentication)[jimtools/jwt-auth

PSR-15 JWT Authentication middleware, A replacement for tuupola/slim-jwt-auth

20142.3k3](/packages/jimtools-jwt-auth)[tkhamez/slim-role-auth

Role-based authorization for the Slim framework

1410.3k](/packages/tkhamez-slim-role-auth)[segrax/open-policy-agent

Open Policy Agent client and PSR-7, PSR-15 Authorization Middleware

212.0k](/packages/segrax-open-policy-agent)

PHPackages © 2026

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