poor-plebs / guzzle-obfuscated-formatter
Guzzle HTTP message formatter with configurable obfuscation for safe logging of sensitive data.
Package info
github.com/Poor-Plebs/guzzle-obfuscated-formatter
pkg:composer/poor-plebs/guzzle-obfuscated-formatter
Requires
- php: ^8.4.0
- guzzlehttp/guzzle: ^7.4.5
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.92.5
- pestphp/pest: ^4.3.1
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-type-coverage: ^4.0.3
- phpstan/phpstan: ^2.1.33
- phpstan/phpstan-deprecation-rules: ^2.0.3
- phpstan/phpstan-strict-rules: ^2.0.7
- roave/security-advisories: dev-latest
README
What is it for? | What are the requirements? | How to install it? | How to use it? | How to contribute?
Guzzle HTTP message formatter with configurable obfuscation for safe logging of sensitive data.
What is it for?
This package provides a Guzzle MessageFormatterInterface implementation that
can selectively obfuscate sensitive data in HTTP messages before logging. It
supports obfuscating:
- URI path segments via regex patterns
- Query parameters by name
- Request and response headers by name
- JSON body fields (request and response) by key, including nested fields
- User info (password part) in URIs
It also includes utilities for PSR-7 message stringification with large payload compression.
What are the requirements?
- PHP 8.4 or above
- Guzzle HTTP 7.4.5+
How to install it?
composer require poor-plebs/guzzle-obfuscated-formatter
How to use it?
Basic usage
use PoorPlebs\GuzzleObfuscatedFormatter\GuzzleHttp\ObfuscatedMessageFormatter; use PoorPlebs\GuzzleObfuscatedFormatter\Obfuscator\StringObfuscator; $formatter = (new ObfuscatedMessageFormatter(ObfuscatedMessageFormatter::DEBUG)) ->setQueryParameters(['api_key', 'token']) ->setRequestHeaders(['Authorization']) ->setResponseHeaders(['Set-Cookie']) ->setRequestBodyParameters(['password', 'secret']) ->setResponseBodyParameters(['access_token']);
URI path obfuscation with regex
$formatter->setUriParameters([ '/\/api\/v1\/users\/\d+/' => new StringObfuscator('*', 5), ]);
Custom obfuscator per parameter
$formatter->setRequestHeaders([ 'Authorization' => new StringObfuscator('X', 3), // Replaces with "XXX" ]);
How to contribute?
poor-plebs/guzzle-obfuscated-formatter follows semantic versioning. Read more
on semver.org.
Create issues to report problems or requests. Fork and create pull requests to propose solutions and ideas.
Development Setup
This package uses modern PHP tooling with strict quality standards:
- Testing: Pest PHP v4 with parallel execution
- Static Analysis: PHPStan at level
maxwith strict and deprecation rules - Code Style: PHP-CS-Fixer (PSR-12)
- Coverage Requirements: Minimum 80% code coverage and 80% type coverage
Available Commands
composer test # Run tests (parallel, no coverage) composer coverage # Run tests with coverage (min 80%) composer type-coverage # Check type coverage (min 80%) composer static # Run PHPStan analysis composer cs # Check code style composer csf # Fix code style composer ci # Run full CI pipeline
Docker
bin/dc install # Install dependencies via Docker bin/dc test # Run tests via Docker bin/dc ci # Run full CI pipeline via Docker
Versioning and Releases
This project uses Semantic Versioning with tags in MAJOR.MINOR.PATCH
format (no v prefix). Releases are automated via GitHub Actions when a tag is
pushed.
bin/release-tag 1.0.0 notes.md --push