PHPackages                             allejo/php-vcr-sanitizer - 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. [Security](/categories/security)
4. /
5. allejo/php-vcr-sanitizer

ActiveLibrary[Security](/categories/security)

allejo/php-vcr-sanitizer
========================

Bring privacy to php-vcr by excluding API keys, passwords, and credentials from your recordings

v1.1.1(1y ago)14580.6k↑26.2%55MITPHPPHP &gt;=7.1.3CI failing

Since Apr 12Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/allejo/php-vcr-sanitizer)[ Packagist](https://packagist.org/packages/allejo/php-vcr-sanitizer)[ Fund](https://www.buymeacoffee.com/allejo)[ GitHub Sponsors](https://github.com/allejo)[ RSS](/packages/allejo-php-vcr-sanitizer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (18)Used By (5)

php-vcr-sanitizer
=================

[](#php-vcr-sanitizer)

[![Packagist](https://camo.githubusercontent.com/7f79021d17fc4f03d4643ad97a01f90b404733d99b72e112029bee3112efc78f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c6c656a6f2f7068702d7663722d73616e6974697a65722e737667)](https://packagist.org/packages/allejo/php-vcr-sanitizer)[![Tested with php-vcr v1.4+](https://camo.githubusercontent.com/422fae5690db1fe14dcabdd2b8f57d16a7b2d72f4d5462c2c0032a29005572af/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f546573746564253230776974682532307068702d2d7663722d312e34253230253743253230312e35253230253743253230312e362d627269676874677265656e)](https://github.com/php-vcr/php-vcr)[![Unit Tests](https://github.com/allejo/php-vcr-sanitizer/workflows/Unit%20Tests/badge.svg)](https://github.com/allejo/php-vcr-sanitizer/workflows/Unit%20Tests/badge.svg)[![GitHub license](https://camo.githubusercontent.com/b3fea8da46dd10534ecf7b037419a989a5c8b8291c4efdf51d950a2a151f111f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f616c6c656a6f2f7068702d7663722d73616e6974697a65722e737667)](https://github.com/allejo/php-vcr-sanitizer/blob/master/LICENSE.md)

[php-vcr](https://php-vcr.github.io/) is a tool for recording and replaying outgoing requests, however it has had ["Privacy aware" marked as "soon"](https://php-vcr.github.io/#page-nav-Features) for quite some time now. Whenever I test my APIs, there will often be some sensitive information such as keys or passwords in the recordings. Up until now, I've had a separate script to always remove sensitive data before getting checked into version control.

I got tired of having to always sanitize the data, so this is a quick and dirty solution until php-vcr officially supports "private" recordings.

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

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Configuration](#configuration)
        - [Sanitizing Requests](#sanitizing-requests)
        - [Sanitizing Responses](#sanitizing-responses)
    - [Disabling the Sanitizer](#disabling-the-sanitizer)
- [How Sanitizing Works](#how-sanitizing-works)
    - [Hostnames](#hostnames)
    - [Headers](#headers)
    - [URL Parameters](#url-parameters)
    - [Body Content](#body-content)
    - [Post Field Content](#post-field-content)
- [License](#license)

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

[](#installation)

Install the package through [Composer](https://getcomposer.org/).

```
composer require --dev allejo/php-vcr-sanitizer
```

Usage
-----

[](#usage)

After your VCR instance has been turned on, call `VCRCleaner::enable()` and pass whatever URL parameters or headers you don't want to be recorded in your fixtures.

```
VCR::turnOn();
VCR::insertCassette('...');

VCRCleaner::enable(array(
   'request' => array(
       'ignoreHostname' => false,
       'ignoreQueryFields' => array(
           'apiKey',
       ),
       'ignoreHeaders' => array(
           'X-Api-Key',
       ),
       'bodyScrubbers' => array(
           function($body) {
               return preg_replace('/
