Download the PHP package rennf93/psr15-guard without Composer
On this page you can find all versions of the php package rennf93/psr15-guard. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rennf93/psr15-guard
More information about rennf93/psr15-guard
Files in rennf93/psr15-guard
Package psr15-guard
Short Description PSR-15 middleware adapter for guard-core-php: translates PSR-7 server requests to the guard-core engine and block verdicts back to PSR-7 responses
License MIT
Informations about the package psr15-guard
psr15-guard
PSR-15 middleware adapter for guard-core-php: translates any PSR-7 ServerRequestInterface to the guard-core engine and translates block verdicts back to PSR-7 responses. Works with Slim 4, Mezzio, Symfony PSR-15 bridges, or any PSR-7/PSR-15 stack.
Docs: https://rennf93.github.io/psr15-guard/
Install
Usage
Blocked requests get the engine's BlockResponse translated exactly (status, body, headers), for example 403 Forbidden for a blacklisted IP, 429 Too many requests with Retry-After for a rate limit hit. Passing requests continue down the stack untouched.
Pass-through responses are finished by the middleware too: the engine's security headers and CORS verdict headers are merged on top of the handler's response, and the engine's behavioral return rules observe the response status code plus a body prefix bounded by behaviorMaxResponseBodyInspectBytes (only while behaviorScanResponseBody is on; the PSR-7 stream is rewound after the bounded capture when it is seekable, so emitters still see the full body). Per-route configuration attaches through the middleware's route map or a custom resolver:
routes patterns match a path exactly or as a prefix when they end with /. Geo rate-limit tiers need a country resolver: pass geoRateLimitResolver explicitly, or configure geoIpHandler together with blockedCountries/whitelistCountries (the engine keeps the injected handler only when country lists are set) and the middleware bridges it onto the engine's rate-limit handler automatically.
Lifecycle
PHP shared-nothing applies: construct GuardEngine (and therefore GuardMiddleware) per request in classic FPM, or per worker under Swoole/Octane/RoadRunner. The middleware holds no mutable state of its own. In-memory fallbacks are per-request safety nets; distributed rate limits, IP bans, and cloud-range caches require Redis (set enableRedis: true and point REDIS_HOST/REDIS_PORT at your instance).
Behavior notes
- Fail-closed: if the engine throws, the middleware returns the engine's fail-closed response (
500 Security check failed, honorably overridden bycustomErrorResponses) instead of letting the request through. - Bounded body read: the request body is scanned as a prefix of at most 256 KiB (
PsrGuardRequest::MAX_BODY_BYTES, matching the engine's full-scan window). Payloads beyond the prefix, or signatures split across its boundary, are not detected. - With
redisFailOpen: truethe middleware constructs and serves requests even when Redis is unreachable; withredisFailOpen: falseconstruction fails closed. - No security headers or CORS are added by this adapter.
Testing
composer test runs the plain-PHP suite in bin/test_psr15.php (unit coverage always; set REDIS_HOST to a reachable Redis to include the shared-state integration cases).
License
MIT
All versions of psr15-guard with dependencies
rennf93/guard-core-php Version ^4.4.0
psr/http-message Version ^1.1|^2.0
psr/http-factory Version ^1.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0