Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Array Redactor

Array Redactor Laravel Package

mtownsend/array-redactor

Redact sensitive data from PHP arrays before logging or storing it. Array Redactor masks values by key using dot notation and wildcards, with a configurable replacement string and Laravel support. Keeps passwords, tokens, and personal data out of your logs and dumps.

View on GitHub
Deep Wiki
Context7

Array Redactor is a lightweight PHP package for removing sensitive data from arrays before logging, debugging, or returning them in API responses. Define the keys to hide using simple dot notation and let the package scrub matching values recursively—including deeply nested arrays.

  • Dot notation targets nested keys like user.password
  • Wildcards (users.*.email) redact matches at any level
  • Custom redaction via closures or replacement values
  • Structure preserved so array shape stays intact
  • Framework-agnostic with optional Laravel support
Frequently asked questions about Array Redactor
What does the mtownsend/array-redactor package actually do?
It is a single-responsibility PHP utility that takes an associative array and a list of keys, then returns a copy with the values at those keys replaced by a redaction token. The package description advertises redacting specific keys, nested values, and wildcard key patterns, with a customizable replacement value. The core class is framework-agnostic; Laravel integration is an optional service provider and facade. It performs no I/O, no persistence, and keeps no state, so it is easy to drop into logging middleware, Monolog processors, exception handlers, or audit-trail writers.
How do I install array-redactor in a Laravel app?
Installation is a one-line composer require for mtownsend/array-redactor, after which Laravel auto-discovers the service provider and facade. There are no meaningful transitive dependencies, so Composer resolution conflicts are unlikely. The package is a small array transform, so there is nothing to publish or configure beyond the list of keys you want masked. Before adopting it, verify the declared PHP constraint in its composer.json against your runtime.
Does array-redactor support Laravel 10, Laravel 11, and PHP 8?
Probably, but this must be verified rather than assumed: the last release was 2019-06-08, before PHP 8 existed. The code itself is simple enough that it likely runs fine on PHP 8.x, but a 2019 composer.json almost certainly restricts php to ^7.x, which forces either --ignore-platform-reqs or a maintained fork with a widened constraint. The practical path is to widen the constraint in a fork and run the existing test suite on the PHP and Laravel versions you actually deploy. Treat that validation as a 30-minute task and do it before writing integration code.
Can array-redactor redact nested keys, dot-notation paths, and wildcard patterns?
The package blurb states that nested values and wildcard key patterns are supported, but recursion behavior, dot-notation support, and case sensitivity are not fully specified in the package metadata. Read the source or the test suite to confirm exactly how deep matching works and whether keys are compared case-sensitively. This matters because key-based redaction is a deny-list: if a secret lands one level deeper than your pattern covers, or under a differently-cased key, it passes through untouched and nothing throws an error.
What value replaces the sensitive data, and can I customize the redaction token?
Matching values are replaced with a redaction token, and the package supports replacing them with custom values via its fluent API. Choose the token deliberately: in structured logs a marker like a fixed asterisk string keeps the field present without exposing the secret, which is usually what log aggregators and parsers expect. Avoid tokens that reveal the shape or length of the original value. Confirm the exact default token in the source before relying on it in dashboards or alerting rules.
Does array-redactor mutate the original array or return a copy?
Treat immutability as something to verify in the source and tests rather than something documented in the package metadata. If callers reuse the same payload after redaction, in-place mutation would silently strip values the rest of the request still needs. Write a quick test that redacts an array and then asserts the original still contains the secret. If the package mutates, copy the array yourself before handing it to the redactor.
How do I use array-redactor in Laravel logging so passwords and tokens never reach the log file?
Wire it into a Monolog processor, a logging middleware, or your exception handler so payloads are redacted before they are serialized. Because it is a pure array transform with no state, it composes cleanly into HTTP client request and response taps and audit-trail writers as well. Keep the call site behind a narrow internal interface instead of calling the facade directly from application code, so you can swap implementations later. Remember that a denylist sitting in the log path creates an implicit contract about which keys hold secrets, and that contract drifts as fields get renamed.
Can array-redactor detect or scrub PII and credit card numbers inside free text?
No. It does not detect PII, does not scan values, and does not understand regex patterns; it replaces values at known keys. Anything embedded in free text, such as card numbers, emails, tokens inside stack traces, or SQL error messages, will pass straight through. If you need pattern-based scrubbing, pair this package with a value-level scrubber. Document this distinction clearly so nobody reads "we redact PII" as a compliance control before an audit rather than after.
Is array-redactor maintained, and what are the risks of depending on it?
It has roughly 145 GitHub stars and zero dependents, with no release since June 2019 and a single maintainer, so there is no community CVE watch and no external pressure to patch. The larger technical risk is silent under-redaction: because matching is key-based, a renamed field or unexpected nesting level leaks data without throwing an exception. The mitigation is to fork the package, own it internally, and set a patch SLA, since a security-adjacent dependency deserves a named owner. Also decide up front who maintains the fork if the original maintainer disappears.
How should I test array-redactor in my Laravel application?
Write feature tests that assert known sensitive keys are masked at each nesting level you rely on, plus negative tests proving the original payload is unchanged and that fields outside your key list survive intact. Add a test that fails loudly when a new sensitive field is introduced, since the failure mode here is silent pass-through rather than an exception. If you fork the package to widen the PHP constraint, run its own suite on your target PHP and Laravel versions first and keep that in CI. The utility is trivially testable precisely because it has no I/O, no persistence, and no state.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle
adachsoft/api-version-bundle
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
cgv/localized-resource