dmt-software/anti-xss-middleware

PSR-15 middleware to help prevent xss attacks

2.1.0 2024-08-29 14:10 UTC

This package is auto-updated.

Last update: 2024-10-30 08:13:31 UTC


README

This middleware implements the PSR-15 MiddlewareInterface and can be helpful to prevent XSS attacks.

Installation

composer require dmt-software/anti-xss-middleware

Usage

use DMT\Http\AntiXss\Middleware\AntiXssMiddleware;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

/** @var ResponseFactoryInterface $responseFactory */
$antiXssMiddleware = new AntiXssMiddleware($responseFactory);

/** @var ServerRequestInterface $request */
/** @var RequestHandlerInterface $handler */
$response = $antiXssMiddleware->process($request, $handler);

if ($response->getStatusCode() === 400) {
    // cross site scripting detected
}